Merge branch 'il/vcs-helper'
authorJunio C Hamano <gitster@pobox.com>
Wed, 13 Jan 2010 20:30:39 +0000 (12:30 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Jan 2010 20:30:39 +0000 (12:30 -0800)
* il/vcs-helper:
Reset possible helper before reusing remote structure
Remove special casing of http, https and ftp
Support remote archive from all smart transports
Support remote helpers implementing smart transports
Support taking over transports
Refactor git transport options parsing
Pass unknown protocols to external protocol handlers
Support mandatory capabilities
Add remote helper debug mode

Conflicts:
Documentation/git-remote-helpers.txt
transport-helper.c

1  2 
.gitignore
Makefile
builtin-archive.c
diff --combined .gitignore
index 0746a4d2090c5387d7dbe6e9e40b529064e18a8d,aa7a8ac193c7a0a981a85261ab18b78d8b997a81..83cf1b7532f6cf35c1fefdedb7372062a10b468f
@@@ -2,7 -2,6 +2,7 @@@
  /GIT-CFLAGS
  /GIT-GUI-VARS
  /GIT-VERSION-FILE
 +/bin-wrappers/
  /git
  /git-add
  /git-add--interactive
  /git-relink
  /git-remote
  /git-remote-curl
+ /git-remote-http
+ /git-remote-https
+ /git-remote-ftp
+ /git-remote-ftps
  /git-repack
  /git-replace
  /git-repo-config
  /test-delta
  /test-dump-cache-tree
  /test-genrandom
 +/test-index-version
  /test-match-trees
  /test-parse-options
  /test-path-utils
diff --combined Makefile
index 412dda83ac6a9cf76682153b5d66c274e2a362fd,87fc7ff4769e6fd41e4918eb0561122c89d307a8..57045dee8903be3bada4ed756cf0aa8052a2e83e
+++ b/Makefile
@@@ -424,6 -424,16 +424,16 @@@ BUILT_INS += git-stage$
  BUILT_INS += git-status$X
  BUILT_INS += git-whatchanged$X
  
+ ifdef NO_CURL
+ REMOTE_CURL_PRIMARY =
+ REMOTE_CURL_ALIASES =
+ REMOTE_CURL_NAMES =
+ else
+ 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)
+ endif
  # what 'all' will build and 'install' will install in gitexecdir,
  # excluding programs for built-in commands
  ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
  # what 'all' will build but not install in gitexecdir
  OTHER_PROGRAMS = git$X
  
 +# what test wrappers are needed and 'install' will install, in bindir
 +BINDIR_PROGRAMS_NEED_X += git
 +BINDIR_PROGRAMS_NEED_X += git-upload-pack
 +BINDIR_PROGRAMS_NEED_X += git-receive-pack
 +BINDIR_PROGRAMS_NEED_X += git-upload-archive
 +BINDIR_PROGRAMS_NEED_X += git-shell
 +
 +BINDIR_PROGRAMS_NO_X += git-cvsserver
 +
  # Set paths to tools early so that they can be used for version tests.
  ifndef SHELL_PATH
        SHELL_PATH = /bin/sh
@@@ -845,7 -846,6 +855,7 @@@ ifeq ($(uname_O),Cygwin
  endif
  ifeq ($(uname_S),FreeBSD)
        NEEDS_LIBICONV = YesPlease
 +      OLD_ICONV = YesPlease
        NO_MEMMEM = YesPlease
        BASIC_CFLAGS += -I/usr/local/include
        BASIC_LDFLAGS += -L/usr/local/lib
@@@ -1107,7 -1107,7 +1117,7 @@@ els
        else
                CURL_LIBCURL = -lcurl
        endif
-       PROGRAMS += git-remote-curl$X git-http-fetch$X
+       PROGRAMS += $(REMOTE_CURL_NAMES) git-http-fetch$X
        curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
        ifeq "$(curl_check)" "070908"
                ifndef NO_EXPAT
@@@ -1644,7 -1644,7 +1654,7 @@@ git.o git.spec 
        $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
  %.s: %.c GIT-CFLAGS
        $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
 -%.o: %.S
 +%.o: %.S GIT-CFLAGS
        $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
  
  exec_cmd.o: exec_cmd.c GIT-CFLAGS
@@@ -1686,7 -1686,13 +1696,13 @@@ git-http-push$X: revision.o http.o http
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
  
- git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS)
+ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
+       $(QUIET_LNCP)$(RM) $@ && \
+       ln $< $@ 2>/dev/null || \
+       ln -s $< $@ 2>/dev/null || \
+       cp $< $@
+ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
  
@@@ -1753,7 -1759,6 +1769,7 @@@ GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPT
        @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
        @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
 +      @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
  
  ### Detect Tck/Tk interpreter path changes
  ifndef NO_TCLTK
