summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-04-10 05:30:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-04-10 22:55:55 (GMT)
commit933ac036d29e65e1b3d71332d9ade8edd1e8a89b (patch)
tree60c744f379c82dc8b82801efca5d07bce081de21 /refs.c
parent432ad41e60cedb87ceec446ab034d46a53f5f9d8 (diff)
downloadgit-933ac036d29e65e1b3d71332d9ade8edd1e8a89b.zip
git-933ac036d29e65e1b3d71332d9ade8edd1e8a89b.tar.gz
git-933ac036d29e65e1b3d71332d9ade8edd1e8a89b.tar.bz2
do_for_each_ref(): only iterate over the subtree that was requested
If the base argument has a "/" chararacter, then only iterate over the reference subdir whose name is the part up to the last "/". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/refs.c b/refs.c
index b6fb1ec..09322fe 100644
--- a/refs.c
+++ b/refs.c
@@ -1143,13 +1143,34 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
int trim, int flags, void *cb_data)
{
struct ref_cache *refs = get_ref_cache(submodule);
- struct ref_dir *packed_refs = get_packed_refs(refs);
- struct ref_dir *loose_refs = get_loose_refs(refs);
- sort_ref_dir(packed_refs);
- sort_ref_dir(loose_refs);
- return do_for_each_ref_in_dirs(packed_refs,
- loose_refs,
- base, fn, trim, flags, cb_data);
+ struct ref_dir *packed_dir = get_packed_refs(refs);
+ struct ref_dir *loose_dir = get_loose_refs(refs);
+ int retval = 0;
+
+ if (base && *base) {
+ packed_dir = find_containing_dir(packed_dir, base, 0);
+ loose_dir = find_containing_dir(loose_dir, base, 0);
+ }
+
+ if (packed_dir && loose_dir) {
+ sort_ref_dir(packed_dir);
+ sort_ref_dir(loose_dir);
+ retval = do_for_each_ref_in_dirs(
+ packed_dir, loose_dir,
+ base, fn, trim, flags, cb_data);
+ } else if (packed_dir) {
+ sort_ref_dir(packed_dir);
+ retval = do_for_each_ref_in_dir(
+ packed_dir, 0,
+ base, fn, trim, flags, cb_data);
+ } else if (loose_dir) {
+ sort_ref_dir(loose_dir);
+ retval = do_for_each_ref_in_dir(
+ loose_dir, 0,
+ base, fn, trim, flags, cb_data);
+ }
+
+ return retval;
}
static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)