Merge branch 'mh/maint-http-proxy-fix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 2 Mar 2008 23:11:26 +0000 (15:11 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Mar 2008 23:11:26 +0000 (15:11 -0800)
* mh/maint-http-proxy-fix:
Set proxy override with http_init()

1  2 
builtin-http-fetch.c
http-push.c
transport.c
diff --combined builtin-http-fetch.c
index 299093ff9134f517e53b5105ec356e6575df6214,48128c610e4b36789efbe16fb974b2f3389093ff..b1f33891c36fe38d855ace535cf9218fe9603541
@@@ -59,7 -59,7 +59,7 @@@ int cmd_http_fetch(int argc, const cha
                url = rewritten_url;
        }
  
-       walker = get_http_walker(url);
+       walker = get_http_walker(url, NULL);
        walker->get_tree = get_tree;
        walker->get_history = get_history;
        walker->get_all = get_all;
@@@ -80,7 -80,8 +80,7 @@@
  
        walker_free(walker);
  
 -      if (rewritten_url)
 -              free(rewritten_url);
 +      free(rewritten_url);
  
        return rc;
  }
diff --combined http-push.c
index 5bc77361f9a8cc40723e6b74977b7021c151ac8f,869c01c75bfd9896aa6a4013701f55270958fff9..5b230380ccd33d8b04f8dfce24050237ae9206ad
@@@ -664,7 -664,8 +664,7 @@@ static void release_request(struct tran
                close(request->local_fileno);
        if (request->local_stream)
                fclose(request->local_stream);
 -      if (request->url != NULL)
 -              free(request->url);
 +      free(request->url);
        free(request);
  }
  
@@@ -1282,8 -1283,10 +1282,8 @@@ static struct remote_lock *lock_remote(
        strbuf_release(&in_buffer);
  
        if (lock->token == NULL || lock->timeout <= 0) {
 -              if (lock->token != NULL)
 -                      free(lock->token);
 -              if (lock->owner != NULL)
 -                      free(lock->owner);
 +              free(lock->token);
 +              free(lock->owner);
                free(url);
                free(lock);
                lock = NULL;
@@@ -1341,7 -1344,8 +1341,7 @@@ static int unlock_remote(struct remote_
                        prev->next = prev->next->next;
        }
  
 -      if (lock->owner != NULL)
 -              free(lock->owner);
 +      free(lock->owner);
        free(lock->url);
        free(lock->token);
        free(lock);
@@@ -1630,19 -1634,12 +1630,19 @@@ static struct object_list **process_tre
  
        init_tree_desc(&desc, tree->buffer, tree->size);
  
 -      while (tree_entry(&desc, &entry)) {
 -              if (S_ISDIR(entry.mode))
 +      while (tree_entry(&desc, &entry))
 +              switch (object_type(entry.mode)) {
 +              case OBJ_TREE:
                        p = process_tree(lookup_tree(entry.sha1), p, &me, name);
 -              else
 +                      break;
 +              case OBJ_BLOB:
                        p = process_blob(lookup_blob(entry.sha1), p, &me, name);
 -      }
 +                      break;
 +              default:
 +                      /* Subproject commit - not in this repository */
 +                      break;
 +              }
 +
        free(tree->buffer);
        tree->buffer = NULL;
        return p;
@@@ -2031,7 -2028,8 +2031,7 @@@ static void fetch_symref(const char *pa
        }
        free(url);
  
 -      if (*symref != NULL)
 -              free(*symref);
 +      free(*symref);
        *symref = NULL;
        hashclr(sha1);
  
@@@ -2133,8 -2131,6 +2133,8 @@@ static int delete_remote_branch(char *p
  
        /* Send delete request */
        fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
 +      if (dry_run)
 +              return 0;
        url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1);
        sprintf(url, "%s%s", remote->url, remote_ref->name);
        slot = get_active_slot();
@@@ -2237,7 -2233,7 +2237,7 @@@ int main(int argc, char **argv
  
        memset(remote_dir_exists, -1, 256);
  
-       http_init();
+       http_init(NULL);
  
        no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
  
  
                if (!ref->peer_ref)
                        continue;
 +
 +              if (is_zero_sha1(ref->peer_ref->new_sha1)) {
 +                      if (delete_remote_branch(ref->name, 1) == -1) {
 +                              error("Could not remove %s", ref->name);
 +                              rc = -4;
 +                      }
 +                      new_refs++;
 +                      continue;
 +              }
 +
                if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
                        if (push_verbosely || 1)
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
                        }
                }
                hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
 -              if (is_zero_sha1(ref->new_sha1)) {
 -                      error("cannot happen anymore");
 -                      rc = -3;
 -                      continue;
 -              }
                new_refs++;
                strcpy(old_hex, sha1_to_hex(ref->old_sha1));
                new_hex = sha1_to_hex(ref->new_sha1);
  
                /* Generate a list of objects that need to be pushed */
                pushing = 0;
 -              prepare_revision_walk(&revs);
 +              if (prepare_revision_walk(&revs))
 +                      die("revision walk setup failed");
                mark_edges_uninteresting(revs.commits);
                objects_to_send = get_delta(&revs, ref_lock);
                finish_all_active_slots();
                fill_active_slots();
                add_fill_function(NULL, fill_active_slot);
  #endif
 -              finish_all_active_slots();
 +              do {
 +                      finish_all_active_slots();
 +#ifdef USE_CURL_MULTI
 +                      fill_active_slots();
 +#endif
 +              } while (request_queue_head && !aborted);
  
                /* Update the remote branch if all went well */
 -              if (aborted || !update_remote(ref->new_sha1, ref_lock)) {
 +              if (aborted || !update_remote(ref->new_sha1, ref_lock))
                        rc = 1;
 -                      goto unlock;
 -              }
  
 -      unlock:
                if (!rc)
                        fprintf(stderr, "    done\n");
                unlock_remote(ref_lock);
        }
  
   cleanup:
 -      if (rewritten_url)
 -              free(rewritten_url);
 +      free(rewritten_url);
        if (info_ref_lock)
                unlock_remote(info_ref_lock);
        free(remote);
