Merge branch 'rc/maint-curl-helper' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 16 Jun 2010 23:19:43 +0000 (16:19 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Jun 2010 23:19:43 +0000 (16:19 -0700)
* rc/maint-curl-helper:
remote-curl: ensure that URLs have a trailing slash
http: make end_url_with_slash() public
t5541-http-push: add test for URLs with trailing slash

Conflicts:
remote-curl.c

1  2 
http.c
remote-curl.c
t/t5541-http-push.sh
diff --combined http.c
index 4814217c6401faa1fd8f13f0288758f57b5e3755,163c0e48e471430adea36b9b63a8996de62d71b1..364c333c6b9c553121c4cc6ad6a9b622de185808
--- 1/http.c
--- 2/http.c
+++ b/http.c
@@@ -204,7 -204,7 +204,7 @@@ static void init_curl_http_auth(CURL *r
        if (user_name) {
                struct strbuf up = STRBUF_INIT;
                if (!user_pass)
 -                      user_pass = xstrdup(getpass("Password: "));
 +                      user_pass = xstrdup(git_getpass("Password: "));
                strbuf_addf(&up, "%s:%s", user_name, user_pass);
                curl_easy_setopt(result, CURLOPT_USERPWD,
                                 strbuf_detach(&up, NULL));
@@@ -219,7 -219,7 +219,7 @@@ static int has_cert_password(void
                return 0;
        /* Only prompt the user once. */
        ssl_cert_password_required = -1;
 -      ssl_cert_password = getpass("Certificate Password: ");
 +      ssl_cert_password = git_getpass("Certificate Password: ");
        if (ssl_cert_password != NULL) {
                ssl_cert_password = xstrdup(ssl_cert_password);
                return 1;
@@@ -720,7 -720,7 +720,7 @@@ static inline int hex(int v
                return 'A' + v - 10;
  }
  
static void end_url_with_slash(struct strbuf *buf, const char *url)
+ void end_url_with_slash(struct strbuf *buf, const char *url)
  {
        strbuf_addstr(buf, url);
        if (buf->len && buf->buf[buf->len - 1] != '/')
diff --combined remote-curl.c
index b76bfcb3d3cdbbee2e3279a6696c7d6b526176d7,1fe59d6db0e85ab938959f08d3bca4a83f748ab5..9c7fcf29566caa3813bd91a22fc78a00cec05335
@@@ -9,7 -9,8 +9,7 @@@
  #include "sideband.h"
  
  static struct remote *remote;
- static const char *url;
+ static const char *url; /* always ends with a trailing slash */
 -static struct walker *walker;
  
  struct options {
        int verbosity;
  };
  static struct options options;
  
 -static void init_walker(void)
 -{
 -      if (!walker)
 -              walker = get_http_walker(url, remote);
 -}
 -
  static int set_option(const char *name, const char *value)
  {
        if (!strcmp(name, "verbosity")) {
@@@ -101,7 -108,7 +101,7 @@@ static struct discovery* discover_refs(
                return last;
        free_discovery(last);
  
-       strbuf_addf(&buffer, "%s/info/refs", url);
+       strbuf_addf(&buffer, "%sinfo/refs", url);
        if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
                is_http = 1;
                if (!strchr(url, '?'))
        }
        refs_url = strbuf_detach(&buffer, NULL);
  
 -      init_walker();
        http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
  
        /* try again with "plain" url (no ? or & appended) */
                strbuf_reset(&buffer);
  
                proto_git_candidate = 0;
-               strbuf_addf(&buffer, "%s/info/refs", url);
+               strbuf_addf(&buffer, "%sinfo/refs", url);
                refs_url = strbuf_detach(&buffer, NULL);
  
                http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
        return last;
  }
  
 -static int write_discovery(int fd, void *data)
 +static int write_discovery(int in, int out, void *data)
  {
        struct discovery *heads = data;
        int err = 0;
 -      if (write_in_full(fd, heads->buf, heads->len) != heads->len)
 +      if (write_in_full(out, heads->buf, heads->len) != heads->len)
                err = 1;
 -      close(fd);
 +      close(out);
        return err;
  }
  
@@@ -194,7 -202,6 +194,7 @@@ static struct ref *parse_git_refs(struc
        memset(&async, 0, sizeof(async));
        async.proc = write_discovery;
        async.data = heads;
 +      async.out = -1;
  
        if (start_async(&async))
                die("cannot start thread to parse advertised refs");
@@@ -242,8 -249,9 +242,8 @@@ static struct ref *parse_info_refs(stru
                i++;
        }
  
 -      init_walker();
        ref = alloc_ref("HEAD");
 -      if (!walker->fetch_ref(walker, ref) &&
 +      if (!http_fetch_ref(url, ref) &&
            !resolve_remote_symref(ref, refs)) {
                ref->next = refs;
                refs = ref;
@@@ -493,6 -501,7 +493,6 @@@ static int rpc_service(struct rpc_stat
        struct child_process client;
        int err = 0;
  
 -      init_walker();
        memset(&client, 0, sizeof(client));
        client.in = -1;
        client.out = -1;
        rpc->out = client.out;
        strbuf_init(&rpc->result, 0);
  
-       strbuf_addf(&buf, "%s/%s", url, svc);
+       strbuf_addf(&buf, "%s%s", url, svc);
        rpc->service_url = strbuf_detach(&buf, NULL);
  
        strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
  
  static int fetch_dumb(int nr_heads, struct ref **to_fetch)
  {
 +      struct walker *walker;
        char **targets = xmalloc(nr_heads * sizeof(char*));
        int ret, i;
  
        for (i = 0; i < nr_heads; i++)
                targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
  
 -      init_walker();
 +      walker = get_http_walker(url);
        walker->get_all = 1;
        walker->get_tree = 1;
        walker->get_history = 1;
        walker->get_verbosely = options.verbosity >= 3;
        walker->get_recover = 0;
        ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
 +      walker_free(walker);
  
        for (i = 0; i < nr_heads; i++)
                free(targets[i]);
@@@ -798,13 -805,13 +798,15 @@@ int main(int argc, const char **argv
        remote = remote_get(argv[1]);
  
        if (argc > 2) {
-               url = argv[2];
+               end_url_with_slash(&buf, argv[2]);
        } else {
-               url = remote->url[0];
+               end_url_with_slash(&buf, remote->url[0]);
        }
  
+       url = strbuf_detach(&buf, NULL);
 +      http_init(remote);
 +
        do {
                if (strbuf_getline(&buf, stdin, '\n') == EOF)
                        break;
                }
                strbuf_reset(&buf);
        } while (1);
 +
 +      http_cleanup();
 +
        return 0;
  }
diff --combined t/t5541-http-push.sh
index 795dc2bcdf98e582dd2f05d901b791ab4225ce3b,f0c50d3d774dcbd2449988c65e0813cf25366b89..17e1bdc5a81ce4802f5074ddb9c1996c68fc97be
@@@ -34,8 -34,34 +34,34 @@@ test_expect_success 'setup remote repos
        mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
  '
  
- test_expect_success 'clone remote repository' '
+ cat >exp <<EOF
+ GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
+ POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
+ EOF
+ test_expect_success 'no empty path components' '
+       # In the URL, add a trailing slash, and see if git appends yet another
+       # slash.
        cd "$ROOT_PATH" &&
+       git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
+       sed -e "
+               s/^.* \"//
+               s/\"//
+               s/ [1-9][0-9]*\$//
+               s/^GET /GET  /
+       " >act <"$HTTPD_ROOT_PATH"/access.log &&
+       # Clear the log, so that it does not affect the "used receive-pack
+       # service" test which reads the log too.
+       #
+       # We do this before the actual comparison to ensure the log is cleared.
+       echo > "$HTTPD_ROOT_PATH"/access.log &&
+       test_cmp exp act
+ '
+ test_expect_success 'clone remote repository' '
+       rm -rf test_repo_clone &&
        git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
  '
  
@@@ -68,6 -94,7 +94,7 @@@ test_expect_success 'create and delete 
  '
  
  cat >exp <<EOF
  GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
  GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
@@@ -88,8 -115,26 +115,8 @@@ test_expect_success 'used receive-pack 
        test_cmp exp act
  '
  
 -test_expect_success 'non-fast-forward push fails' '
 -      cd "$ROOT_PATH"/test_repo_clone &&
 -      git checkout master &&
 -      echo "changed" > path2 &&
 -      git commit -a -m path2 --amend &&
 -
 -      HEAD=$(git rev-parse --verify HEAD) &&
 -      !(git push -v origin >output 2>&1) &&
 -      (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
 -       test $HEAD != $(git rev-parse --verify HEAD))
 -'
 -
 -test_expect_success 'non-fast-forward push show ref status' '
 -      grep "^ ! \[rejected\][ ]*master -> master (non-fast-forward)$" output
 -'
 -
 -test_expect_success 'non-fast-forward push shows help message' '
 -      grep "To prevent you from losing history, non-fast-forward updates were rejected" \
 -              output
 -'
 +test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 +      "$ROOT_PATH"/test_repo_clone master
  
  test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
        # create a dissimilarly-named remote ref so that git is unable to match the