From: Michael Witten <mfwitten@gmail.com>
To: git@vger.kernel.org
Subject: [RFC 1/3] Alternates API: Untangle the interface
Date: Wed, 30 Mar 2011 20:43:18 +0000 [thread overview]
Message-ID: <5ed7886ec5e12c8e3a5f45d19625a4f5d2cdd38a.1301521243.git.mfwitten@gmail.com> (raw)
In-Reply-To: <cover.1301521243.git.mfwitten@gmail.com>
These 2 functions:
cache.h:896: foreach_alt_odb
transport.h:170: refs_from_alternate_cb
were unnecessarily coupled; the callback used by:
refs_from_alternate_cb
was being passed to the higher-level:
foreach_alt_odb
which necessitated some casting ugliness that has
actually been invoking undefined behavior[0].
This commit decouples this relationship, resulting
in a simpler (albeit slightly more verbose) usage.
As a bonus, the undefined behavior is automatically
resolved.
References
----------
[0] Variables of type pointer to void were being used
to pass around values of type pointer to function; see:
[RFC 1/2] Portability: Convert strictly between function pointers
Message-ID: <3c6b883f-8860-4da2-b328-d912019a4145-mfwitten@gmail.com>
Signed-off-by: Michael Witten <mfwitten@gmail.com>
---
builtin/fetch-pack.c | 7 ++++++-
builtin/receive-pack.c | 7 ++++++-
cache.h | 4 ++--
sha1_file.c | 4 ++--
transport.c | 3 +--
transport.h | 4 ++--
6 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/cache.h b/cache.h
index 9f06d21..71cfcef 100644
--- a/cache.h
+++ b/cache.h
@@ -892,8 +892,8 @@ extern struct alternate_object_database {
} *alt_odb_list;
extern void prepare_alt_odb(void);
extern void add_to_alternates_file(const char *reference);
-typedef int alt_odb_fn(struct alternate_object_database *, void *);
+typedef int (*alt_odb_fn)(struct alternate_object_database *);
-extern void foreach_alt_odb(alt_odb_fn, void*);
+extern void foreach_alt_odb(alt_odb_fn);
struct pack_window {
struct pack_window *next;
diff --git a/sha1_file.c b/sha1_file.c
index df0edba..e55a496 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -388,13 +388,13 @@ void add_to_alternates_file(const char *reference)
link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
}
-void foreach_alt_odb(alt_odb_fn fn, void *cb)
+void foreach_alt_odb(alt_odb_fn fn)
{
struct alternate_object_database *ent;
prepare_alt_odb();
for (ent = alt_odb_list; ent; ent = ent->next)
- if (fn(ent, cb))
+ if (fn(ent))
return;
}
diff --git a/transport.h b/transport.h
index efb1968..72a692f 100644
--- a/transport.h
+++ b/transport.h
@@ -166,7 +166,7 @@ int transport_refs_pushed(struct ref *ref);
void transport_print_push_status(const char *dest, struct ref *refs,
int verbose, int porcelain, int *nonfastforward);
-typedef void alternate_ref_fn(const struct ref *, void *);
+typedef void (*alternate_ref_fn)(const struct ref *, void *);
-extern int refs_from_alternate_cb(struct alternate_object_database *e, void *cb);
+extern int refs_from_alternate_cb(struct alternate_object_database *, alternate_ref_fn);
#endif
diff --git a/transport.c b/transport.c
index a02f79a..c61723f 100644
--- a/transport.c
+++ b/transport.c
@@ -1190,14 +1190,13 @@ literal_copy:
return xstrdup(url);
}
-int refs_from_alternate_cb(struct alternate_object_database *e, void *cb)
+int refs_from_alternate_cb(struct alternate_object_database *e, alternate_ref_fn ref_fn)
{
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));
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 85aff02..62ebdb4 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -224,9 +224,14 @@ static void insert_one_alternate_ref(const struct ref *ref, void *unused)
rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
}
+static int alt_odb_callback(struct alternate_object_database *d)
+{
+ return refs_from_alternate_cb(d,insert_one_alternate_ref);
+}
+
static void insert_alternate_refs(void)
{
- foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
+ foreach_alt_odb(alt_odb_callback);
}
#define INITIAL_FLUSH 16
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 27050e7..8ef6301 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -736,9 +736,14 @@ static void add_one_alternate_ref(const struct ref *ref, void *unused)
add_extra_ref(".have", ref->old_sha1, 0);
}
+static int alt_odb_callback(struct alternate_object_database *d)
+{
+ return refs_from_alternate_cb(d,add_one_alternate_ref);
+}
+
static void add_alternate_refs(void)
{
- foreach_alt_odb(refs_from_alternate_cb, add_one_alternate_ref);
+ foreach_alt_odb(alt_odb_callback);
}
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
--
1.7.4.18.g68fe8
next prev parent reply other threads:[~2011-03-30 22:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-29 15:28 [RFC 2/2] Future Proofing: Pass around pointers to either functions or data Michael Witten
2011-03-29 15:02 ` [RFC 1/2] Portability: Convert strictly between function pointers Michael Witten
2011-03-30 10:09 ` [RFC 2/2] Future Proofing: Pass around pointers to either functions or data Erik Faye-Lund
2011-03-30 15:02 ` Michael Witten
2011-03-30 19:41 ` Junio C Hamano
2011-03-30 21:40 ` [RFC 0/3] Alternates API Michael Witten
2011-03-30 21:24 ` [RFC 2/3] Alternates API: Improve naming Michael Witten
2011-03-30 21:28 ` [RFC 3/3] Alternates API: Remove unused parameter Michael Witten
2011-03-30 20:43 ` Michael Witten [this message]
2011-03-30 22:28 ` [RFC 1/3] Alternates API: Untangle the interface Junio C Hamano
2011-03-30 22:46 ` [RFC 3/3] Alternates API: Remove unused parameter Junio C Hamano
2011-03-30 22:31 ` [RFC 2/3] Alternates API: Improve naming Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5ed7886ec5e12c8e3a5f45d19625a4f5d2cdd38a.1301521243.git.mfwitten@gmail.com \
--to=mfwitten@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).