From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, John Tapsell <johnflux@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functions
Date: Mon, 30 Mar 2009 05:07:15 +0200 [thread overview]
Message-ID: <20090330050715.7fa6f3ab.chriscool@tuxfamily.org> (raw)
The "for_each_{tag,branch,remote,replace,}_ref" functions are
redefined in terms of "for_each_ref_in" so that we can lose the
hardcoded length of prefix strings from the code.
And the "for_each_bisect_ref" as it is only used in "bisect.c" and
a call like 'for_each_ref_in("refs/bisect/", register_ref, NULL)'
is clear enough.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
bisect.c | 2 +-
refs.c | 18 +++++++++---------
refs.h | 2 +-
3 files changed, 11 insertions(+), 11 deletions(-)
Junio wrote:
> > +static int read_bisect_refs(void)
> > +{
> > + return for_each_bisect_ref(register_ref, NULL);
> > +}
>
> This is only a minor point, but I do not foresee anybody other than
> bisect--helper (and later bisect) running for_each_bisect_ref(). It might
> make sense to redo [01/10] to introduce
>
> for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb)
>
> and change this call site to:
>
> return for_each_ref_in("refs/bisect/", register_ref, NULL);
>
> Needless to say, for_each_{ref,tag_ref,branch_ref,remote_ref}() can be
> redefined in terms of for_each_ref_in() so that we can lose these
> hardcoded length of prefix strings from the code.
Here is a patch to do that, though "for_each_ref" is not redefined in terms
of "for_each_ref_in", as it passes 0 as the length of the prefix string.
diff --git a/bisect.c b/bisect.c
index b4089ca..2e3d063 100644
--- a/bisect.c
+++ b/bisect.c
@@ -422,7 +422,7 @@ static int register_ref(const char *refname, const unsigned char *sha1,
static int read_bisect_refs(void)
{
- return for_each_bisect_ref(register_ref, NULL);
+ return for_each_ref_in("refs/bisect/", register_ref, NULL);
}
void read_bisect_paths(void)
diff --git a/refs.c b/refs.c
index e512d4c..c52a758 100644
--- a/refs.c
+++ b/refs.c
@@ -647,29 +647,29 @@ int for_each_ref(each_ref_fn fn, void *cb_data)
return do_for_each_ref("refs/", fn, 0, 0, cb_data);
}
-int for_each_tag_ref(each_ref_fn fn, void *cb_data)
+int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref("refs/tags/", fn, 10, 0, cb_data);
+ return do_for_each_ref(prefix, fn, strlen(prefix), 0, cb_data);
}
-int for_each_branch_ref(each_ref_fn fn, void *cb_data)
+int for_each_tag_ref(each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref("refs/heads/", fn, 11, 0, cb_data);
+ return for_each_ref_in("refs/tags/", fn, cb_data);
}
-int for_each_remote_ref(each_ref_fn fn, void *cb_data)
+int for_each_branch_ref(each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref("refs/remotes/", fn, 13, 0, cb_data);
+ return for_each_ref_in("refs/heads/", fn, cb_data);
}
-int for_each_bisect_ref(each_ref_fn fn, void *cb_data)
+int for_each_remote_ref(each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref("refs/bisect/", fn, 12, 0, cb_data);
+ return for_each_ref_in("refs/remotes/", fn, cb_data);
}
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref("refs/replace/", fn, 13, 0, cb_data);
+ return for_each_ref_in("refs/replace/", fn, cb_data);
}
int for_each_rawref(each_ref_fn fn, void *cb_data)
diff --git a/refs.h b/refs.h
index c76d96b..18649a7 100644
--- a/refs.h
+++ b/refs.h
@@ -20,10 +20,10 @@ struct ref_lock {
typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
extern int head_ref(each_ref_fn, void *);
extern int for_each_ref(each_ref_fn, void *);
+extern int for_each_ref_in(const char *, each_ref_fn, void *);
extern int for_each_tag_ref(each_ref_fn, void *);
extern int for_each_branch_ref(each_ref_fn, void *);
extern int for_each_remote_ref(each_ref_fn, void *);
-extern int for_each_bisect_ref(each_ref_fn, void *);
extern int for_each_replace_ref(each_ref_fn, void *);
/* can be used to learn about broken ref and symref */
--
1.6.2.1.531.gbd5067.dirty
reply other threads:[~2009-03-30 3:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20090330050715.7fa6f3ab.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johnflux@gmail.com \
/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).