Make merge-base a built-in.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2007-01-09 00:50:02 -08:00
parent 1c23d794bf
commit 71dfbf224f
4 changed files with 8 additions and 8 deletions

View File

@ -194,7 +194,6 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
PROGRAMS = \ PROGRAMS = \
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ 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-hash-object$X git-index-pack$X git-local-fetch$X \
git-merge-base$X \
git-daemon$X \ git-daemon$X \
git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \ git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \
git-peek-remote$X git-receive-pack$X \ git-peek-remote$X git-receive-pack$X \
@ -289,6 +288,7 @@ BUILTIN_OBJS = \
builtin-ls-tree.o \ builtin-ls-tree.o \
builtin-mailinfo.o \ builtin-mailinfo.o \
builtin-mailsplit.o \ builtin-mailsplit.o \
builtin-merge-base.o \
builtin-merge-file.o \ builtin-merge-file.o \
builtin-mv.o \ builtin-mv.o \
builtin-name-rev.o \ builtin-name-rev.o \

View File

@ -1,9 +1,7 @@
#include "cache.h" #include "cache.h"
#include "commit.h" #include "commit.h"
static int show_all; static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
static int merge_base(struct commit *rev1, struct commit *rev2)
{ {
struct commit_list *result = get_merge_bases(rev1, rev2, 0); struct commit_list *result = get_merge_bases(rev1, rev2, 0);
@ -23,16 +21,16 @@ static int merge_base(struct commit *rev1, struct commit *rev2)
static const char merge_base_usage[] = static const char merge_base_usage[] =
"git-merge-base [--all] <commit-id> <commit-id>"; "git-merge-base [--all] <commit-id> <commit-id>";
int main(int argc, char **argv) int cmd_merge_base(int argc, const char **argv, const char *prefix)
{ {
struct commit *rev1, *rev2; struct commit *rev1, *rev2;
unsigned char rev1key[20], rev2key[20]; unsigned char rev1key[20], rev2key[20];
int show_all = 0;
setup_git_directory();
git_config(git_default_config); git_config(git_default_config);
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {
char *arg = argv[1]; const char *arg = argv[1];
if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
show_all = 1; show_all = 1;
else else
@ -49,5 +47,5 @@ int main(int argc, char **argv)
rev2 = lookup_commit_reference(rev2key); rev2 = lookup_commit_reference(rev2key);
if (!rev1 || !rev2) if (!rev1 || !rev2)
return 1; return 1;
return merge_base(rev1, rev2); return show_merge_base(rev1, rev2, show_all);
} }

View File

@ -42,6 +42,7 @@ extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
extern int cmd_ls_tree(int argc, const char **argv, const char *prefix); 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_mailinfo(int argc, const char **argv, const char *prefix);
extern int cmd_mailsplit(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_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_mv(int argc, const char **argv, const char *prefix);
extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_name_rev(int argc, const char **argv, const char *prefix);

1
git.c
View File

@ -238,6 +238,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
{ "ls-tree", cmd_ls_tree, RUN_SETUP }, { "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "mailinfo", cmd_mailinfo }, { "mailinfo", cmd_mailinfo },
{ "mailsplit", cmd_mailsplit }, { "mailsplit", cmd_mailsplit },
{ "merge-base", cmd_merge_base, RUN_SETUP },
{ "merge-file", cmd_merge_file }, { "merge-file", cmd_merge_file },
{ "mv", cmd_mv, RUN_SETUP }, { "mv", cmd_mv, RUN_SETUP },
{ "name-rev", cmd_name_rev, RUN_SETUP }, { "name-rev", cmd_name_rev, RUN_SETUP },