summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1c23d79)
raw | patch | inline | side by side (parent: 1c23d79)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 9 Jan 2007 08:50:02 +0000 (00:50 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 10 Jan 2007 01:57:03 +0000 (17:57 -0800) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile | patch | blob | history | |
builtin-merge-base.c | [new file with mode: 0644] | patch | blob |
builtin.h | patch | blob | history | |
git.c | patch | blob | history | |
merge-base.c | [deleted file] | patch | blob | history |
diff --git a/Makefile b/Makefile
index 43113e9e16937899332bcd24a88a2ae78ce65c97..eb88860bc9bfa694e455f5dfc76dd02d49b52d79 100644 (file)
--- a/Makefile
+++ b/Makefile
PROGRAMS = \
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
git-hash-object$X git-index-pack$X git-local-fetch$X \
- git-merge-base$X \
git-daemon$X \
git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \
git-peek-remote$X git-receive-pack$X \
builtin-ls-tree.o \
builtin-mailinfo.o \
builtin-mailsplit.o \
+ builtin-merge-base.o \
builtin-merge-file.o \
builtin-mv.o \
builtin-name-rev.o \
diff --git a/builtin-merge-base.c b/builtin-merge-base.c
--- /dev/null
+++ b/builtin-merge-base.c
@@ -0,0 +1,51 @@
+#include "cache.h"
+#include "commit.h"
+
+static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
+{
+ struct commit_list *result = get_merge_bases(rev1, rev2, 0);
+
+ if (!result)
+ return 1;
+
+ while (result) {
+ printf("%s\n", sha1_to_hex(result->item->object.sha1));
+ if (!show_all)
+ return 0;
+ result = result->next;
+ }
+
+ return 0;
+}
+
+static const char merge_base_usage[] =
+"git-merge-base [--all] <commit-id> <commit-id>";
+
+int cmd_merge_base(int argc, const char **argv, const char *prefix)
+{
+ struct commit *rev1, *rev2;
+ unsigned char rev1key[20], rev2key[20];
+ int show_all = 0;
+
+ git_config(git_default_config);
+
+ while (1 < argc && argv[1][0] == '-') {
+ const char *arg = argv[1];
+ if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
+ show_all = 1;
+ else
+ usage(merge_base_usage);
+ argc--; argv++;
+ }
+ if (argc != 3)
+ usage(merge_base_usage);
+ if (get_sha1(argv[1], rev1key))
+ die("Not a valid object name %s", argv[1]);
+ if (get_sha1(argv[2], rev2key))
+ die("Not a valid object name %s", argv[2]);
+ rev1 = lookup_commit_reference(rev1key);
+ rev2 = lookup_commit_reference(rev2key);
+ if (!rev1 || !rev2)
+ return 1;
+ return show_merge_base(rev1, rev2, show_all);
+}
diff --git a/builtin.h b/builtin.h
index df72d09447d0edd17d07eb97a9b3b36fa4b57531..ae32993ce945000018c38668eb33c8282c15400d 100644 (file)
--- a/builtin.h
+++ b/builtin.h
extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
+extern int cmd_merge_base(int argc, const char **argv, const char *prefix);
extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
extern int cmd_mv(int argc, const char **argv, const char *prefix);
extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
index bf55499dc3d555dfaa853b0c6e4aec5439c3532e..e7bc79af936190e527698df922b7b8e4cb37095f 100644 (file)
--- a/git.c
+++ b/git.c
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "mailinfo", cmd_mailinfo },
{ "mailsplit", cmd_mailsplit },
+ { "merge-base", cmd_merge_base, RUN_SETUP },
{ "merge-file", cmd_merge_file },
{ "mv", cmd_mv, RUN_SETUP },
{ "name-rev", cmd_name_rev, RUN_SETUP },
diff --git a/merge-base.c b/merge-base.c
--- a/merge-base.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "cache.h"
-#include "commit.h"
-
-static int show_all;
-
-static int merge_base(struct commit *rev1, struct commit *rev2)
-{
- struct commit_list *result = get_merge_bases(rev1, rev2, 0);
-
- if (!result)
- return 1;
-
- while (result) {
- printf("%s\n", sha1_to_hex(result->item->object.sha1));
- if (!show_all)
- return 0;
- result = result->next;
- }
-
- return 0;
-}
-
-static const char merge_base_usage[] =
-"git-merge-base [--all] <commit-id> <commit-id>";
-
-int main(int argc, char **argv)
-{
- struct commit *rev1, *rev2;
- unsigned char rev1key[20], rev2key[20];
-
- setup_git_directory();
- git_config(git_default_config);
-
- while (1 < argc && argv[1][0] == '-') {
- char *arg = argv[1];
- if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
- show_all = 1;
- else
- usage(merge_base_usage);
- argc--; argv++;
- }
- if (argc != 3)
- usage(merge_base_usage);
- if (get_sha1(argv[1], rev1key))
- die("Not a valid object name %s", argv[1]);
- if (get_sha1(argv[2], rev2key))
- die("Not a valid object name %s", argv[2]);
- rev1 = lookup_commit_reference(rev1key);
- rev2 = lookup_commit_reference(rev2key);
- if (!rev1 || !rev2)
- return 1;
- return merge_base(rev1, rev2);
-}