diff --combined transport.c
index 0a5cf0a9c29c34a7f0fd0d53a5f6472ab2f2fa4f,97c59dce60eb01382bdd10e4d20cc476fd489cf0..166c1d1d46d954653b50897ca49678bd21f6bdfb
@@@ -442,7 -442,8 +442,8 @@@ static struct ref *get_refs_via_curl(st
        struct ref *last_ref = NULL;
  
        if (!transport->data)
-               transport->data = get_http_walker(transport->url);
+               transport->data = get_http_walker(transport->url,
+                                               transport->remote);
  
        refs_url = xmalloc(strlen(transport->url) + 11);
        sprintf(refs_url, "%s/info/refs", transport->url);
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_URL, refs_url);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
-       if (transport->remote->http_proxy)
-               curl_easy_setopt(slot->curl, CURLOPT_PROXY,
-                                transport->remote->http_proxy);
  
        if (start_active_slot(slot)) {
                run_active_slot(slot);
@@@ -509,7 -507,8 +507,8 @@@ static int fetch_objs_via_curl(struct t
                                 int nr_objs, struct ref **to_fetch)
  {
        if (!transport->data)
-               transport->data = get_http_walker(transport->url);
+               transport->data = get_http_walker(transport->url,
+                                               transport->remote);
        return fetch_objs_via_walker(transport, nr_objs, to_fetch);
  }
  
@@@ -562,8 -561,6 +561,8 @@@ struct git_transport_data 
        unsigned thin : 1;
        unsigned keep : 1;
        int depth;
 +      struct child_process *conn;
 +      int fd[2];
        const char *uploadpack;
        const char *receivepack;
  };
@@@ -594,20 -591,20 +593,20 @@@ static int set_git_option(struct transp
        return 1;
  }
  
 +static int connect_setup(struct transport *transport)
 +{
 +      struct git_transport_data *data = transport->data;
 +      data->conn = git_connect(data->fd, transport->url, data->uploadpack, 0);
 +      return 0;
 +}
 +
  static struct ref *get_refs_via_connect(struct transport *transport)
  {
        struct git_transport_data *data = transport->data;
        struct ref *refs;
 -      int fd[2];
 -      char *dest = xstrdup(transport->url);
 -      struct child_process *conn = git_connect(fd, dest, data->uploadpack, 0);
 -
 -      get_remote_heads(fd[0], &refs, 0, NULL, 0);
 -      packet_flush(fd[1]);
 -
 -      finish_connect(conn);
  
 -      free(dest);
 +      connect_setup(transport);
 +      get_remote_heads(data->fd[0], &refs, 0, NULL, 0);
  
        return refs;
  }
@@@ -618,11 -615,10 +617,11 @@@ static int fetch_refs_via_pack(struct t
        struct git_transport_data *data = transport->data;
        char **heads = xmalloc(nr_heads * sizeof(*heads));
        char **origh = xmalloc(nr_heads * sizeof(*origh));
 -      struct ref *refs;
 +      const struct ref *refs;
        char *dest = xstrdup(transport->url);
        struct fetch_pack_args args;
        int i;
 +      struct ref *refs_tmp = NULL;
  
        memset(&args, 0, sizeof(args));
        args.uploadpack = data->uploadpack;
  
        for (i = 0; i < nr_heads; i++)
                origh[i] = heads[i] = xstrdup(to_fetch[i]->name);
 -      refs = fetch_pack(&args, dest, nr_heads, heads, &transport->pack_lockfile);
 +
 +      if (!data->conn) {
 +              connect_setup(transport);
 +              get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0);
 +      }
 +
 +      refs = fetch_pack(&args, data->fd, data->conn,
 +                        refs_tmp ? refs_tmp : transport->remote_refs,
 +                        dest, nr_heads, heads, &transport->pack_lockfile);
 +      close(data->fd[0]);
 +      close(data->fd[1]);
 +      if (finish_connect(data->conn))
 +              refs = NULL;
 +      data->conn = NULL;
 +
 +      free_refs(refs_tmp);
  
        for (i = 0; i < nr_heads; i++)
                free(origh[i]);
        free(origh);
        free(heads);
 -      free_refs(refs);
        free(dest);
        return (refs ? 0 : -1);
  }
@@@ -677,15 -659,7 +676,15 @@@ static int git_transport_push(struct tr
  
  static int disconnect_git(struct transport *transport)
  {
 -      free(transport->data);
 +      struct git_transport_data *data = transport->data;
 +      if (data->conn) {
 +              packet_flush(data->fd[1]);
 +              close(data->fd[0]);
 +              close(data->fd[1]);
 +              finish_connect(data->conn);
 +      }
 +
 +      free(data);
        return 0;
  }
  
@@@ -745,7 -719,6 +744,7 @@@ struct transport *transport_get(struct 
                ret->disconnect = disconnect_git;
  
                data->thin = 1;
 +              data->conn = NULL;
                data->uploadpack = "git-upload-pack";
                if (remote && remote->uploadpack)
                        data->uploadpack = remote->uploadpack;