diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-07-25 14:13:33 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-25 14:13:33 -0700 |
commit | 87492cb24d9d8be8e18217b89ae5f090089ff31d (patch) | |
tree | b517e8efaa98fa713d8b6286ed6ee1c08c385a2e /refs.c | |
parent | 702ebbf4e2937accbac8184f87932f961e626a63 (diff) | |
parent | 2880d16f09635f9d43247b27fd7e6508b992e599 (diff) | |
download | git-87492cb24d9d8be8e18217b89ae5f090089ff31d.tar.gz |
Merge branch 'mh/ref-iterators'
The API to iterate over all the refs (i.e. for_each_ref(), etc.)
has been revamped.
* mh/ref-iterators:
for_each_reflog(): reimplement using iterators
dir_iterator: new API for iterating over a directory tree
for_each_reflog(): don't abort for bad references
do_for_each_ref(): reimplement using reference iteration
refs: introduce an iterator interface
ref_resolves_to_object(): new function
entry_resolves_to_object(): rename function from ref_resolves_to_object()
get_ref_cache(): only create an instance if there is a submodule
remote rm: handle symbolic refs correctly
delete_refs(): add a flags argument
refs: use name "prefix" consistently
do_for_each_ref(): move docstring to the header file
refs: remove unnecessary "extern" keywords
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -1120,6 +1120,26 @@ int head_ref(each_ref_fn fn, void *cb_data) return head_ref_submodule(NULL, fn, cb_data); } +/* + * Call fn for each reference in the specified submodule for which the + * refname begins with prefix. If trim is non-zero, then trim that + * many characters off the beginning of each refname before passing + * the refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to + * include broken references in the iteration. If fn ever returns a + * non-zero value, stop the iteration and return that value; + * otherwise, return 0. + */ +static int do_for_each_ref(const char *submodule, const char *prefix, + each_ref_fn fn, int trim, int flags, void *cb_data) +{ + struct ref_iterator *iter; + + iter = files_ref_iterator_begin(submodule, prefix, flags); + iter = prefix_ref_iterator_begin(iter, prefix, trim); + + return do_for_each_ref_iterator(iter, fn, cb_data); +} + int for_each_ref(each_ref_fn fn, void *cb_data) { return do_for_each_ref(NULL, "", fn, 0, 0, cb_data); |