Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Sat, 20 Mar 2010 18:29:19 +0000 (11:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Mar 2010 18:29:19 +0000 (11:29 -0700)
* maint:
Update draft release notes to 1.7.0.3
fetch: Fix minor memory leak
fetch: Future-proof initialization of a refspec on stack
fetch: Check for a "^{}" suffix with suffixcmp()
daemon: parse_host_and_port SIGSEGV if port is specified
Makefile: Fix CDPATH problem
pull: replace unnecessary sed invocation

1  2 
Makefile
builtin/fetch.c
git-pull.sh
diff --combined Makefile
index fc03436617f91614b8ac2c75b3c82ae9240685d4,98372ebbfcabc0b96d33bdcde045ff73de971e28..3a6c6ea5259693db4846b91855675218b1e1a920
+++ b/Makefile
@@@ -214,13 -214,6 +214,13 @@@ all:
  #   DEFAULT_EDITOR='~/bin/vi',
  #   DEFAULT_EDITOR='$GIT_FALLBACK_EDITOR',
  #   DEFAULT_EDITOR='"C:\Program Files\Vim\gvim.exe" --nofork'
 +#
 +# Define COMPUTE_HEADER_DEPENDENCIES if your compiler supports the -MMD option
 +# and you want to avoid rebuilding objects when an unrelated header file
 +# changes.
 +#
 +# Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded
 +# dependency rules.
  
  GIT-VERSION-FILE: FORCE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@@ -308,7 -301,7 +308,7 @@@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__pow
  # Those must not be GNU-specific; they are shared with perl/ which may
  # be built by a different compiler. (Note that this is an artifact now
  # but it still might be nice to keep that distinction.)
 -BASIC_CFLAGS =
 +BASIC_CFLAGS = -I.
  BASIC_LDFLAGS =
  
  # Guard against environment variables
@@@ -316,17 -309,20 +316,23 @@@ BUILTIN_OBJS 
  BUILT_INS =
  COMPAT_CFLAGS =
  COMPAT_OBJS =
 +EXTRA_CPPFLAGS =
  LIB_H =
  LIB_OBJS =
 +PROGRAM_OBJS =
  PROGRAMS =
  SCRIPT_PERL =
  SCRIPT_PYTHON =
  SCRIPT_SH =
 -TEST_PROGRAMS =
 +SCRIPT_LIB =
 +TEST_PROGRAMS_NEED_X =
  
+ # Having this variable in your environment would break pipelines because
+ # you cause "cd" to echo its destination to stdout.  It can also take
+ # scripts to unexpected places.  If you like CDPATH, define it for your
+ # interactive shell sessions without exporting it.
+ unexport CDPATH
  SCRIPT_SH += git-am.sh
  SCRIPT_SH += git-bisect.sh
  SCRIPT_SH += git-difftool--helper.sh
@@@ -336,20 -332,20 +342,20 @@@ SCRIPT_SH += git-merge-octopus.s
  SCRIPT_SH += git-merge-one-file.sh
  SCRIPT_SH += git-merge-resolve.sh
  SCRIPT_SH += git-mergetool.sh
 -SCRIPT_SH += git-mergetool--lib.sh
 -SCRIPT_SH += git-notes.sh
 -SCRIPT_SH += git-parse-remote.sh
  SCRIPT_SH += git-pull.sh
  SCRIPT_SH += git-quiltimport.sh
  SCRIPT_SH += git-rebase--interactive.sh
  SCRIPT_SH += git-rebase.sh
  SCRIPT_SH += git-repack.sh
  SCRIPT_SH += git-request-pull.sh
 -SCRIPT_SH += git-sh-setup.sh
  SCRIPT_SH += git-stash.sh
  SCRIPT_SH += git-submodule.sh
  SCRIPT_SH += git-web--browse.sh
  
 +SCRIPT_LIB += git-mergetool--lib
 +SCRIPT_LIB += git-parse-remote
 +SCRIPT_LIB += git-sh-setup
 +
  SCRIPT_PERL += git-add--interactive.perl
  SCRIPT_PERL += git-difftool.perl
  SCRIPT_PERL += git-archimport.perl
@@@ -370,35 -366,16 +376,35 @@@ EXTRA_PROGRAMS 
  
  # ... and all the rest that could be moved out of bindir to gitexecdir
  PROGRAMS += $(EXTRA_PROGRAMS)
 -PROGRAMS += git-fast-import$X
 -PROGRAMS += git-imap-send$X
 -PROGRAMS += git-shell$X
 -PROGRAMS += git-show-index$X
 -PROGRAMS += git-upload-pack$X
 -PROGRAMS += git-http-backend$X
 +
 +PROGRAM_OBJS += fast-import.o
 +PROGRAM_OBJS += imap-send.o
 +PROGRAM_OBJS += shell.o
 +PROGRAM_OBJS += show-index.o
 +PROGRAM_OBJS += upload-pack.o
 +PROGRAM_OBJS += http-backend.o
 +
 +PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
 +
 +TEST_PROGRAMS_NEED_X += test-chmtime
 +TEST_PROGRAMS_NEED_X += test-ctype
 +TEST_PROGRAMS_NEED_X += test-date
 +TEST_PROGRAMS_NEED_X += test-delta
 +TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 +TEST_PROGRAMS_NEED_X += test-genrandom
 +TEST_PROGRAMS_NEED_X += test-match-trees
 +TEST_PROGRAMS_NEED_X += test-parse-options
 +TEST_PROGRAMS_NEED_X += test-path-utils
 +TEST_PROGRAMS_NEED_X += test-run-command
 +TEST_PROGRAMS_NEED_X += test-sha1
 +TEST_PROGRAMS_NEED_X += test-sigchain
 +TEST_PROGRAMS_NEED_X += test-index-version
 +
 +TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
  
  # List built-in command $C whose implementation cmd_$C() is not in
 -# builtin-$C.o but is linked in as part of some other command.
 -BUILT_INS += $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
 +# builtin/$C.o but is linked in as part of some other command.
 +BUILT_INS += $(patsubst builtin/%.o,git-%$X,$(BUILTIN_OBJS))
  
  BUILT_INS += git-cherry$X
  BUILT_INS += git-cherry-pick$X
@@@ -454,7 -431,6 +460,7 @@@ LIB_H += blob.
  LIB_H += builtin.h
  LIB_H += cache.h
  LIB_H += cache-tree.h
 +LIB_H += color.h
  LIB_H += commit.h
  LIB_H += compat/bswap.h
  LIB_H += compat/cygwin.h
@@@ -466,7 -442,6 +472,7 @@@ LIB_H += delta.
  LIB_H += diffcore.h
  LIB_H += diff.h
  LIB_H += dir.h
 +LIB_H += exec_cmd.h
  LIB_H += fsck.h
  LIB_H += git-compat-util.h
  LIB_H += graph.h
@@@ -509,8 -484,7 +515,8 @@@ LIB_H += tree-walk.
  LIB_H += unpack-trees.h
  LIB_H += userdiff.h
  LIB_H += utf8.h
 -LIB_H += wt-status.h
 +LIB_H += xdiff-interface.h
 +LIB_H += xdiff/xdiff.h
  
  LIB_OBJS += abspath.o
  LIB_OBJS += advice.o
@@@ -624,96 -598,95 +630,96 @@@ LIB_OBJS += ws.
  LIB_OBJS += wt-status.o
  LIB_OBJS += xdiff-interface.o
  
 -BUILTIN_OBJS += builtin-add.o
 -BUILTIN_OBJS += builtin-annotate.o
 -BUILTIN_OBJS += builtin-apply.o
 -BUILTIN_OBJS += builtin-archive.o
 -BUILTIN_OBJS += builtin-bisect--helper.o
 -BUILTIN_OBJS += builtin-blame.o
 -BUILTIN_OBJS += builtin-branch.o
 -BUILTIN_OBJS += builtin-bundle.o
 -BUILTIN_OBJS += builtin-cat-file.o
 -BUILTIN_OBJS += builtin-check-attr.o
 -BUILTIN_OBJS += builtin-check-ref-format.o
 -BUILTIN_OBJS += builtin-checkout-index.o
 -BUILTIN_OBJS += builtin-checkout.o
 -BUILTIN_OBJS += builtin-clean.o
 -BUILTIN_OBJS += builtin-clone.o
 -BUILTIN_OBJS += builtin-commit-tree.o
 -BUILTIN_OBJS += builtin-commit.o
 -BUILTIN_OBJS += builtin-config.o
 -BUILTIN_OBJS += builtin-count-objects.o
 -BUILTIN_OBJS += builtin-describe.o
 -BUILTIN_OBJS += builtin-diff-files.o
 -BUILTIN_OBJS += builtin-diff-index.o
 -BUILTIN_OBJS += builtin-diff-tree.o
 -BUILTIN_OBJS += builtin-diff.o
 -BUILTIN_OBJS += builtin-fast-export.o
 -BUILTIN_OBJS += builtin-fetch-pack.o
 -BUILTIN_OBJS += builtin-fetch.o
 -BUILTIN_OBJS += builtin-fmt-merge-msg.o
 -BUILTIN_OBJS += builtin-for-each-ref.o
 -BUILTIN_OBJS += builtin-fsck.o
 -BUILTIN_OBJS += builtin-gc.o
 -BUILTIN_OBJS += builtin-grep.o
 -BUILTIN_OBJS += builtin-hash-object.o
 -BUILTIN_OBJS += builtin-help.o
 -BUILTIN_OBJS += builtin-index-pack.o
 -BUILTIN_OBJS += builtin-init-db.o
 -BUILTIN_OBJS += builtin-log.o
 -BUILTIN_OBJS += builtin-ls-files.o
 -BUILTIN_OBJS += builtin-ls-remote.o
 -BUILTIN_OBJS += builtin-ls-tree.o
 -BUILTIN_OBJS += builtin-mailinfo.o
 -BUILTIN_OBJS += builtin-mailsplit.o
 -BUILTIN_OBJS += builtin-merge.o
 -BUILTIN_OBJS += builtin-merge-base.o
 -BUILTIN_OBJS += builtin-merge-file.o
 -BUILTIN_OBJS += builtin-merge-index.o
 -BUILTIN_OBJS += builtin-merge-ours.o
 -BUILTIN_OBJS += builtin-merge-recursive.o
 -BUILTIN_OBJS += builtin-merge-tree.o
 -BUILTIN_OBJS += builtin-mktag.o
 -BUILTIN_OBJS += builtin-mktree.o
 -BUILTIN_OBJS += builtin-mv.o
 -BUILTIN_OBJS += builtin-name-rev.o
 -BUILTIN_OBJS += builtin-pack-objects.o
 -BUILTIN_OBJS += builtin-pack-redundant.o
 -BUILTIN_OBJS += builtin-pack-refs.o
 -BUILTIN_OBJS += builtin-patch-id.o
 -BUILTIN_OBJS += builtin-prune-packed.o
 -BUILTIN_OBJS += builtin-prune.o
 -BUILTIN_OBJS += builtin-push.o
 -BUILTIN_OBJS += builtin-read-tree.o
 -BUILTIN_OBJS += builtin-receive-pack.o
 -BUILTIN_OBJS += builtin-reflog.o
 -BUILTIN_OBJS += builtin-remote.o
 -BUILTIN_OBJS += builtin-replace.o
 -BUILTIN_OBJS += builtin-rerere.o
 -BUILTIN_OBJS += builtin-reset.o
 -BUILTIN_OBJS += builtin-rev-list.o
 -BUILTIN_OBJS += builtin-rev-parse.o
 -BUILTIN_OBJS += builtin-revert.o
 -BUILTIN_OBJS += builtin-rm.o
 -BUILTIN_OBJS += builtin-send-pack.o
 -BUILTIN_OBJS += builtin-shortlog.o
 -BUILTIN_OBJS += builtin-show-branch.o
 -BUILTIN_OBJS += builtin-show-ref.o
 -BUILTIN_OBJS += builtin-stripspace.o
 -BUILTIN_OBJS += builtin-symbolic-ref.o
 -BUILTIN_OBJS += builtin-tag.o
 -BUILTIN_OBJS += builtin-tar-tree.o
 -BUILTIN_OBJS += builtin-unpack-file.o
 -BUILTIN_OBJS += builtin-unpack-objects.o
 -BUILTIN_OBJS += builtin-update-index.o
 -BUILTIN_OBJS += builtin-update-ref.o
 -BUILTIN_OBJS += builtin-update-server-info.o
 -BUILTIN_OBJS += builtin-upload-archive.o
 -BUILTIN_OBJS += builtin-var.o
 -BUILTIN_OBJS += builtin-verify-pack.o
 -BUILTIN_OBJS += builtin-verify-tag.o
 -BUILTIN_OBJS += builtin-write-tree.o
 +BUILTIN_OBJS += builtin/add.o
 +BUILTIN_OBJS += builtin/annotate.o
 +BUILTIN_OBJS += builtin/apply.o
 +BUILTIN_OBJS += builtin/archive.o
 +BUILTIN_OBJS += builtin/bisect--helper.o
 +BUILTIN_OBJS += builtin/blame.o
 +BUILTIN_OBJS += builtin/branch.o
 +BUILTIN_OBJS += builtin/bundle.o
 +BUILTIN_OBJS += builtin/cat-file.o
 +BUILTIN_OBJS += builtin/check-attr.o
 +BUILTIN_OBJS += builtin/check-ref-format.o
 +BUILTIN_OBJS += builtin/checkout-index.o
 +BUILTIN_OBJS += builtin/checkout.o
 +BUILTIN_OBJS += builtin/clean.o
 +BUILTIN_OBJS += builtin/clone.o
 +BUILTIN_OBJS += builtin/commit-tree.o
 +BUILTIN_OBJS += builtin/commit.o
 +BUILTIN_OBJS += builtin/config.o
 +BUILTIN_OBJS += builtin/count-objects.o
 +BUILTIN_OBJS += builtin/describe.o
 +BUILTIN_OBJS += builtin/diff-files.o
 +BUILTIN_OBJS += builtin/diff-index.o
 +BUILTIN_OBJS += builtin/diff-tree.o
 +BUILTIN_OBJS += builtin/diff.o
 +BUILTIN_OBJS += builtin/fast-export.o
 +BUILTIN_OBJS += builtin/fetch-pack.o
 +BUILTIN_OBJS += builtin/fetch.o
 +BUILTIN_OBJS += builtin/fmt-merge-msg.o
 +BUILTIN_OBJS += builtin/for-each-ref.o
 +BUILTIN_OBJS += builtin/fsck.o
 +BUILTIN_OBJS += builtin/gc.o
 +BUILTIN_OBJS += builtin/grep.o
 +BUILTIN_OBJS += builtin/hash-object.o
 +BUILTIN_OBJS += builtin/help.o
 +BUILTIN_OBJS += builtin/index-pack.o
 +BUILTIN_OBJS += builtin/init-db.o
 +BUILTIN_OBJS += builtin/log.o
 +BUILTIN_OBJS += builtin/ls-files.o
 +BUILTIN_OBJS += builtin/ls-remote.o
 +BUILTIN_OBJS += builtin/ls-tree.o
 +BUILTIN_OBJS += builtin/mailinfo.o
 +BUILTIN_OBJS += builtin/mailsplit.o
 +BUILTIN_OBJS += builtin/merge.o
 +BUILTIN_OBJS += builtin/merge-base.o
 +BUILTIN_OBJS += builtin/merge-file.o
 +BUILTIN_OBJS += builtin/merge-index.o
 +BUILTIN_OBJS += builtin/merge-ours.o
 +BUILTIN_OBJS += builtin/merge-recursive.o
 +BUILTIN_OBJS += builtin/merge-tree.o
 +BUILTIN_OBJS += builtin/mktag.o
 +BUILTIN_OBJS += builtin/mktree.o
 +BUILTIN_OBJS += builtin/mv.o
 +BUILTIN_OBJS += builtin/name-rev.o
 +BUILTIN_OBJS += builtin/notes.o
 +BUILTIN_OBJS += builtin/pack-objects.o
 +BUILTIN_OBJS += builtin/pack-redundant.o
 +BUILTIN_OBJS += builtin/pack-refs.o
 +BUILTIN_OBJS += builtin/patch-id.o
 +BUILTIN_OBJS += builtin/prune-packed.o
 +BUILTIN_OBJS += builtin/prune.o
 +BUILTIN_OBJS += builtin/push.o
 +BUILTIN_OBJS += builtin/read-tree.o
 +BUILTIN_OBJS += builtin/receive-pack.o
 +BUILTIN_OBJS += builtin/reflog.o
 +BUILTIN_OBJS += builtin/remote.o
 +BUILTIN_OBJS += builtin/replace.o
 +BUILTIN_OBJS += builtin/rerere.o
 +BUILTIN_OBJS += builtin/reset.o
 +BUILTIN_OBJS += builtin/rev-list.o
 +BUILTIN_OBJS += builtin/rev-parse.o
 +BUILTIN_OBJS += builtin/revert.o
 +BUILTIN_OBJS += builtin/rm.o
 +BUILTIN_OBJS += builtin/send-pack.o
 +BUILTIN_OBJS += builtin/shortlog.o
 +BUILTIN_OBJS += builtin/show-branch.o
 +BUILTIN_OBJS += builtin/show-ref.o
 +BUILTIN_OBJS += builtin/stripspace.o
 +BUILTIN_OBJS += builtin/symbolic-ref.o
 +BUILTIN_OBJS += builtin/tag.o
 +BUILTIN_OBJS += builtin/tar-tree.o
 +BUILTIN_OBJS += builtin/unpack-file.o
 +BUILTIN_OBJS += builtin/unpack-objects.o
 +BUILTIN_OBJS += builtin/update-index.o
 +BUILTIN_OBJS += builtin/update-ref.o
 +BUILTIN_OBJS += builtin/update-server-info.o
 +BUILTIN_OBJS += builtin/upload-archive.o
 +BUILTIN_OBJS += builtin/var.o
 +BUILTIN_OBJS += builtin/verify-pack.o
 +BUILTIN_OBJS += builtin/verify-tag.o
 +BUILTIN_OBJS += builtin/write-tree.o
  
  GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
  EXTLIBS =
@@@ -1053,14 -1026,6 +1059,14 @@@ endi
  -include config.mak.autogen
  -include config.mak
  
 +ifdef CHECK_HEADER_DEPENDENCIES
 +USE_COMPUTED_HEADER_DEPENDENCIES =
 +endif
 +
 +ifdef COMPUTE_HEADER_DEPENDENCIES
 +USE_COMPUTED_HEADER_DEPENDENCIES = YesPlease
 +endif
 +
  ifdef SANE_TOOL_PATH
  SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
  BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
        REMOTE_CURL_PRIMARY = git-remote-http$X
        REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
        REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES)
 -      PROGRAMS += $(REMOTE_CURL_NAMES) git-http-fetch$X
 +      PROGRAM_OBJS += http-fetch.o
 +      PROGRAMS += $(REMOTE_CURL_NAMES)
        curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
        ifeq "$(curl_check)" "070908"
                ifndef NO_EXPAT
 -                      PROGRAMS += git-http-push$X
 +                      PROGRAM_OBJS += http-push.o
                endif
        endif
        ifndef NO_EXPAT
