summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-03-22 21:37:53 -0700
committerJunio C Hamano <gitster@pobox.com>2011-03-22 21:37:53 -0700
commit91b3c7ce8e189b90d3203265c9625806a15045e1 (patch)
tree2287f84dbd07706e74db16896e8e7f3a7d6dd7ed /transport.c
parent1c92e394468c927f129c8f2a138b760f884e3bed (diff)
parente52d719266a06a8553043cb5616d9b4ce4abd27a (diff)
downloadgit-91b3c7ce8e189b90d3203265c9625806a15045e1.tar.gz
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
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/transport.c b/transport.c
index f1c07816e0..a02f79aae3 100644
--- a/transport.c
+++ b/transport.c
@@ -1189,3 +1189,37 @@ char *transport_anonymize_url(const char *url)
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(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;
+}