Merge branch 'jc/maint-fetch-alt'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 04:37:53 +0000 (21:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2011 04:37:53 +0000 (21:37 -0700)
* jc/maint-fetch-alt:
fetch-pack: objects in our alternates are available to us
refs_from_alternate: helper to use refs from alternates

Conflicts:
builtin/receive-pack.c

1  2 
builtin/fetch-pack.c
builtin/receive-pack.c
transport.c
diff --combined builtin/fetch-pack.c
index ef398620affcb55aa1ee0fdd3ca74dda58c37172,4c25968e16b75793a4938bcdf70b937ae3cba923..28d6900bb0e2a4deb036013236e489f1ffaa9e41
@@@ -1,4 -1,4 +1,4 @@@
 -#include "cache.h"
 +#include "builtin.h"
  #include "refs.h"
  #include "pkt-line.h"
  #include "commit.h"
@@@ -9,6 -9,7 +9,7 @@@
  #include "fetch-pack.h"
  #include "remote.h"
  #include "run-command.h"
+ #include "transport.h"
  
  static int transfer_unpack_limit = -1;
  static int fetch_unpack_limit = -1;
@@@ -217,6 -218,16 +218,16 @@@ static void send_request(int fd, struc
                safe_write(fd, buf->buf, buf->len);
  }
  
+ static void insert_one_alternate_ref(const struct ref *ref, void *unused)
+ {
+       rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
+ }
+ static void insert_alternate_refs(void)
+ {
+       foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
+ }
  static int find_common(int fd[2], unsigned char *result_sha1,
                       struct ref *refs)
  {
        marked = 1;
  
        for_each_ref(rev_list_insert_ref, NULL);
+       insert_alternate_refs();
  
        fetching = 0;
        for ( ; refs ; refs = refs->next) {
@@@ -804,8 -816,6 +816,8 @@@ int cmd_fetch_pack(int argc, const cha
        char **pack_lockfile_ptr = NULL;
        struct child_process *conn;
  
 +      packet_trace_identity("fetch-pack");
 +
        nr_heads = 0;
        heads = NULL;
        for (i = 1; i < argc; i++) {
diff --combined builtin/receive-pack.c
index d8e2c5fca7902d6d9a9e8300e129d58ad7a98192,a5b5fc2ef60e272446064e9efa4f9104791094c2..27050e7c1627ed2899963fb3fdb81a7ba95d06df
@@@ -731,43 -731,14 +731,14 @@@ static int delete_only(struct command *
        return 1;
  }
  
- static int add_refs_from_alternate(struct alternate_object_database *e, void *unused)
+ static void add_one_alternate_ref(const struct ref *ref, void *unused)
  {
-       char *other;
-       size_t len;
-       struct remote *remote;
-       struct transport *transport;
-       const struct ref *extra;
-       e->name[-1] = '\0';
-       other = xstrdup(real_path(e->base));
-       e->name[-1] = '/';
-       len = strlen(other);
-       while (other[len-1] == '/')
-               other[--len] = '\0';
-       if (len < 8 || memcmp(other + len - 8, "/objects", 8))
-               return 0;
-       /* Is this a git repository with refs? */
-       memcpy(other + len - 8, "/refs", 6);
-       if (!is_directory(other))
-               return 0;
-       other[len - 8] = '\0';
-       remote = remote_get(other);
-       transport = transport_get(remote, other);
-       for (extra = transport_get_remote_refs(transport);
-            extra;
-            extra = extra->next) {
-               add_extra_ref(".have", extra->old_sha1, 0);
-       }
-       transport_disconnect(transport);
-       free(other);
-       return 0;
+       add_extra_ref(".have", ref->old_sha1, 0);
  }
  
  static void add_alternate_refs(void)
  {
-       foreach_alt_odb(add_refs_from_alternate, NULL);
+       foreach_alt_odb(refs_from_alternate_cb, add_one_alternate_ref);
  }
  
  int cmd_receive_pack(int argc, const char **argv, const char *prefix)
        char *dir = NULL;
        struct command *commands;
  
 +      packet_trace_identity("receive-pack");
 +
        argv++;
        for (i = 1; i < argc; i++) {
                const char *arg = *argv++;
diff --combined transport.c
index f1c07816e01bb0b1ad93d7665b1374e8cd36e6cb,3dfbc6a79c402bac5e18de97a12c131b556597c4..a02f79aae3d91ea4109d21a9ed9ca2d962125375
@@@ -192,7 -192,7 +192,7 @@@ static const char *rsync_url(const cha
  static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
  {
        struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
 -      struct ref dummy = {0}, *tail = &dummy;
 +      struct ref dummy = {NULL}, *tail = &dummy;
        struct child_process rsync;
        const char *args[5];
        int temp_dir_len;
@@@ -1189,3 -1189,37 +1189,37 @@@ char *transport_anonymize_url(const cha
  literal_copy:
        return xstrdup(url);
  }
 -      other = xstrdup(make_absolute_path(e->base));
+ int refs_from_alternate_cb(struct alternate_object_database *e, void *cb)
+ {
+       char *other;
+       size_t len;
+       struct remote *remote;
+       struct transport *transport;
+       const struct ref *extra;
+       alternate_ref_fn *ref_fn = cb;
+       e->name[-1] = '\0';
++      other = xstrdup(real_path(e->base));
+       e->name[-1] = '/';
+       len = strlen(other);
+       while (other[len-1] == '/')
+               other[--len] = '\0';
+       if (len < 8 || memcmp(other + len - 8, "/objects", 8))
+               return 0;
+       /* Is this a git repository with refs? */
+       memcpy(other + len - 8, "/refs", 6);
+       if (!is_directory(other))
+               return 0;
+       other[len - 8] = '\0';
+       remote = remote_get(other);
+       transport = transport_get(remote, other);
+       for (extra = transport_get_remote_refs(transport);
+            extra;
+            extra = extra->next)
+               ref_fn(extra, NULL);
+       transport_disconnect(transport);
+       free(other);
+       return 0;
+ }