X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=transport.c;h=c9c8056f9de69bd378cd271d70363b5560f13e07;hb=588150b0231ee342ed528292a2205f4049b3dcb1;hp=00786606117feea4b33b7e632b8ff8a3c26de4e4;hpb=34df9fe36a3627e1c2a9ae244820fb61e3891b90;p=git.git diff --git a/transport.c b/transport.c index 007866061..c9c8056f9 100644 --- a/transport.c +++ b/transport.c @@ -156,7 +156,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, continue; if (!ref->peer_ref) continue; - if (!ref->new_sha1 || is_null_sha1(ref->new_sha1)) + if (is_null_sha1(ref->new_sha1)) continue; /* Follow symbolic refs (mainly for HEAD). */ @@ -192,7 +192,7 @@ static const char *rsync_url(const char *url) 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,51 @@ char *transport_anonymize_url(const char *url) literal_copy: return xstrdup(url); } + +struct alternate_refs_data { + alternate_ref_fn *fn; + void *data; +}; + +static int refs_from_alternate_cb(struct alternate_object_database *e, + void *data) +{ + char *other; + size_t len; + struct remote *remote; + struct transport *transport; + const struct ref *extra; + struct alternate_refs_data *cb = data; + + 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) + cb->fn(extra, cb->data); + transport_disconnect(transport); + free(other); + return 0; +} + +void for_each_alternate_ref(alternate_ref_fn fn, void *data) +{ + struct alternate_refs_data cb; + cb.fn = fn; + cb.data = data; + foreach_alt_odb(refs_from_alternate_cb, &cb); +}