@@@ -1141,7 -1105,7 +1147,7 @@@ endi
  EXTLIBS += -lz
  
  ifndef NO_POSIX_ONLY_PROGRAMS
 -      PROGRAMS += git-daemon$X
 +      PROGRAM_OBJS += daemon.o
  endif
  ifndef NO_OPENSSL
        OPENSSL_LIBSSL = -lssl
@@@ -1307,12 -1271,10 +1313,12 @@@ endi
  ifdef BLK_SHA1
        SHA1_HEADER = "block-sha1/sha1.h"
        LIB_OBJS += block-sha1/sha1.o
 +      LIB_H += block-sha1/sha1.h
  else
  ifdef PPC_SHA1
        SHA1_HEADER = "ppc/sha1.h"
        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
 +      LIB_H += ppc/sha1.h
  else
        SHA1_HEADER = <openssl/sha.h>
        EXTLIBS += $(LIB_4_CRYPTO)
@@@ -1454,7 -1416,7 +1460,7 @@@ export TAR INSTALL DESTDIR SHELL_PAT
  
  SHELL = $(SHELL_PATH)
  
 -all:: shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
 +all:: shell_compatibility_test $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
  ifneq (,$X)
        $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
  endif
@@@ -1481,15 -1443,15 +1487,15 @@@ strip: $(PROGRAMS) git$
        $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
  
  git.o: common-cmds.h
 -git.s git.o: ALL_CFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' \
 +git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
        '-DGIT_HTML_PATH="$(htmldir_SQ)"'
  
  git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
                $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
  
 -builtin-help.o: common-cmds.h
 -builtin-help.s builtin-help.o: ALL_CFLAGS += \
 +builtin/help.o: common-cmds.h
 +builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
        '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
        '-DGIT_MAN_PATH="$(mandir_SQ)"' \
        '-DGIT_INFO_PATH="$(infodir_SQ)"'
