Merge branch 'tc/http-urls-ends-with-slash'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2010 05:49:52 +0000 (21:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2010 05:49:52 +0000 (21:49 -0800)
* tc/http-urls-ends-with-slash:
http-fetch: rework url handling
http-push: add trailing slash at arg-parse time, instead of later on
http-push: check path length before using it
http-push: Normalise directory names when pushing to some WebDAV servers
http-backend: use end_url_with_slash()
url: add str wrapper for end_url_with_slash()
shift end_url_with_slash() from http.[ch] to url.[ch]
t5550-http-fetch: add test for http-fetch
t5550-http-fetch: add missing '&&'

1  2 
Makefile
http.c
t/t5550-http-fetch.sh
diff --combined Makefile
index 6439c7bd390777afbf5f89d5ba59be0e13d3839d,90aaa30e7f4cc5c614c4d7d14dbd437412af5a2d..49c41f1757c0a18de292c305a0518f572f6f3cc8
+++ b/Makefile
@@@ -70,11 -70,6 +70,11 @@@ all:
  #
  # Define NO_STRTOK_R if you don't have strtok_r in the C library.
  #
 +# Define NO_FNMATCH if you don't have fnmatch in the C library.
 +#
 +# Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the
 +# FNM_CASEFOLD GNU extension.
 +#
  # Define NO_LIBGEN_H if you don't have libgen.h.
  #
  # Define NEEDS_LIBGEN if your libgen needs -lgen when linking
  # Define NO_ST_BLOCKS_IN_STRUCT_STAT if your platform does not have st_blocks
  # field that counts the on-disk footprint in 512-byte blocks.
  #
 -# Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8
 +# Define ASCIIDOC7 if you want to format documentation with AsciiDoc 7
  #
  # Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72
  # (not v1.73 or v1.71).
  #
 -# Define ASCIIDOC_NO_ROFF if your DocBook XSL escapes raw roff directives
 -# (versions 1.72 and later and 1.68.1 and earlier).
 +# Define ASCIIDOC_ROFF if your DocBook XSL does not escape raw roff directives
 +# (versions 1.68.1 through v1.72).
  #
  # Define GNU_ROFF if your target system uses GNU groff.  This forces
  # apostrophes to be ASCII so that cut&pasting examples to the shell
@@@ -275,7 -270,6 +275,7 @@@ STRIP ?= stri
  #   infodir
  #   htmldir
  #   ETC_GITCONFIG (but not sysconfdir)
 +#   ETC_GITATTRIBUTES
  # can be specified as a relative path some/where/else;
  # this is interpreted as relative to $(prefix) and "git" at
  # runtime figures out where they are based on the path to the executable.
@@@ -294,11 -288,9 +294,11 @@@ htmldir = share/doc/git-do
  ifeq ($(prefix),/usr)
  sysconfdir = /etc
  ETC_GITCONFIG = $(sysconfdir)/gitconfig
 +ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
  else
  sysconfdir = $(prefix)/etc
  ETC_GITCONFIG = etc/gitconfig
 +ETC_GITATTRIBUTES = etc/gitattributes
  endif
  lib = lib
  # DESTDIR=
@@@ -406,7 -398,6 +406,7 @@@ EXTRA_PROGRAMS 
  # ... and all the rest that could be moved out of bindir to gitexecdir
  PROGRAMS += $(EXTRA_PROGRAMS)
  
 +PROGRAM_OBJS += daemon.o
  PROGRAM_OBJS += fast-import.o
  PROGRAM_OBJS += imap-send.o
  PROGRAM_OBJS += shell.o
@@@ -502,9 -493,6 +502,9 @@@ LIB_H += compat/bswap.
  LIB_H += compat/cygwin.h
  LIB_H += compat/mingw.h
  LIB_H += compat/win32/pthread.h
 +LIB_H += compat/win32/syslog.h
 +LIB_H += compat/win32/sys/poll.h
 +LIB_H += compat/win32/dirent.h
  LIB_H += csum-file.h
  LIB_H += decorate.h
  LIB_H += delta.h
@@@ -526,7 -514,6 +526,7 @@@ LIB_H += mailmap.
  LIB_H += merge-recursive.h
  LIB_H += notes.h
  LIB_H += notes-cache.h
 +LIB_H += notes-merge.h
  LIB_H += object.h
  LIB_H += pack.h
  LIB_H += pack-refs.h
@@@ -617,7 -604,6 +617,7 @@@ LIB_OBJS += merge-recursive.
  LIB_OBJS += name-hash.o
  LIB_OBJS += notes.o
  LIB_OBJS += notes-cache.o
 +LIB_OBJS += notes-merge.o
  LIB_OBJS += object.o
  LIB_OBJS += pack-check.o
  LIB_OBJS += pack-refs.o
@@@ -673,7 -659,6 +673,7 @@@ LIB_OBJS += write_or_die.
  LIB_OBJS += ws.o
  LIB_OBJS += wt-status.o
  LIB_OBJS += xdiff-interface.o
 +LIB_OBJS += zlib.o
  
  BUILTIN_OBJS += builtin/add.o
  BUILTIN_OBJS += builtin/annotate.o
@@@ -740,8 -725,6 +740,8 @@@ BUILTIN_OBJS += builtin/read-tree.
  BUILTIN_OBJS += builtin/receive-pack.o
  BUILTIN_OBJS += builtin/reflog.o
  BUILTIN_OBJS += builtin/remote.o
 +BUILTIN_OBJS += builtin/remote-ext.o
 +BUILTIN_OBJS += builtin/remote-fd.o
  BUILTIN_OBJS += builtin/replace.o
  BUILTIN_OBJS += builtin/rerere.o
  BUILTIN_OBJS += builtin/reset.o
@@@ -860,7 -843,6 +860,7 @@@ ifeq ($(uname_S),SunOS
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        NO_REGEX = YesPlease
 +      NO_FNMATCH_CASEFOLD = YesPlease
        ifeq ($(uname_R),5.6)
                SOCKLEN_T = int
                NO_HSTRERROR = YesPlease
@@@ -1067,7 -1049,6 +1067,7 @@@ ifeq ($(uname_S),Windows
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
        NO_STRTOK_R = YesPlease
 +      NO_FNMATCH = YesPlease
        NO_MEMMEM = YesPlease
        # NEEDS_LIBICONV = YesPlease
        NO_ICONV = YesPlease
        NO_SVN_TESTS = YesPlease
        NO_PERL_MAKEMAKER = YesPlease
        RUNTIME_PREFIX = YesPlease
 -      NO_POSIX_ONLY_PROGRAMS = YesPlease
        NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
        NO_NSEC = YesPlease
        USE_WIN32_MMAP = YesPlease
        NO_CURL = YesPlease
        NO_PYTHON = YesPlease
        BLK_SHA1 = YesPlease
 +      NO_POSIX_GOODIES = UnfortunatelyYes
        NATIVE_CRLF = YesPlease
  
        CC = compat/vcbuild/scripts/clink.pl
        AR = compat/vcbuild/scripts/lib.pl
        CFLAGS =
        BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
 -      COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o compat/win32/pthread.o
 -      COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
 +      COMPAT_OBJS = compat/msvc.o compat/winansi.o \
 +              compat/win32/pthread.o compat/win32/syslog.o \
 +              compat/win32/sys/poll.o compat/win32/dirent.o
 +      COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
        BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
        EXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib
        PTHREAD_LIBS =
  endif
        X = .exe
  endif
 +ifeq ($(uname_S),Interix)
 +      NO_SYS_POLL_H = YesPlease
 +      NO_INTTYPES_H = YesPlease
 +      NO_INITGROUPS = YesPlease
 +      NO_IPV6 = YesPlease
 +      NO_MEMMEM = YesPlease
 +      NO_MKDTEMP = YesPlease
 +      NO_STRTOUMAX = YesPlease
 +      NO_NSEC = YesPlease
 +      NO_MKSTEMPS = YesPlease
 +      ifeq ($(uname_R),3.5)
 +              NO_INET_NTOP = YesPlease
 +              NO_INET_PTON = YesPlease
 +      endif
 +      ifeq ($(uname_R),5.2)
 +              NO_INET_NTOP = YesPlease
 +              NO_INET_PTON = YesPlease
 +      endif
 +endif
  ifneq (,$(findstring MINGW,$(uname_S)))
        pathsep = ;
        NO_PREAD = YesPlease
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
        NO_STRTOK_R = YesPlease
 +      NO_FNMATCH = YesPlease
        NO_MEMMEM = YesPlease
        NEEDS_LIBICONV = YesPlease
        OLD_ICONV = YesPlease
        NO_SVN_TESTS = YesPlease
        NO_PERL_MAKEMAKER = YesPlease
        RUNTIME_PREFIX = YesPlease
 -      NO_POSIX_ONLY_PROGRAMS = YesPlease
        NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
        NO_NSEC = YesPlease
        USE_WIN32_MMAP = YesPlease
        NO_PYTHON = YesPlease
        BLK_SHA1 = YesPlease
        ETAGS_TARGET = ETAGS
 -      COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
 +      NO_INET_PTON = YesPlease
 +      NO_INET_NTOP = YesPlease
 +      NO_POSIX_GOODIES = UnfortunatelyYes
 +      COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/win32
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
 -      COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
 -              compat/win32/pthread.o
 +      COMPAT_OBJS += compat/mingw.o compat/winansi.o \
 +              compat/win32/pthread.o compat/win32/syslog.o \
 +              compat/win32/sys/poll.o compat/win32/dirent.o
        EXTLIBS += -lws2_32
        PTHREAD_LIBS =
        X = .exe
@@@ -1287,6 -1243,9 +1287,6 @@@ ifdef ZLIB_PAT
  endif
  EXTLIBS += -lz
  
 -ifndef NO_POSIX_ONLY_PROGRAMS
 -      PROGRAM_OBJS += daemon.o
 -endif
  ifndef NO_OPENSSL
        OPENSSL_LIBSSL = -lssl
        ifdef OPENSSLDIR
@@@ -1380,17 -1339,6 +1380,17 @@@ ifdef NO_STRTOK_
        COMPAT_CFLAGS += -DNO_STRTOK_R
        COMPAT_OBJS += compat/strtok_r.o
  endif
 +ifdef NO_FNMATCH
 +      COMPAT_CFLAGS += -Icompat/fnmatch
 +      COMPAT_CFLAGS += -DNO_FNMATCH
 +      COMPAT_OBJS += compat/fnmatch/fnmatch.o
 +else
 +ifdef NO_FNMATCH_CASEFOLD
 +      COMPAT_CFLAGS += -Icompat/fnmatch
 +      COMPAT_CFLAGS += -DNO_FNMATCH_CASEFOLD
 +      COMPAT_OBJS += compat/fnmatch/fnmatch.o
 +endif
 +endif
  ifdef NO_SETENV
        COMPAT_CFLAGS += -DNO_SETENV
        COMPAT_OBJS += compat/setenv.o
@@@ -1409,15 -1357,6 +1409,15 @@@ endi
  ifdef NO_SYS_SELECT_H
        BASIC_CFLAGS += -DNO_SYS_SELECT_H
  endif
 +ifdef NO_SYS_POLL_H
 +      BASIC_CFLAGS += -DNO_SYS_POLL_H
 +endif
 +ifdef NO_INTTYPES_H
 +      BASIC_CFLAGS += -DNO_INTTYPES_H
 +endif
 +ifdef NO_INITGROUPS
 +      BASIC_CFLAGS += -DNO_INITGROUPS
 +endif
  ifdef NO_MMAP
        COMPAT_CFLAGS += -DNO_MMAP
        COMPAT_OBJS += compat/mmap.o
@@@ -1455,11 -1394,9 +1455,11 @@@ endi
  endif
  ifdef NO_INET_NTOP
        LIB_OBJS += compat/inet_ntop.o
 +      BASIC_CFLAGS += -DNO_INET_NTOP
  endif
  ifdef NO_INET_PTON
        LIB_OBJS += compat/inet_pton.o
 +      BASIC_CFLAGS += -DNO_INET_PTON
  endif
  
  ifdef NO_ICONV
@@@ -1474,10 -1411,6 +1474,10 @@@ ifdef NO_DEFLATE_BOUN
        BASIC_CFLAGS += -DNO_DEFLATE_BOUND
  endif
  
 +ifdef NO_POSIX_GOODIES
 +      BASIC_CFLAGS += -DNO_POSIX_GOODIES
 +endif
 +
  ifdef BLK_SHA1
        SHA1_HEADER = "block-sha1/sha1.h"
        LIB_OBJS += block-sha1/sha1.o
@@@ -1582,15 -1515,14 +1582,15 @@@ ifndef 
  endif
  endif
  
 -ifdef ASCIIDOC8
 -      export ASCIIDOC8
 +ifdef ASCIIDOC7
 +      export ASCIIDOC7
  endif
  
  # Shell quote (do not use $(call) to accommodate ancient setups);
  
  SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
  ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
 +ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
  
  DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  bindir_SQ = $(subst ','\'',$(bindir))
@@@ -1830,8 -1762,6 +1830,8 @@@ XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprep
        xdiff/xmerge.o xdiff/xpatience.o
  VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \
        vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o
 +VCSSVN_TEST_OBJS = test-obj-pool.o test-string-pool.o \
 +      test-line-buffer.o test-treap.o
  OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS)
  
  dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@@ -1940,26 -1870,25 +1940,26 @@@ builtin/branch.o builtin/checkout.o bui
  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/grep.o builtin/pack-objects.o transport-helper.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
  connect.o transport.o http-backend.o: url.h
  http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
- http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
+ http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.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
  
 -$(VCSSVN_OBJS): \
 +$(VCSSVN_OBJS) $(VCSSVN_TEST_OBJS): $(LIB_H) \
        vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h \
        vcs-svn/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \
        vcs-svn/svndump.h
 +
 +test-svn-fe.o: vcs-svn/svndump.h
  endif
  
  exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@@ -1972,8 -1901,6 +1972,8 @@@ builtin/init-db.s builtin/init-db.o: EX
  
  config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
  
 +attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
 +
  http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
  
  ifdef NO_EXPAT
@@@ -1994,7 -1921,7 +1994,7 @@@ git-%$X: %.o $(GITLIBS
  
  git-imap-send$X: imap-send.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 -              $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
 +              $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
  
  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,$^) \
@@@ -2050,7 -1977,7 +2050,7 @@@ cscope
        $(FIND) . -name '*.[hcS]' -print | xargs cscope -b
  
  ### Detect prefix changes
 -TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
 +TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):\
               $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
  
  GIT-CFLAGS: FORCE
diff --combined http.c
index f582b13b915e58a189086cdec2bab6dbb94eac6a,3b3da12e0fb732438fcb7438160e6001afc189fa..9e767723ed1045445e91e79489cb8ec8bb861965
--- 1/http.c
--- 2/http.c
+++ b/http.c
@@@ -280,11 -280,6 +280,11 @@@ static CURL *get_curl_handle(void
        }
  
        curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1);
 +#if LIBCURL_VERSION_NUM >= 0x071301
 +      curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
 +#elif LIBCURL_VERSION_NUM >= 0x071101
 +      curl_easy_setopt(result, CURLOPT_POST301, 1);
 +#endif
  
        if (getenv("GIT_CURL_VERBOSE"))
                curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
  
  static void http_auth_init(const char *url)
  {
 -      char *at, *colon, *cp, *slash;
 +      char *at, *colon, *cp, *slash, *decoded;
        int len;
  
        cp = strstr(url, "://");
                user_name = xmalloc(len + 1);
                memcpy(user_name, cp, len);
                user_name[len] = '\0';
 +              decoded = url_decode(user_name);
 +              free(user_name);
 +              user_name = decoded;
                user_pass = NULL;
        } else {
                len = colon - cp;
                user_name = xmalloc(len + 1);
                memcpy(user_name, cp, len);
                user_name[len] = '\0';
 +              decoded = url_decode(user_name);
 +              free(user_name);
 +              user_name = decoded;
                len = at - (colon + 1);
                user_pass = xmalloc(len + 1);
                memcpy(user_pass, colon + 1, len);
                user_pass[len] = '\0';
 +              decoded = url_decode(user_pass);
 +              free(user_pass);
 +              user_pass = decoded;
        }
  }
  
