* [PATCH] refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functions
@ 2009-03-30 3:07 Christian Couder
0 siblings, 0 replies; only message in thread
From: Christian Couder @ 2009-03-30 3:07 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, John Tapsell, Johannes Schindelin
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-03-30 3:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-30 3:07 [PATCH] refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functions Christian Couder
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).