@@@ -1505,25 -1467,17 +1511,25 @@@ common-cmds.h: ./generate-cmdlist.sh co
  common-cmds.h: $(wildcard Documentation/git-*.txt)
        $(QUIET_GEN)./generate-cmdlist.sh > $@+ && mv $@+ $@
  
 +define cmd_munge_script
 +$(RM) $@ $@+ && \
 +sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 +    -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
 +    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 +    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
 +    -e $(BROKEN_PATH_FIX) \
 +    $@.sh >$@+
 +endef
 +
  $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
 -      $(QUIET_GEN)$(RM) $@ $@+ && \
 -      sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 -          -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
 -          -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 -          -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
 -          -e $(BROKEN_PATH_FIX) \
 -          $@.sh >$@+ && \
 +      $(QUIET_GEN)$(cmd_munge_script) && \
        chmod +x $@+ && \
        mv $@+ $@
  
 +$(SCRIPT_LIB) : % : %.sh
 +      $(QUIET_GEN)$(cmd_munge_script) && \
 +      mv $@+ $@
 +
  ifndef NO_PERL
  $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak
  
@@@ -1633,148 -1587,28 +1639,148 @@@ git.o git.spec 
        $(patsubst %.perl,%,$(SCRIPT_PERL)) \
        : GIT-VERSION-FILE
  
 -%.o: %.c GIT-CFLAGS
 -      $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 +TEST_OBJS := $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
 +GIT_OBJS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
 +      git.o http.o http-walker.o remote-curl.o
 +XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
 +      xdiff/xmerge.o xdiff/xpatience.o
 +OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS)
 +
 +dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
 +dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
 +
 +ifdef COMPUTE_HEADER_DEPENDENCIES
 +$(dep_dirs):
 +      mkdir -p $@
 +
 +missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
 +dep_file = $(dir $@).depend/$(notdir $@).d
 +dep_args = -MF $(dep_file) -MMD -MP
 +ifdef CHECK_HEADER_DEPENDENCIES
 +$(error cannot compute header dependencies outside a normal build. \
 +Please unset CHECK_HEADER_DEPENDENCIES and try again)
 +endif
 +endif
 +
 +ifndef COMPUTE_HEADER_DEPENDENCIES
 +ifndef CHECK_HEADER_DEPENDENCIES
 +dep_dirs =
 +missing_dep_dirs =
 +dep_args =
 +endif
 +endif
 +
 +ifdef CHECK_HEADER_DEPENDENCIES
 +ifndef PRINT_HEADER_DEPENDENCIES
 +missing_deps = $(filter-out $(notdir $^), \
 +      $(notdir $(shell $(MAKE) -s $@ \
 +              CHECK_HEADER_DEPENDENCIES=YesPlease \
 +              USE_COMPUTED_HEADER_DEPENDENCIES=YesPlease \
 +              PRINT_HEADER_DEPENDENCIES=YesPlease)))
 +endif
 +endif
 +
 +ASM_SRC := $(wildcard $(OBJECTS:o=S))
 +ASM_OBJ := $(ASM_SRC:S=o)
 +C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS))
 +
 +.SUFFIXES:
 +
 +ifdef PRINT_HEADER_DEPENDENCIES
 +$(C_OBJ): %.o: %.c FORCE
 +      echo $^
 +$(ASM_OBJ): %.o: %.S FORCE
 +      echo $^
 +
 +ifndef CHECK_HEADER_DEPENDENCIES
 +$(error cannot print header dependencies during a normal build. \
 +Please set CHECK_HEADER_DEPENDENCIES and try again)
 +endif
 +endif
 +
 +ifndef PRINT_HEADER_DEPENDENCIES
 +ifdef CHECK_HEADER_DEPENDENCIES
 +$(C_OBJ): %.o: %.c $(dep_files) FORCE
 +      @set -e; echo CHECK $@; \
 +      missing_deps="$(missing_deps)"; \
 +      if test "$$missing_deps"; \
 +      then \
 +              echo missing dependencies: $$missing_deps; \
 +              false; \
 +      fi
 +$(ASM_OBJ): %.o: %.S $(dep_files) FORCE
 +      @set -e; echo CHECK $@; \
 +      missing_deps="$(missing_deps)"; \
 +      if test "$$missing_deps"; \
 +      then \
 +              echo missing dependencies: $$missing_deps; \
 +              false; \
 +      fi
 +endif
 +endif
 +
 +ifndef CHECK_HEADER_DEPENDENCIES
 +$(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs)
 +      $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
 +$(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs)
 +      $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
 +endif
 +
  %.s: %.c GIT-CFLAGS FORCE
 -      $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 -%.o: %.S GIT-CFLAGS
 -      $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
 +      $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
  
 -exec_cmd.s exec_cmd.o: ALL_CFLAGS += \
 +ifdef USE_COMPUTED_HEADER_DEPENDENCIES
 +# Take advantage of gcc's on-the-fly dependency generation
 +# See <http://gcc.gnu.org/gcc-3.0/features.html>.
 +dep_files_present := $(wildcard $(dep_files))
 +ifneq ($(dep_files_present),)
 +include $(dep_files_present)
 +endif
 +else
 +# Dependencies on header files, for platforms that do not support
 +# the gcc -MMD option.
 +#
 +# Dependencies on automatically generated headers such as common-cmds.h
 +# should _not_ be included here, since they are necessary even when
 +# building an object for the first time.
 +#
 +# XXX. Please check occasionally that these include all dependencies
 +# gcc detects!
 +
 +$(GIT_OBJS): $(LIB_H)
 +builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o transport.o: branch.h
 +builtin/bundle.o bundle.o transport.o: bundle.h
 +builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h
 +builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h
 +builtin/grep.o: thread-utils.h
 +builtin/send-pack.o transport.o: send-pack.h
 +builtin/log.o builtin/shortlog.o: shortlog.h
 +builtin/prune.o builtin/reflog.o reachable.o: reachable.h
 +builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
 +builtin/tar-tree.o archive-tar.o: tar.h
 +builtin/pack-objects.o: thread-utils.h
 +http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
 +http.o http-walker.o http-push.o remote-curl.o: http.h
 +
 +xdiff-interface.o $(XDIFF_OBJS): \
 +      xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
 +      xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
 +endif
 +
 +exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
        '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
        '-DBINDIR="$(bindir_relative_SQ)"' \
        '-DPREFIX="$(prefix_SQ)"'
  
 -builtin-init-db.s builtin-init-db.o: ALL_CFLAGS += \
 +builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
        -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
  
 -config.s config.o: ALL_CFLAGS += -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
 +config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
  
 -http.s http.o: ALL_CFLAGS += -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
 +http.s http.o: EXTRA_CPPFLAGS = -DGIT_USER_AGENT='"git/$(GIT_VERSION)"'
  
  ifdef NO_EXPAT
 -http-walker.o: http.h
 -http-walker.s http-walker.o: ALL_CFLAGS += -DNO_EXPAT
 +http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
  endif
  
  git-%$X: %.o $(GITLIBS)
