X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=transport.c;h=1a3998ee51e6edf090b18cfd90f4c2c78aece7c6;hb=114a6a889f5d21c26800c395a97cdd400073a9e8;hp=f1c07816e01bb0b1ad93d7665b1374e8cd36e6cb;hpb=1ea9f9d6c28caf886747ca256e9d39d24f03d229;p=thirdparty%2Fgit.git diff --git a/transport.c b/transport.c index f1c07816e0..1a3998ee51 100644 --- a/transport.c +++ b/transport.c @@ -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); +}