summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ea1ab4b)
raw | patch | inline | side by side (parent: ea1ab4b)
author | Jeff King <peff@peff.net> | |
Thu, 19 May 2011 21:33:17 +0000 (17:33 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 20 May 2011 03:01:10 +0000 (20:01 -0700) |
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch-pack.c | patch | blob | history | |
builtin/receive-pack.c | patch | blob | history | |
transport.c | patch | blob | history | |
transport.h | patch | blob | history |
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 85aff029b225c023f09fda635f16cc00a22ed7ca..60a17c74ef9196e6afc468539ecf67a9d310495e 100644 (file)
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
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 e1ba4dc697abd1b2582713744c5a1892ef4a4882..6bb1281666e45684b0f75ecbfc04e887723e914a 100644 (file)
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
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)
diff --git a/transport.c b/transport.c
index a02f79aae3d91ea4109d21a9ed9ca2d962125375..1a3998ee51e6edf090b18cfd90f4c2c78aece7c6 100644 (file)
--- a/transport.c
+++ b/transport.c
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));
for (extra = transport_get_remote_refs(transport);
extra;
extra = extra->next)
- ref_fn(extra, NULL);
+ 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);
+}
diff --git a/transport.h b/transport.h
index efb19688692b5f1be4fc085cc36d737ace2df417..161d724bba5c132950b45866286c558148560d01 100644 (file)
--- a/transport.h
+++ b/transport.h
int verbose, int porcelain, int *nonfastforward);
typedef void alternate_ref_fn(const struct ref *, void *);
-extern int refs_from_alternate_cb(struct alternate_object_database *e, void *cb);
+extern void for_each_alternate_ref(alternate_ref_fn, void *);
#endif