path: root/transport.c
diff options
authorJeff King <>2011-05-19 21:33:17 (GMT)
committerJunio C Hamano <>2011-05-20 03:01:10 (GMT)
commit114a6a889f5d21c26800c395a97cdd400073a9e8 (patch)
tree1d6f4cbf532602cece264882eb096fcccaf86de4 /transport.c
parentea1ab4b280ed3b041da53e161e32e38930569f3e (diff)
refactor refs_from_alternate_cb to allow passing extra data
The foreach_alt_odb function triggers a callback for each alternate object db we have, with room for a single void pointer as data. Currently, we always call refs_from_alternate_cb as the callback function, and then pass another callback (to receive each ref individually) as the void pointer. This has two problems: 1. C technically forbids stuffing a function pointer into a "void *". In practice, this probably doesn't matter on any architectures git runs on, but it never hurts to follow the letter of the law. 2. There is no room for an extra data pointer. Indeed, the alternate_ref_fn that refs_from_alternate_cb calls takes a void* for data, but we always pass it NULL. Instead, let's properly stuff our function pointer into a data struct, which also leaves room for an extra caller-supplied data pointer. And to keep things simple for existing callers, let's make a for_each_alternate_ref function that takes care of creating the extra struct. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'transport.c')
1 files changed, 17 insertions, 3 deletions
diff --git a/transport.c b/transport.c
index a02f79a..1a3998e 100644
--- a/transport.c
+++ b/transport.c
@@ -1190,14 +1190,20 @@ literal_copy:
return xstrdup(url);
-int refs_from_alternate_cb(struct alternate_object_database *e, void *cb)
+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;
- alternate_ref_fn *ref_fn = cb;
+ struct alternate_refs_data *cb = data;
e->name[-1] = '\0';
other = xstrdup(real_path(e->base));
@@ -1218,8 +1224,16 @@ int refs_from_alternate_cb(struct alternate_object_database *e, void *cb)
for (extra = transport_get_remote_refs(transport);
extra = extra->next)
- ref_fn(extra, NULL);
+ cb->fn(extra, cb->data);
return 0;
+void for_each_alternate_ref(alternate_ref_fn fn, void *data)
+ struct alternate_refs_data cb;
+ cb.fn = fn;
+ = data;
+ foreach_alt_odb(refs_from_alternate_cb, &cb);