mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functions
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. Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
parent
eaa759b914
commit
2a8177b63d
11
refs.c
11
refs.c
@ -647,19 +647,24 @@ 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_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
|
||||
{
|
||||
return do_for_each_ref(prefix, fn, strlen(prefix), 0, cb_data);
|
||||
}
|
||||
|
||||
int for_each_tag_ref(each_ref_fn fn, void *cb_data)
|
||||
{
|
||||
return do_for_each_ref("refs/tags/", fn, 10, 0, cb_data);
|
||||
return for_each_ref_in("refs/tags/", fn, cb_data);
|
||||
}
|
||||
|
||||
int for_each_branch_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/heads/", fn, cb_data);
|
||||
}
|
||||
|
||||
int for_each_remote_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/remotes/", fn, cb_data);
|
||||
}
|
||||
|
||||
int for_each_rawref(each_ref_fn fn, void *cb_data)
|
||||
|
1
refs.h
1
refs.h
@ -20,6 +20,7 @@ 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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user