From 114a6a889f5d21c26800c395a97cdd400073a9e8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 19 May 2011 17:33:17 -0400 Subject: 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 --- builtin/fetch-pack.c | 2 +- builtin/receive-pack.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 85aff029b2..60a17c74ef 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -226,7 +226,7 @@ static void insert_one_alternate_ref(const struct ref *ref, void *unused) static void insert_alternate_refs(void) { - foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref); + for_each_alternate_ref(insert_one_alternate_ref, NULL); } #define INITIAL_FLUSH 16 diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index e1ba4dc697..6bb1281666 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -738,7 +738,7 @@ static void add_one_alternate_ref(const struct ref *ref, void *unused) static void add_alternate_refs(void) { - foreach_alt_odb(refs_from_alternate_cb, add_one_alternate_ref); + for_each_alternate_ref(add_one_alternate_ref, NULL); } int cmd_receive_pack(int argc, const char **argv, const char *prefix) -- cgit v1.2.3