From: Junio C Hamano Date: Wed, 23 Mar 2011 04:37:53 +0000 (-0700) Subject: Merge branch 'jc/maint-fetch-alt' X-Git-Tag: v1.7.5-rc0~44 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/91b3c7ce8e189b90d3203265c9625806a15045e1?ds=inline;hp=-c Merge branch 'jc/maint-fetch-alt' * 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 --- 91b3c7ce8e189b90d3203265c9625806a15045e1 diff --combined builtin/fetch-pack.c index ef398620af,4c25968e16..28d6900bb0 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@@ -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) { @@@ -235,6 -246,7 +246,7 @@@ 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 d8e2c5fca7,a5b5fc2ef6..27050e7c16 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@@ -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) @@@ -778,8 -749,6 +749,8 @@@ 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 f1c07816e0,3dfbc6a79c..a02f79aae3 --- a/transport.c +++ b/transport.c @@@ -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); } + + 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(make_absolute_path(e->base)); ++ 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; + }