@@@ -743,13 -729,6 +743,6 @@@ static inline int hex(int v
                return 'A' + v - 10;
  }
  
- void end_url_with_slash(struct strbuf *buf, const char *url)
- {
-       strbuf_addstr(buf, url);
-       if (buf->len && buf->buf[buf->len - 1] != '/')
-               strbuf_addstr(buf, "/");
- }
  static char *quote_ref_url(const char *base, const char *ref)
  {
        struct strbuf buf = STRBUF_INIT;
diff --combined t/t5550-http-fetch.sh
index 8c2ac353b7736c4bce7ed71333284863d9c4e514,d3bf5cefb14d5228904b80b538e170aa294584a4..a1883ca6b649a236e5e08a5e4b76d1479353dcac
@@@ -30,25 -30,30 +30,37 @@@ test_expect_success 'create http-access
  '
  
  test_expect_success 'clone http repository' '
-       git clone $HTTPD_URL/dumb/repo.git clone &&
+       git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
+       cp -R clone-tmpl clone &&
        test_cmp file clone/file
  '
  
 +test_expect_success 'clone http repository with authentication' '
 +      mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
 +      cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
 +      git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
 +      test_cmp file clone-auth/file
 +'
 +
  test_expect_success 'fetch changes via http' '
        echo content >>file &&
        git commit -a -m two &&
-       git push public
+       git push public &&
        (cd clone && git pull) &&
        test_cmp file clone/file
  '
  
+ test_expect_success 'fetch changes via manual http-fetch' '
+       cp -R clone-tmpl clone2 &&
+       HEAD=$(git rev-parse --verify HEAD) &&
+       (cd clone2 &&
+        git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
+        git checkout master-new &&
+        test $HEAD = $(git rev-parse --verify HEAD)) &&
+       test_cmp file clone2/file
+ '
  test_expect_success 'http remote detects correct HEAD' '
        git push public master:other &&
        (cd clone &&