@@@ -1784,6 -1618,10 +1790,6 @@@ git-imap-send$X: imap-send.o $(GITLIBS
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
  
 -http.o http-walker.o http-push.o: http.h
 -
 -http.o http-walker.o: $(LIB_H)
 -
  git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL)
@@@ -1801,9 -1639,18 +1807,9 @@@ $(REMOTE_CURL_PRIMARY): remote-curl.o h
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
  
 -$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
 -$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h)
 -builtin-revert.o wt-status.o: wt-status.h
 -
  $(LIB_FILE): $(LIB_OBJS)
        $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
  
 -XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
 -      xdiff/xmerge.o xdiff/xpatience.o
 -$(XDIFF_OBJS): xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \
 -      xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h
 -
  $(XDIFF_LIB): $(XDIFF_OBJS)
        $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS)
  
@@@ -1869,6 -1716,24 +1875,6 @@@ GIT-GUI-VARS: FORC
              fi
  endif
  
 -### Testing rules
 -
 -TEST_PROGRAMS_NEED_X += test-chmtime
 -TEST_PROGRAMS_NEED_X += test-ctype
 -TEST_PROGRAMS_NEED_X += test-date
 -TEST_PROGRAMS_NEED_X += test-delta
 -TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 -TEST_PROGRAMS_NEED_X += test-genrandom
 -TEST_PROGRAMS_NEED_X += test-match-trees
 -TEST_PROGRAMS_NEED_X += test-parse-options
 -TEST_PROGRAMS_NEED_X += test-path-utils
 -TEST_PROGRAMS_NEED_X += test-run-command
 -TEST_PROGRAMS_NEED_X += test-sha1
 -TEST_PROGRAMS_NEED_X += test-sigchain
 -TEST_PROGRAMS_NEED_X += test-index-version
 -
 -TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
 -
  test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
  
  all:: $(TEST_PROGRAMS) $(test_bindir_programs)
@@@ -1886,8 -1751,6 +1892,8 @@@ bin-wrappers/%: wrap-for-bin.s
  
  export NO_SVN_TESTS
  
 +### Testing rules
 +
  test: all
        $(MAKE) -C t/ all
  
@@@ -1899,7 -1762,9 +1905,7 @@@ test-delta$X: diff-delta.o patch-delta.
  
  test-parse-options$X: parse-options.o
  
 -test-parse-options.o: parse-options.h
 -
 -.PRECIOUS: $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS))
 +.PRECIOUS: $(TEST_OBJS)
  
  test-%$X: test-%.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
@@@ -1945,7 -1810,6 +1951,7 @@@ install: al
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
  ifndef NO_PERL
