From: Junio C Hamano Date: Wed, 14 Feb 2007 00:50:32 +0000 (-0800) Subject: Merge branch 'jc/merge-base' (early part) X-Git-Tag: v1.5.1-rc1~299 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4a164d48df6bb1b4a771741c63d4437fd2dca0bb?ds=inline;hp=-c Merge branch 'jc/merge-base' (early part) This contains an evil merge to fast-import, in order to resolve in_merge_bases() update. --- 4a164d48df6bb1b4a771741c63d4437fd2dca0bb diff --combined Makefile index e38cb9f61c,eb88860bc9..d66126d7ec --- a/Makefile +++ b/Makefile @@@ -1,5 -1,5 +1,5 @@@ # The default target of this Makefile is... -all: +all:: # Define NO_OPENSSL environment variable if you do not have OpenSSL. # This also implies MOZILLA_SHA1. @@@ -172,7 -172,7 +172,7 @@@ SCRIPT_SH = git-merge-one-file.sh git-parse-remote.sh \ git-pull.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ - git-resolve.sh git-revert.sh git-sh-setup.sh \ + git-revert.sh git-sh-setup.sh \ git-tag.sh git-verify-tag.sh \ git-applymbox.sh git-applypatch.sh git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ @@@ -192,10 -192,8 +192,10 @@@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ - git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ + git-convert-objects$X git-fetch-pack$X git-fsck$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ + git-fast-import$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 \ @@@ -205,7 -203,7 +205,7 @@@ git-update-server-info$X \ git-upload-pack$X git-verify-pack$X \ git-pack-redundant$X git-var$X \ - git-describe$X git-merge-tree$X git-imap-send$X \ + git-merge-tree$X git-imap-send$X \ git-merge-recursive$X \ $(EXTRA_PROGRAMS) @@@ -214,12 -212,12 +214,12 @@@ EXTRA_PROGRAMS BUILT_INS = \ git-format-patch$X git-show$X git-whatchanged$X git-cherry$X \ - git-get-tar-commit-id$X git-init$X \ + git-get-tar-commit-id$X git-init$X git-repo-config$X \ + git-fsck-objects$X \ $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS)) # what 'all' will build and 'install' will install, in gitexecdir -ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) \ - git-merge-recur$X +ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) # Backward compatibility -- to be removed after 1.0 PROGRAMS += git-ssh-pull$X git-ssh-push$X @@@ -242,7 -240,7 +242,7 @@@ LIB_H = diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \ - utf8.h + utf8.h reflog-walk.h DIFF_OBJS = \ diff.o diff-lib.o diffcore-break.o diffcore-order.o \ @@@ -255,7 -253,7 +255,7 @@@ LIB_OBJS = interpolate.o \ lockfile.o \ object.o pack-check.o patch-delta.o path.o pkt-line.o sideband.o \ - reachable.o \ + reachable.o reflog-walk.o \ quote.o read-cache.o refs.o run-command.o dir.o object-refs.o \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ @@@ -276,14 -274,13 +276,14 @@@ BUILTIN_OBJS = builtin-check-ref-format.o \ builtin-commit-tree.o \ builtin-count-objects.o \ + builtin-describe.o \ builtin-diff.o \ builtin-diff-files.o \ builtin-diff-index.o \ - builtin-diff-stages.o \ builtin-diff-tree.o \ builtin-fmt-merge-msg.o \ builtin-for-each-ref.o \ + builtin-fsck.o \ builtin-grep.o \ builtin-init-db.o \ builtin-log.o \ @@@ -291,6 -288,7 +291,7 @@@ 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 \ @@@ -300,7 -298,7 +301,7 @@@ builtin-push.o \ builtin-read-tree.o \ builtin-reflog.o \ - builtin-repo-config.o \ + builtin-config.o \ builtin-rerere.o \ builtin-rev-list.o \ builtin-rev-parse.o \ @@@ -503,7 -501,7 +504,7 @@@ ifdef NO_D_INO_IN_DIREN BASIC_CFLAGS += -DNO_D_INO_IN_DIRENT endif ifdef NO_C99_FORMAT - ALL_CFLAGS += -DNO_C99_FORMAT + BASIC_CFLAGS += -DNO_C99_FORMAT endif ifdef NO_SYMLINK_HEAD BASIC_CFLAGS += -DNO_SYMLINK_HEAD @@@ -601,18 -599,14 +602,18 @@@ LIB_OBJS += $(COMPAT_OBJS ALL_CFLAGS += $(BASIC_CFLAGS) ALL_LDFLAGS += $(BASIC_LDFLAGS) -export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir +export prefix gitexecdir TAR INSTALL DESTDIR SHELL_PATH template_dir ### Build rules -all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk gitweb/gitweb.cgi +all:: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk gitweb/gitweb.cgi +ifneq (,$X) + $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), rm -f '$p';) +endif -all: +all:: + $(MAKE) -C git-gui all $(MAKE) -C perl PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all $(MAKE) -C templates @@@ -626,6 -620,9 +627,6 @@@ git$X: git.c common-cmds.h $(BUILTIN_OB help.o: common-cmds.h -git-merge-recur$X: git-merge-recursive$X - rm -f $@ && ln git-merge-recursive$X $@ - $(BUILT_INS): git$X rm -f $@ && ln git$X $@ @@@ -843,7 -840,6 +844,7 @@@ install: al $(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install $(MAKE) -C perl prefix='$(prefix_SQ)' install + $(MAKE) -C git-gui install if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \ then \ ln -f '$(DESTDIR_SQ)$(bindir_SQ)/git$X' \ @@@ -852,9 -848,6 +853,9 @@@ '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X'; \ fi $(foreach p,$(BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git$X' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;) +ifneq (,$X) + $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p';) +endif install-doc: $(MAKE) -C Documentation install @@@ -877,11 -870,8 +878,11 @@@ dist: git.spec git-archiv @mkdir -p $(GIT_TARNAME) @cp git.spec $(GIT_TARNAME) @echo $(GIT_VERSION) > $(GIT_TARNAME)/version + @$(MAKE) -C git-gui TARDIR=../$(GIT_TARNAME)/git-gui dist-version $(TAR) rf $(GIT_TARNAME).tar \ - $(GIT_TARNAME)/git.spec $(GIT_TARNAME)/version + $(GIT_TARNAME)/git.spec \ + $(GIT_TARNAME)/version \ + $(GIT_TARNAME)/git-gui/version @rm -rf $(GIT_TARNAME) gzip -f -9 $(GIT_TARNAME).tar @@@ -922,7 -912,6 +923,7 @@@ clean rm -f gitweb/gitweb.cgi $(MAKE) -C Documentation/ clean $(MAKE) -C perl clean + $(MAKE) -C git-gui clean $(MAKE) -C templates/ clean $(MAKE) -C t/ clean rm -f GIT-VERSION-FILE GIT-CFLAGS @@@ -937,7 -926,7 +938,7 @@@ check-docs: do \ case "$$v" in \ git-merge-octopus | git-merge-ours | git-merge-recursive | \ - git-merge-resolve | git-merge-stupid | git-merge-recur | \ + git-merge-resolve | git-merge-stupid | \ git-ssh-pull | git-ssh-push ) continue ;; \ esac ; \ test -f "Documentation/$$v.txt" || \ diff --combined builtin-branch.c index 2d8d61b453,020ed6be7b..d0e7209368 --- a/builtin-branch.c +++ b/builtin-branch.c @@@ -134,7 -134,7 +134,7 @@@ static int delete_branches(int argc, co */ if (!force && - !in_merge_bases(rev, head_rev)) { + !in_merge_bases(rev, &head_rev, 1)) { error("The branch '%s' is not a strict subset of " "your current HEAD.\n" "If you are sure you want to delete it, " @@@ -275,7 -275,7 +275,7 @@@ static void print_ref_item(struct ref_i } } -static void print_ref_list(int kinds, int verbose, int abbrev) +static void print_ref_list(int kinds, int detached, int verbose, int abbrev) { int i; struct ref_list ref_list; @@@ -286,20 -286,8 +286,20 @@@ qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp); + detached = (detached && (kinds & REF_LOCAL_BRANCH)); + if (detached) { + struct ref_item item; + item.name = "(no branch)"; + item.kind = REF_LOCAL_BRANCH; + hashcpy(item.sha1, head_sha1); + if (strlen(item.name) > ref_list.maxwidth) + ref_list.maxwidth = strlen(item.name); + print_ref_item(&item, ref_list.maxwidth, verbose, abbrev, 1); + } + for (i = 0; i < ref_list.index; i++) { - int current = (ref_list.list[i].kind == REF_LOCAL_BRANCH) && + int current = !detached && + (ref_list.list[i].kind == REF_LOCAL_BRANCH) && !strcmp(ref_list.list[i].name, head); print_ref_item(&ref_list.list[i], ref_list.maxwidth, verbose, abbrev, current); @@@ -308,15 -296,13 +308,15 @@@ free_ref_list(&ref_list); } -static void create_branch(const char *name, const char *start, +static void create_branch(const char *name, const char *start_name, + unsigned char *start_sha1, int force, int reflog) { struct ref_lock *lock; struct commit *commit; unsigned char sha1[20]; char ref[PATH_MAX], msg[PATH_MAX + 20]; + int forcing = 0; snprintf(ref, sizeof ref, "refs/heads/%s", name); if (check_ref_format(ref)) @@@ -325,34 -311,23 +325,34 @@@ if (resolve_ref(ref, sha1, 1, NULL)) { if (!force) die("A branch named '%s' already exists.", name); - else if (!strcmp(head, name)) + else if (!is_bare_repository() && !strcmp(head, name)) die("Cannot force update the current branch."); + forcing = 1; } - if (get_sha1(start, sha1) || - (commit = lookup_commit_reference(sha1)) == NULL) - die("Not a valid branch point: '%s'.", start); + if (start_sha1) + /* detached HEAD */ + hashcpy(sha1, start_sha1); + else if (get_sha1(start_name, sha1)) + die("Not a valid object name: '%s'.", start_name); + + if ((commit = lookup_commit_reference(sha1)) == NULL) + die("Not a valid branch point: '%s'.", start_name); hashcpy(sha1, commit->object.sha1); lock = lock_any_ref_for_update(ref, NULL); if (!lock) die("Failed to lock ref for update: %s.", strerror(errno)); - if (reflog) { + if (reflog) log_all_ref_updates = 1; - snprintf(msg, sizeof msg, "branch: Created from %s", start); - } + + if (forcing) + snprintf(msg, sizeof msg, "branch: Reset from %s", + start_name); + else + snprintf(msg, sizeof msg, "branch: Created from %s", + start_name); if (write_ref_sha1(lock, sha1, msg) < 0) die("Failed to write ref: %s.", strerror(errno)); @@@ -363,9 -338,6 +363,9 @@@ static void rename_branch(const char *o char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100]; unsigned char sha1[20]; + if (!oldname) + die("cannot rename the current branch while not on any."); + if (snprintf(oldref, sizeof(oldref), "refs/heads/%s", oldname) > sizeof(oldref)) die("Old branchname too long"); @@@ -387,8 -359,7 +387,8 @@@ if (rename_ref(oldref, newref, logmsg)) die("Branch rename failed"); - if (!strcmp(oldname, head) && create_symref("HEAD", newref)) + /* no need to pass logmsg here as HEAD didn't really move */ + if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL)) die("Branch renamed to %s, but HEAD is not updated!", newname); } @@@ -396,11 -367,12 +396,11 @@@ int cmd_branch(int argc, const char **a { int delete = 0, force_delete = 0, force_create = 0; int rename = 0, force_rename = 0; - int verbose = 0, abbrev = DEFAULT_ABBREV; + int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0; int reflog = 0; int kinds = REF_LOCAL_BRANCH; int i; - setup_ident(); git_config(git_branch_config); for (i = 1; i < argc; i++) { @@@ -472,27 -444,22 +472,27 @@@ head = xstrdup(resolve_ref("HEAD", head_sha1, 0, NULL)); if (!head) die("Failed to resolve HEAD as a valid ref."); - if (strncmp(head, "refs/heads/", 11)) - die("HEAD not found below refs/heads!"); - head += 11; + if (!strcmp(head, "HEAD")) { + detached = 1; + } + else { + if (strncmp(head, "refs/heads/", 11)) + die("HEAD not found below refs/heads!"); + head += 11; + } if (delete) return delete_branches(argc - i, argv + i, force_delete, kinds); else if (i == argc) - print_ref_list(kinds, verbose, abbrev); + print_ref_list(kinds, detached, verbose, abbrev); else if (rename && (i == argc - 1)) rename_branch(head, argv[i], force_rename); else if (rename && (i == argc - 2)) rename_branch(argv[i], argv[i + 1], force_rename); else if (i == argc - 1) - create_branch(argv[i], head, force_create, reflog); + create_branch(argv[i], head, head_sha1, force_create, reflog); else if (i == argc - 2) - create_branch(argv[i], argv[i + 1], force_create, reflog); + create_branch(argv[i], argv[i+1], NULL, force_create, reflog); else usage(builtin_branch_usage); diff --combined builtin-reflog.c index 65b845b447,fb37984ae6..341555139e --- a/builtin-reflog.c +++ b/builtin-reflog.c @@@ -13,7 -13,7 +13,7 @@@ */ static const char reflog_expire_usage[] = -"git-reflog expire [--verbose] [--dry-run] [--fix-stale] [--expire=