@@@ -1771,31 -1776,19 +1787,31 @@@ endi
  
  ### Testing rules
  
 -TEST_PROGRAMS += test-chmtime$X
 -TEST_PROGRAMS += test-ctype$X
 -TEST_PROGRAMS += test-date$X
 -TEST_PROGRAMS += test-delta$X
 -TEST_PROGRAMS += test-dump-cache-tree$X
 -TEST_PROGRAMS += test-genrandom$X
 -TEST_PROGRAMS += test-match-trees$X
 -TEST_PROGRAMS += test-parse-options$X
 -TEST_PROGRAMS += test-path-utils$X
 -TEST_PROGRAMS += test-sha1$X
 -TEST_PROGRAMS += test-sigchain$X
 +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-sha1
 +TEST_PROGRAMS_NEED_X += test-sigchain
 +TEST_PROGRAMS_NEED_X += test-index-version
 +
 +TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
  
 -all:: $(TEST_PROGRAMS)
 +test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
 +
 +all:: $(TEST_PROGRAMS) $(test_bindir_programs)
 +
 +bin-wrappers/%: wrap-for-bin.sh
 +      @mkdir -p bin-wrappers
 +      $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 +           -e 's|@@BUILD_DIR@@|$(shell pwd)|' \
 +           -e 's|@@PROG@@|$(@F)|' < $< > $@ && \
 +      chmod +x $@
  
  # GNU make supports exporting all variables by "export" without parameters.
  # However, the environment gets quite big, and some programs have problems
@@@ -1856,13 -1849,11 +1872,13 @@@ endi
  gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
  export gitexec_instdir
  
 +install_bindir_programs := $(patsubst %,%$X,$(BINDIR_PROGRAMS_NEED_X)) $(BINDIR_PROGRAMS_NO_X)
 +
  install: all
        $(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) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X git-shell$X git-cvsserver '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
  ifndef NO_PERL
        $(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@@ -1877,6 -1868,7 +1893,7 @@@ endi
  ifneq (,$X)
        $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
  endif
        bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
        execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
        { test "$$bindir/" = "$$execdir/" || \
                ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
                cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
          done; } && \
+       { for p in $(REMOTE_CURL_ALIASES); do \
+               $(RM) "$$execdir/$$p" && \
+               ln "$$execdir/git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
+               ln -s "git-remote-http$X" "$$execdir/$$p" 2>/dev/null || \
+               cp "$$execdir/git-remote-http$X" "$$execdir/$$p" || exit; \
+         done; } && \
        ./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X"
  
  install-doc:
@@@ -1976,7 -1974,6 +1999,7 @@@ clean
                $(LIB_FILE) $(XDIFF_LIB)
        $(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
 +      $(RM) -r bin-wrappers
        $(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
diff --combined builtin-archive.c
index 446d6bff30ed47a5cf308310e3f28c5b30648a2c,d34b3fd028262fdd4215380b206abbf58bea07a4..3fb41364a512db28c92d79a21c60b238141c7970
@@@ -5,6 -5,7 +5,7 @@@
  #include "cache.h"
  #include "builtin.h"
  #include "archive.h"
+ #include "transport.h"
  #include "parse-options.h"
  #include "pkt-line.h"
  #include "sideband.h"
@@@ -25,12 -26,16 +26,16 @@@ static void create_output_file(const ch
  static int run_remote_archiver(int argc, const char **argv,
                               const char *remote, const char *exec)
  {
-       char *url, buf[LARGE_PACKET_MAX];
+       char buf[LARGE_PACKET_MAX];
        int fd[2], i, len, rv;
-       struct child_process *conn;
+       struct transport *transport;
+       struct remote *_remote;
  
-       url = xstrdup(remote);
-       conn = git_connect(fd, url, exec, 0);
+       _remote = remote_get(remote);
+       if (!_remote->url[0])
+               die("git archive: Remote with no URL");
+       transport = transport_get(_remote, _remote->url[0]);
+       transport_connect(transport, "git-upload-archive", exec, fd);
  
        for (i = 1; i < argc; i++)
                packet_write(fd[1], "argument %s\n", argv[i]);
@@@ -53,9 -58,7 +58,7 @@@
  
        /* Now, start reading from fd[0] and spit it out to stdout */
        rv = recv_sideband("archive", fd[0], 1);
-       close(fd[0]);
-       close(fd[1]);
-       rv |= finish_connect(conn);
+       rv |= transport_disconnect(transport);
  
        return !!rv;
  }
@@@ -106,17 -109,13 +109,17 @@@ int cmd_archive(int argc, const char **
        if (format) {
                sprintf(fmt_opt, "--format=%s", format);
                /*
 -               * This is safe because either --format and/or --output must
 -               * have been given on the original command line if we get to
 -               * this point, and parse_options() must have eaten at least
 -               * one argument, i.e. we have enough room to append to argv[].
 +               * We have enough room in argv[] to muck it in place,
 +               * because either --format and/or --output must have
 +               * been given on the original command line if we get
 +               * to this point, and parse_options() must have eaten
 +               * it, i.e. we can add back one element to the array.
 +               * But argv[] may contain "--"; we should make it the
 +               * first option.
                 */
 -              argv[argc++] = fmt_opt;
 -              argv[argc] = NULL;
 +              memmove(argv + 2, argv + 1, sizeof(*argv) * argc);
 +              argv[1] = fmt_opt;
 +              argv[++argc] = NULL;
        }
  
        if (remote)