@@@ -2064,11 -1928,10 +2070,11 @@@ distclean: clea
  
  clean:
        $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \
 -              $(LIB_FILE) $(XDIFF_LIB)
 -      $(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
 +              builtin/*.o $(LIB_FILE) $(XDIFF_LIB)
 +      $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
        $(RM) -r bin-wrappers
 +      $(RM) -r $(dep_dirs)
        $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
        $(RM) -r autom4te.cache
        $(RM) config.log config.mak.autogen config.mak.append config.status config.cache
@@@ -2098,13 -1961,12 +2104,13 @@@ endi
  ### Check documentation
  #
  check-docs::
 -      @(for v in $(ALL_PROGRAMS) $(BUILT_INS) git gitk; \
 +      @(for v in $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git gitk; \
        do \
                case "$$v" in \
                git-merge-octopus | git-merge-ours | git-merge-recursive | \
                git-merge-resolve | git-merge-subtree | \
                git-fsck-objects | git-init-db | \
 +              git-remote-* | git-stage | \
                git-?*--?* ) continue ;; \
                esac ; \
                test -f "Documentation/$$v.txt" || \
                documented,gitrepository-layout | \
                documented,gittutorial | \
                documented,gittutorial-2 | \
 +              documented,git-bisect-lk2009 | \
 +              documented,git-remote-helpers | \
 +              documented,gitworkflows | \
                sentinel,not,matching,is,ok ) continue ;; \
                esac; \
 -              case " $(ALL_PROGRAMS) $(BUILT_INS) git gitk " in \
 +              case " $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git gitk " in \
                *" $$cmd "*)    ;; \
                *) echo "removed but $$how: $$cmd" ;; \
                esac; \
diff --combined builtin/fetch.c
index 2bb75c130526d506b066c890cf165302dbb3c14d,0000000000000000000000000000000000000000..957be9f9269c657fb094b1b3daa4f309c1324ae0
mode 100644,000000..100644
--- /dev/null
@@@ -1,941 -1,0 +1,940 @@@
-               refspec.dst = NULL;
-               refspec.pattern = 0;
-               refspec.force = 0;
 +/*
 + * "git fetch"
 + */
 +#include "cache.h"
 +#include "refs.h"
 +#include "commit.h"
 +#include "builtin.h"
 +#include "string-list.h"
 +#include "remote.h"
 +#include "transport.h"
 +#include "run-command.h"
 +#include "parse-options.h"
 +#include "sigchain.h"
 +#include "transport.h"
 +
 +static const char * const builtin_fetch_usage[] = {
 +      "git fetch [options] [<repository> <refspec>...]",
 +      "git fetch [options] <group>",
 +      "git fetch --multiple [options] [<repository> | <group>]...",
 +      "git fetch --all [options]",
 +      NULL
 +};
 +
 +enum {
 +      TAGS_UNSET = 0,
 +      TAGS_DEFAULT = 1,
 +      TAGS_SET = 2
 +};
 +
 +static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
 +static int progress;
 +static int tags = TAGS_DEFAULT;
 +static const char *depth;
 +static const char *upload_pack;
 +static struct strbuf default_rla = STRBUF_INIT;
 +static struct transport *transport;
 +
 +static struct option builtin_fetch_options[] = {
 +      OPT__VERBOSITY(&verbosity),
 +      OPT_BOOLEAN(0, "all", &all,
 +                  "fetch from all remotes"),
 +      OPT_BOOLEAN('a', "append", &append,
 +                  "append to .git/FETCH_HEAD instead of overwriting"),
 +      OPT_STRING(0, "upload-pack", &upload_pack, "PATH",
 +                 "path to upload pack on remote end"),
 +      OPT_BOOLEAN('f', "force", &force,
 +                  "force overwrite of local branch"),
 +      OPT_BOOLEAN('m', "multiple", &multiple,
 +                  "fetch from multiple remotes"),
 +      OPT_SET_INT('t', "tags", &tags,
 +                  "fetch all tags and associated objects", TAGS_SET),
 +      OPT_SET_INT('n', NULL, &tags,
 +                  "do not fetch all tags (--no-tags)", TAGS_UNSET),
 +      OPT_BOOLEAN('p', "prune", &prune,
 +                  "prune tracking branches no longer on remote"),
 +      OPT_BOOLEAN(0, "dry-run", &dry_run,
 +                  "dry run"),
 +      OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
 +      OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
 +                  "allow updating of HEAD ref"),
 +      OPT_BOOLEAN(0, "progress", &progress, "force progress reporting"),
 +      OPT_STRING(0, "depth", &depth, "DEPTH",
 +                 "deepen history of shallow clone"),
 +      OPT_END()
 +};
 +
 +static void unlock_pack(void)
 +{
 +      if (transport)
 +              transport_unlock_pack(transport);
 +}
 +
 +static void unlock_pack_on_signal(int signo)
 +{
 +      unlock_pack();
 +      sigchain_pop(signo);
 +      raise(signo);
 +}
 +
 +static void add_merge_config(struct ref **head,
 +                         const struct ref *remote_refs,
 +                         struct branch *branch,
 +                         struct ref ***tail)
 +{
 +      int i;
 +
 +      for (i = 0; i < branch->merge_nr; i++) {
 +              struct ref *rm, **old_tail = *tail;
 +              struct refspec refspec;
 +
 +              for (rm = *head; rm; rm = rm->next) {
 +                      if (branch_merge_matches(branch, i, rm->name)) {
 +                              rm->merge = 1;
 +                              break;
 +                      }
 +              }
 +              if (rm)
 +                      continue;
 +
 +              /*
 +               * Not fetched to a tracking branch?  We need to fetch
 +               * it anyway to allow this branch's "branch.$name.merge"
 +               * to be honored by 'git pull', but we do not have to
 +               * fail if branch.$name.merge is misconfigured to point
 +               * at a nonexisting branch.  If we were indeed called by
 +               * 'git pull', it will notice the misconfiguration because
 +               * there is no entry in the resulting FETCH_HEAD marked
 +               * for merging.
 +               */
++              memset(&refspec, 0, sizeof(refspec));
 +              refspec.src = branch->merge[i]->src;
-               if (ref)
 +              get_fetch_map(remote_refs, &refspec, tail, 1);
 +              for (rm = *old_tail; rm; rm = rm->next)
 +                      rm->merge = 1;
 +      }
 +}
 +
 +static void find_non_local_tags(struct transport *transport,
 +                      struct ref **head,
 +                      struct ref ***tail);
 +
 +static struct ref *get_ref_map(struct transport *transport,
 +                             struct refspec *refs, int ref_count, int tags,
 +                             int *autotags)
 +{
 +      int i;
 +      struct ref *rm;
 +      struct ref *ref_map = NULL;
 +      struct ref **tail = &ref_map;
 +
 +      const struct ref *remote_refs = transport_get_remote_refs(transport);
 +
 +      if (ref_count || tags == TAGS_SET) {
 +              for (i = 0; i < ref_count; i++) {
 +                      get_fetch_map(remote_refs, &refs[i], &tail, 0);
 +                      if (refs[i].dst && refs[i].dst[0])
 +                              *autotags = 1;
 +              }
 +              /* Merge everything on the command line, but not --tags */
 +              for (rm = ref_map; rm; rm = rm->next)
 +                      rm->merge = 1;
 +              if (tags == TAGS_SET)
 +                      get_fetch_map(remote_refs, tag_refspec, &tail, 0);
 +      } else {
 +              /* Use the defaults */
 +              struct remote *remote = transport->remote;
 +              struct branch *branch = branch_get(NULL);
 +              int has_merge = branch_has_merge_config(branch);
 +              if (remote && (remote->fetch_refspec_nr || has_merge)) {
 +                      for (i = 0; i < remote->fetch_refspec_nr; i++) {
 +                              get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0);
 +                              if (remote->fetch[i].dst &&
 +                                  remote->fetch[i].dst[0])
 +                                      *autotags = 1;
 +                              if (!i && !has_merge && ref_map &&
 +                                  !remote->fetch[0].pattern)
 +                                      ref_map->merge = 1;
 +                      }
 +                      /*
 +                       * if the remote we're fetching from is the same
 +                       * as given in branch.<name>.remote, we add the
 +                       * ref given in branch.<name>.merge, too.
 +                       */
 +                      if (has_merge &&
 +                          !strcmp(branch->remote_name, remote->name))
 +                              add_merge_config(&ref_map, remote_refs, branch, &tail);
 +              } else {
 +                      ref_map = get_remote_ref(remote_refs, "HEAD");
 +                      if (!ref_map)
 +                              die("Couldn't find remote ref HEAD");
 +                      ref_map->merge = 1;
 +                      tail = &ref_map->next;
 +              }
 +      }
 +      if (tags == TAGS_DEFAULT && *autotags)
 +              find_non_local_tags(transport, &ref_map, &tail);
 +      ref_remove_duplicates(ref_map);
 +
 +      return ref_map;
 +}
 +
 +#define STORE_REF_ERROR_OTHER 1
 +#define STORE_REF_ERROR_DF_CONFLICT 2
 +
 +static int s_update_ref(const char *action,
 +                      struct ref *ref,
 +                      int check_old)
 +{
 +      char msg[1024];
 +      char *rla = getenv("GIT_REFLOG_ACTION");
 +      static struct ref_lock *lock;
 +
 +      if (dry_run)
 +              return 0;
 +      if (!rla)
 +              rla = default_rla.buf;
 +      snprintf(msg, sizeof(msg), "%s: %s", rla, action);
 +      lock = lock_any_ref_for_update(ref->name,
 +                                     check_old ? ref->old_sha1 : NULL, 0);
 +      if (!lock)
 +              return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
 +                                        STORE_REF_ERROR_OTHER;
 +      if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
 +              return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
 +                                        STORE_REF_ERROR_OTHER;
 +      return 0;
 +}
 +
 +#define REFCOL_WIDTH  10
 +
 +static int update_local_ref(struct ref *ref,
 +                          const char *remote,
 +                          char *display)
 +{
 +      struct commit *current = NULL, *updated;
 +      enum object_type type;
 +      struct branch *current_branch = branch_get(NULL);
 +      const char *pretty_ref = prettify_refname(ref->name);
 +
 +      *display = 0;
 +      type = sha1_object_info(ref->new_sha1, NULL);
 +      if (type < 0)
 +              die("object %s not found", sha1_to_hex(ref->new_sha1));
 +
 +      if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
 +              if (verbosity > 0)
 +                      sprintf(display, "= %-*s %-*s -> %s", TRANSPORT_SUMMARY_WIDTH,
 +                              "[up to date]", REFCOL_WIDTH, remote,
 +                              pretty_ref);
 +              return 0;
 +      }
 +
 +      if (current_branch &&
 +          !strcmp(ref->name, current_branch->name) &&
 +          !(update_head_ok || is_bare_repository()) &&
 +          !is_null_sha1(ref->old_sha1)) {
 +              /*
 +               * If this is the head, and it's not okay to update
 +               * the head, and the old value of the head isn't empty...
 +               */
 +              sprintf(display, "! %-*s %-*s -> %s  (can't fetch in current branch)",
 +                      TRANSPORT_SUMMARY_WIDTH, "[rejected]", REFCOL_WIDTH, remote,
 +                      pretty_ref);
 +              return 1;
 +      }
 +
 +      if (!is_null_sha1(ref->old_sha1) &&
 +          !prefixcmp(ref->name, "refs/tags/")) {
 +              int r;
 +              r = s_update_ref("updating tag", ref, 0);
 +              sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '-',
 +                      TRANSPORT_SUMMARY_WIDTH, "[tag update]", REFCOL_WIDTH, remote,
 +                      pretty_ref, r ? "  (unable to update local ref)" : "");
 +              return r;
 +      }
 +
 +      current = lookup_commit_reference_gently(ref->old_sha1, 1);
 +      updated = lookup_commit_reference_gently(ref->new_sha1, 1);
 +      if (!current || !updated) {
 +              const char *msg;
 +              const char *what;
 +              int r;
 +              if (!strncmp(ref->name, "refs/tags/", 10)) {
 +                      msg = "storing tag";
 +                      what = "[new tag]";
 +              }
 +              else {
 +                      msg = "storing head";
 +                      what = "[new branch]";
 +              }
 +
 +              r = s_update_ref(msg, ref, 0);
 +              sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '*',
 +                      TRANSPORT_SUMMARY_WIDTH, what, REFCOL_WIDTH, remote, pretty_ref,
 +                      r ? "  (unable to update local ref)" : "");
 +              return r;
 +      }
 +
 +      if (in_merge_bases(current, &updated, 1)) {
 +              char quickref[83];
 +              int r;
 +              strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
 +              strcat(quickref, "..");
 +              strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
 +              r = s_update_ref("fast-forward", ref, 1);
 +              sprintf(display, "%c %-*s %-*s -> %s%s", r ? '!' : ' ',
 +                      TRANSPORT_SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote,
 +                      pretty_ref, r ? "  (unable to update local ref)" : "");
 +              return r;
 +      } else if (force || ref->force) {
 +              char quickref[84];
 +              int r;
 +              strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
 +              strcat(quickref, "...");
 +              strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
 +              r = s_update_ref("forced-update", ref, 1);
 +              sprintf(display, "%c %-*s %-*s -> %s  (%s)", r ? '!' : '+',
 +                      TRANSPORT_SUMMARY_WIDTH, quickref, REFCOL_WIDTH, remote,
 +                      pretty_ref,
 +                      r ? "unable to update local ref" : "forced update");
 +              return r;
 +      } else {
 +              sprintf(display, "! %-*s %-*s -> %s  (non-fast-forward)",
 +                      TRANSPORT_SUMMARY_WIDTH, "[rejected]", REFCOL_WIDTH, remote,
 +                      pretty_ref);
 +              return 1;
 +      }
 +}
 +
 +static int store_updated_refs(const char *raw_url, const char *remote_name,
 +              struct ref *ref_map)
 +{
 +      FILE *fp;
 +      struct commit *commit;
 +      int url_len, i, note_len, shown_url = 0, rc = 0;
 +      char note[1024];
 +      const char *what, *kind;
 +      struct ref *rm;
 +      char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
 +
 +      fp = fopen(filename, "a");
 +      if (!fp)
 +              return error("cannot open %s: %s\n", filename, strerror(errno));
 +
 +      if (raw_url)
 +              url = transport_anonymize_url(raw_url);
 +      else
 +              url = xstrdup("foreign");
 +      for (rm = ref_map; rm; rm = rm->next) {
 +              struct ref *ref = NULL;
 +
 +              if (rm->peer_ref) {
 +                      ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
 +                      strcpy(ref->name, rm->peer_ref->name);
 +                      hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
 +                      hashcpy(ref->new_sha1, rm->old_sha1);
 +                      ref->force = rm->peer_ref->force;
 +              }
 +
 +              commit = lookup_commit_reference_gently(rm->old_sha1, 1);
 +              if (!commit)
 +                      rm->merge = 0;
 +
 +              if (!strcmp(rm->name, "HEAD")) {
 +                      kind = "";
 +                      what = "";
 +              }
 +              else if (!prefixcmp(rm->name, "refs/heads/")) {
 +                      kind = "branch";
 +                      what = rm->name + 11;
 +              }
 +              else if (!prefixcmp(rm->name, "refs/tags/")) {
 +                      kind = "tag";
 +                      what = rm->name + 10;
 +              }
 +              else if (!prefixcmp(rm->name, "refs/remotes/")) {
 +                      kind = "remote branch";
 +                      what = rm->name + 13;
 +              }
 +              else {
 +                      kind = "";
 +                      what = rm->name;
 +              }
 +
 +              url_len = strlen(url);
 +              for (i = url_len - 1; url[i] == '/' && 0 <= i; i--)
 +                      ;
 +              url_len = i + 1;
 +              if (4 < i && !strncmp(".git", url + i - 3, 4))
 +                      url_len = i - 3;
 +
 +              note_len = 0;
 +              if (*what) {
 +                      if (*kind)
 +                              note_len += sprintf(note + note_len, "%s ",
 +                                                  kind);
 +                      note_len += sprintf(note + note_len, "'%s' of ", what);
 +              }
 +              note[note_len] = '\0';
 +              fprintf(fp, "%s\t%s\t%s",
 +                      sha1_to_hex(commit ? commit->object.sha1 :
 +                                  rm->old_sha1),
 +                      rm->merge ? "" : "not-for-merge",
 +                      note);
 +              for (i = 0; i < url_len; ++i)
 +                      if ('\n' == url[i])
 +                              fputs("\\n", fp);
 +                      else
 +                              fputc(url[i], fp);
 +              fputc('\n', fp);
 +
-               else
++              if (ref) {
 +                      rc |= update_local_ref(ref, what, note);
-               if (!strcmp(ref->name + strlen(ref->name) - 3, "^{}")) {
++                      free(ref);
++              } else
 +                      sprintf(note, "* %-*s %-*s -> FETCH_HEAD",
 +                              TRANSPORT_SUMMARY_WIDTH, *kind ? kind : "branch",
 +                               REFCOL_WIDTH, *what ? what : "HEAD");
 +              if (*note) {
 +                      if (verbosity >= 0 && !shown_url) {
 +                              fprintf(stderr, "From %.*s\n",
 +                                              url_len, url);
 +                              shown_url = 1;
 +                      }
 +                      if (verbosity >= 0)
 +                              fprintf(stderr, " %s\n", note);
 +              }
 +      }
 +      free(url);
 +      fclose(fp);
 +      if (rc & STORE_REF_ERROR_DF_CONFLICT)
 +              error("some local refs could not be updated; try running\n"
 +                    " 'git remote prune %s' to remove any old, conflicting "
 +                    "branches", remote_name);
 +      return rc;
 +}
 +
 +/*
 + * We would want to bypass the object transfer altogether if
 + * everything we are going to fetch already exists and is connected
 + * locally.
 + *
 + * The refs we are going to fetch are in ref_map.  If running
 + *
 + *  $ git rev-list --objects --stdin --not --all
 + *
 + * (feeding all the refs in ref_map on its standard input)
 + * does not error out, that means everything reachable from the
 + * refs we are going to fetch exists and is connected to some of
 + * our existing refs.
 + */
 +static int quickfetch(struct ref *ref_map)
 +{
 +      struct child_process revlist;
 +      struct ref *ref;
 +      int err;
 +      const char *argv[] = {"rev-list",
 +              "--quiet", "--objects", "--stdin", "--not", "--all", NULL};
 +
 +      /*
 +       * If we are deepening a shallow clone we already have these
 +       * objects reachable.  Running rev-list here will return with
 +       * a good (0) exit status and we'll bypass the fetch that we
 +       * really need to perform.  Claiming failure now will ensure
 +       * we perform the network exchange to deepen our history.
 +       */
 +      if (depth)
 +              return -1;
 +
 +      if (!ref_map)
 +              return 0;
 +
 +      memset(&revlist, 0, sizeof(revlist));
 +      revlist.argv = argv;
 +      revlist.git_cmd = 1;
 +      revlist.no_stdout = 1;
 +      revlist.no_stderr = 1;
 +      revlist.in = -1;
 +
 +      err = start_command(&revlist);
 +      if (err) {
 +              error("could not run rev-list");
 +              return err;
 +      }
 +
 +      /*
 +       * If rev-list --stdin encounters an unknown commit, it terminates,
 +       * which will cause SIGPIPE in the write loop below.
 +       */
 +      sigchain_push(SIGPIPE, SIG_IGN);
 +
 +      for (ref = ref_map; ref; ref = ref->next) {
 +              if (write_in_full(revlist.in, sha1_to_hex(ref->old_sha1), 40) < 0 ||
 +                  write_str_in_full(revlist.in, "\n") < 0) {
 +                      if (errno != EPIPE && errno != EINVAL)
 +                              error("failed write to rev-list: %s", strerror(errno));
 +                      err = -1;
 +                      break;
 +              }
 +      }
 +
 +      if (close(revlist.in)) {
 +              error("failed to close rev-list's stdin: %s", strerror(errno));
 +              err = -1;
 +      }
 +
 +      sigchain_pop(SIGPIPE);
 +
 +      return finish_command(&revlist) || err;
 +}
 +
 +static int fetch_refs(struct transport *transport, struct ref *ref_map)
 +{
 +      int ret = quickfetch(ref_map);
 +      if (ret)
 +              ret = transport_fetch_refs(transport, ref_map);
 +      if (!ret)
 +              ret |= store_updated_refs(transport->url,
 +                              transport->remote->name,
 +                              ref_map);
 +      transport_unlock_pack(transport);
 +      return ret;
 +}
 +
 +static int prune_refs(struct transport *transport, struct ref *ref_map)
 +{
 +      int result = 0;
 +      struct ref *ref, *stale_refs = get_stale_heads(transport->remote, ref_map);
 +      const char *dangling_msg = dry_run
 +              ? "   (%s will become dangling)\n"
 +              : "   (%s has become dangling)\n";
 +
 +      for (ref = stale_refs; ref; ref = ref->next) {
 +              if (!dry_run)
 +                      result |= delete_ref(ref->name, NULL, 0);
 +              if (verbosity >= 0) {
 +                      fprintf(stderr, " x %-*s %-*s -> %s\n",
 +                              TRANSPORT_SUMMARY_WIDTH, "[deleted]",
 +                              REFCOL_WIDTH, "(none)", prettify_refname(ref->name));
 +                      warn_dangling_symref(stderr, dangling_msg, ref->name);
 +              }
 +      }
 +      free_refs(stale_refs);
 +      return result;
 +}
 +
 +static int add_existing(const char *refname, const unsigned char *sha1,
 +                      int flag, void *cbdata)
 +{
 +      struct string_list *list = (struct string_list *)cbdata;
 +      struct string_list_item *item = string_list_insert(refname, list);
 +      item->util = (void *)sha1;
 +      return 0;
 +}
 +
 +static int will_fetch(struct ref **head, const unsigned char *sha1)
 +{
 +      struct ref *rm = *head;
 +      while (rm) {
 +              if (!hashcmp(rm->old_sha1, sha1))
 +                      return 1;
 +              rm = rm->next;
 +      }
 +      return 0;
 +}
 +
 +struct tag_data {
 +      struct ref **head;
 +      struct ref ***tail;
 +};
 +
 +static int add_to_tail(struct string_list_item *item, void *cb_data)
 +{
 +      struct tag_data *data = (struct tag_data *)cb_data;
 +      struct ref *rm = NULL;
 +
 +      /* We have already decided to ignore this item */
 +      if (!item->util)
 +              return 0;
 +
 +      rm = alloc_ref(item->string);
 +      rm->peer_ref = alloc_ref(item->string);
 +      hashcpy(rm->old_sha1, item->util);
 +
 +      **data->tail = rm;
 +      *data->tail = &rm->next;
 +
 +      return 0;
 +}
 +
 +static void find_non_local_tags(struct transport *transport,
 +                      struct ref **head,
 +                      struct ref ***tail)
 +{
 +      struct string_list existing_refs = { NULL, 0, 0, 0 };
 +      struct string_list remote_refs = { NULL, 0, 0, 0 };
 +      struct tag_data data = {head, tail};
 +      const struct ref *ref;
 +      struct string_list_item *item = NULL;
 +
 +      for_each_ref(add_existing, &existing_refs);
 +      for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
 +              if (prefixcmp(ref->name, "refs/tags"))
 +                      continue;
 +
 +              /*
 +               * The peeled ref always follows the matching base
 +               * ref, so if we see a peeled ref that we don't want
 +               * to fetch then we can mark the ref entry in the list
 +               * as one to ignore by setting util to NULL.
 +               */
++              if (!suffixcmp(ref->name, "^{}")) {
 +                      if (item && !has_sha1_file(ref->old_sha1) &&
 +                          !will_fetch(head, ref->old_sha1) &&
 +                          !has_sha1_file(item->util) &&
 +                          !will_fetch(head, item->util))
 +                              item->util = NULL;
 +                      item = NULL;
 +                      continue;
 +              }
 +
 +              /*
 +               * If item is non-NULL here, then we previously saw a
 +               * ref not followed by a peeled reference, so we need
 +               * to check if it is a lightweight tag that we want to
 +               * fetch.
 +               */
 +              if (item && !has_sha1_file(item->util) &&
 +                  !will_fetch(head, item->util))
 +                      item->util = NULL;
 +
 +              item = NULL;
 +
 +              /* skip duplicates and refs that we already have */
 +              if (string_list_has_string(&remote_refs, ref->name) ||
 +                  string_list_has_string(&existing_refs, ref->name))
 +                      continue;
 +
 +              item = string_list_insert(ref->name, &remote_refs);
 +              item->util = (void *)ref->old_sha1;
 +      }
 +      string_list_clear(&existing_refs, 0);
 +
 +      /*
 +       * We may have a final lightweight tag that needs to be
 +       * checked to see if it needs fetching.
 +       */
 +      if (item && !has_sha1_file(item->util) &&
 +          !will_fetch(head, item->util))
 +              item->util = NULL;
 +
 +      /*
 +       * For all the tags in the remote_refs string list, call
 +       * add_to_tail to add them to the list of refs to be fetched
 +       */
 +      for_each_string_list(add_to_tail, &remote_refs, &data);
 +
 +      string_list_clear(&remote_refs, 0);
 +}
 +
 +static void check_not_current_branch(struct ref *ref_map)
 +{
 +      struct branch *current_branch = branch_get(NULL);
 +
 +      if (is_bare_repository() || !current_branch)
 +              return;
 +
 +      for (; ref_map; ref_map = ref_map->next)
 +              if (ref_map->peer_ref && !strcmp(current_branch->refname,
 +                                      ref_map->peer_ref->name))
 +                      die("Refusing to fetch into current branch %s "
 +                          "of non-bare repository", current_branch->refname);
 +}
 +
 +static int truncate_fetch_head(void)
 +{
 +      char *filename = git_path("FETCH_HEAD");
 +      FILE *fp = fopen(filename, "w");
 +
 +      if (!fp)
 +              return error("cannot open %s: %s\n", filename, strerror(errno));
 +      fclose(fp);
 +      return 0;
 +}
 +
 +static int do_fetch(struct transport *transport,
 +                  struct refspec *refs, int ref_count)
 +{
 +      struct string_list existing_refs = { NULL, 0, 0, 0 };
 +      struct string_list_item *peer_item = NULL;
 +      struct ref *ref_map;
 +      struct ref *rm;
 +      int autotags = (transport->remote->fetch_tags == 1);
 +
 +      for_each_ref(add_existing, &existing_refs);
 +
 +      if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
 +              tags = TAGS_SET;
 +      if (transport->remote->fetch_tags == -1)
 +              tags = TAGS_UNSET;
 +
 +      if (!transport->get_refs_list || !transport->fetch)
 +              die("Don't know how to fetch from %s", transport->url);
 +
 +      /* if not appending, truncate FETCH_HEAD */
 +      if (!append && !dry_run) {
 +              int errcode = truncate_fetch_head();
 +              if (errcode)
 +                      return errcode;
 +      }
 +
 +      ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
 +      if (!update_head_ok)
 +              check_not_current_branch(ref_map);
 +
 +      for (rm = ref_map; rm; rm = rm->next) {
 +              if (rm->peer_ref) {
 +                      peer_item = string_list_lookup(rm->peer_ref->name,
 +                                                     &existing_refs);
 +                      if (peer_item)
 +                              hashcpy(rm->peer_ref->old_sha1,
 +                                      peer_item->util);
 +              }
 +      }
 +
 +      if (tags == TAGS_DEFAULT && autotags)
 +              transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
 +      if (fetch_refs(transport, ref_map)) {
 +              free_refs(ref_map);
 +              return 1;
 +      }
 +      if (prune)
 +              prune_refs(transport, ref_map);
 +      free_refs(ref_map);
 +
 +      /* if neither --no-tags nor --tags was specified, do automated tag
 +       * following ... */
 +      if (tags == TAGS_DEFAULT && autotags) {
 +              struct ref **tail = &ref_map;
 +              ref_map = NULL;
 +              find_non_local_tags(transport, &ref_map, &tail);
 +              if (ref_map) {
 +                      transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
 +                      transport_set_option(transport, TRANS_OPT_DEPTH, "0");
 +                      fetch_refs(transport, ref_map);
 +              }
 +              free_refs(ref_map);
 +      }
 +
 +      return 0;
 +}
 +
 +static void set_option(const char *name, const char *value)
 +{
 +      int r = transport_set_option(transport, name, value);
 +      if (r < 0)
 +              die("Option \"%s\" value \"%s\" is not valid for %s",
 +                      name, value, transport->url);
 +      if (r > 0)
 +              warning("Option \"%s\" is ignored for %s\n",
 +                      name, transport->url);
 +}
 +
 +static int get_one_remote_for_fetch(struct remote *remote, void *priv)
 +{
 +      struct string_list *list = priv;
 +      if (!remote->skip_default_update)
 +              string_list_append(remote->name, list);
 +      return 0;
 +}
 +
 +struct remote_group_data {
 +      const char *name;
 +      struct string_list *list;
 +};
 +
 +static int get_remote_group(const char *key, const char *value, void *priv)
 +{
 +      struct remote_group_data *g = priv;
 +
 +      if (!prefixcmp(key, "remotes.") &&
 +                      !strcmp(key + 8, g->name)) {
 +              /* split list by white space */
 +              int space = strcspn(value, " \t\n");
 +              while (*value) {
 +                      if (space > 1) {
 +                              string_list_append(xstrndup(value, space),
 +                                                 g->list);
 +                      }
 +                      value += space + (value[space] != '\0');
 +                      space = strcspn(value, " \t\n");
 +              }
 +      }
 +
 +      return 0;
 +}
 +
 +static int add_remote_or_group(const char *name, struct string_list *list)
 +{
 +      int prev_nr = list->nr;
 +      struct remote_group_data g = { name, list };
 +
 +      git_config(get_remote_group, &g);
 +      if (list->nr == prev_nr) {
 +              struct remote *remote;
 +              if (!remote_is_configured(name))
 +                      return 0;
 +              remote = remote_get(name);
 +              string_list_append(remote->name, list);
 +      }
 +      return 1;
 +}
 +
 +static int fetch_multiple(struct string_list *list)
 +{
 +      int i, result = 0;
 +      const char *argv[11] = { "fetch", "--append" };
 +      int argc = 2;
 +
 +      if (dry_run)
 +              argv[argc++] = "--dry-run";
 +      if (prune)
 +              argv[argc++] = "--prune";
 +      if (update_head_ok)
 +              argv[argc++] = "--update-head-ok";
 +      if (force)
 +              argv[argc++] = "--force";
 +      if (keep)
 +              argv[argc++] = "--keep";
 +      if (verbosity >= 2)
 +              argv[argc++] = "-v";
 +      if (verbosity >= 1)
 +              argv[argc++] = "-v";
 +      else if (verbosity < 0)
 +              argv[argc++] = "-q";
 +
 +      if (!append && !dry_run) {
 +              int errcode = truncate_fetch_head();
 +              if (errcode)
 +                      return errcode;
 +      }
 +
 +      for (i = 0; i < list->nr; i++) {
 +              const char *name = list->items[i].string;
 +              argv[argc] = name;
 +              argv[argc + 1] = NULL;
 +              if (verbosity >= 0)
 +                      printf("Fetching %s\n", name);
 +              if (run_command_v_opt(argv, RUN_GIT_CMD)) {
 +                      error("Could not fetch %s", name);
 +                      result = 1;
 +              }
 +      }
 +
 +      return result;
 +}
 +
 +static int fetch_one(struct remote *remote, int argc, const char **argv)
 +{
 +      int i;
 +      static const char **refs = NULL;
 +      int ref_nr = 0;
 +      int exit_code;
 +
 +      if (!remote)
 +              die("Where do you want to fetch from today?");
 +
 +      transport = transport_get(remote, NULL);
 +      transport_set_verbosity(transport, verbosity, progress);
 +      if (upload_pack)
 +              set_option(TRANS_OPT_UPLOADPACK, upload_pack);
 +      if (keep)
 +              set_option(TRANS_OPT_KEEP, "yes");
 +      if (depth)
 +              set_option(TRANS_OPT_DEPTH, depth);
 +
 +      if (argc > 0) {
 +              int j = 0;
 +              refs = xcalloc(argc + 1, sizeof(const char *));
 +              for (i = 0; i < argc; i++) {
 +                      if (!strcmp(argv[i], "tag")) {
 +                              char *ref;
 +                              i++;
 +                              if (i >= argc)
 +                                      die("You need to specify a tag name.");
 +                              ref = xmalloc(strlen(argv[i]) * 2 + 22);
 +                              strcpy(ref, "refs/tags/");
 +                              strcat(ref, argv[i]);
 +                              strcat(ref, ":refs/tags/");
 +                              strcat(ref, argv[i]);
 +                              refs[j++] = ref;
 +                      } else
 +                              refs[j++] = argv[i];
 +              }
 +              refs[j] = NULL;
 +              ref_nr = j;
 +      }
 +
 +      sigchain_push_common(unlock_pack_on_signal);
 +      atexit(unlock_pack);
 +      exit_code = do_fetch(transport,
 +                      parse_fetch_refspec(ref_nr, refs), ref_nr);
 +      transport_disconnect(transport);
 +      transport = NULL;
 +      return exit_code;
 +}
 +
 +int cmd_fetch(int argc, const char **argv, const char *prefix)
 +{
 +      int i;
 +      struct string_list list = { NULL, 0, 0, 0 };
 +      struct remote *remote;
 +      int result = 0;
 +
 +      /* Record the command line for the reflog */
 +      strbuf_addstr(&default_rla, "fetch");
 +      for (i = 1; i < argc; i++)
 +              strbuf_addf(&default_rla, " %s", argv[i]);
 +
 +      argc = parse_options(argc, argv, prefix,
 +                           builtin_fetch_options, builtin_fetch_usage, 0);
 +
 +      if (all) {
 +              if (argc == 1)
 +                      die("fetch --all does not take a repository argument");
 +              else if (argc > 1)
 +                      die("fetch --all does not make sense with refspecs");
 +              (void) for_each_remote(get_one_remote_for_fetch, &list);
 +              result = fetch_multiple(&list);
 +      } else if (argc == 0) {
 +              /* No arguments -- use default remote */
 +              remote = remote_get(NULL);
 +              result = fetch_one(remote, argc, argv);
 +      } else if (multiple) {
 +              /* All arguments are assumed to be remotes or groups */
 +              for (i = 0; i < argc; i++)
 +                      if (!add_remote_or_group(argv[i], &list))
 +                              die("No such remote or remote group: %s", argv[i]);
 +              result = fetch_multiple(&list);
 +      } else {
 +              /* Single remote or group */
 +              (void) add_remote_or_group(argv[0], &list);
 +              if (list.nr > 1) {
 +                      /* More than one remote */
 +                      if (argc > 1)
 +                              die("Fetching a group and specifying refspecs does not make sense");
 +                      result = fetch_multiple(&list);
 +              } else {
 +                      /* Zero or one remotes */
 +                      remote = remote_get(argv[0]);
 +                      result = fetch_one(remote, argc-1, argv+1);
 +              }
 +      }
 +
 +      /* All names were strdup()ed or strndup()ed */
 +      list.strdup_strings = 1;
 +      string_list_clear(&list, 0);
 +
 +      return result;
 +}
diff --combined git-pull.sh
index d45b50cf4783912cedc4b7764a609ea9b4176969,246a3a4b373dba87877204c90c9f808dfa93c45c..1a4729f7bb29205fb7bc251887dcd4f5237f1659
@@@ -38,10 -38,10 +38,10 @@@ test -z "$(git ls-files -u)" || die_con
  test -f "$GIT_DIR/MERGE_HEAD" && die_merge
  
  strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
 -log_arg= verbosity=
 +log_arg= verbosity= progress=
  merge_args=
  curr_branch=$(git symbolic-ref -q HEAD)
- curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||")
+ curr_branch_short="${curr_branch#refs/heads/}"
  rebase=$(git config --bool branch.$curr_branch_short.rebase)
  while :
  do
@@@ -50,8 -50,6 +50,8 @@@
                verbosity="$verbosity -q" ;;
        -v|--verbose)
                verbosity="$verbosity -v" ;;
 +      --progress)
 +              progress=--progress ;;
        -n|--no-stat|--no-summary)
                diffstat=--no-stat ;;
        --stat|--summary)
@@@ -216,7 -214,7 +216,7 @@@ test true = "$rebase" && 
        done
  }
  orig_head=$(git rev-parse -q --verify HEAD)
 -git fetch $verbosity --update-head-ok "$@" || exit 1
 +git fetch $verbosity $progress --update-head-ok "$@" || exit 1
  
  curr_head=$(git rev-parse -q --verify HEAD)
  if test -n "$orig_head" && test "$curr_head" != "$orig_head"