aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-04-10 07:30:15 +0200
committerJunio C Hamano <gitster@pobox.com>2012-04-10 15:51:52 -0700
commitc36b5bc2e44c7e53a4c078056f1c40c155d8a87e (patch)
tree3d7f24a91bcdf98035059ecba5f612b0351a98a6 /refs.c
parent429213e47039e6c60dd7ffcf4b32bf5bb3515690 (diff)
downloadgit-c36b5bc2e44c7e53a4c078056f1c40c155d8a87e.tar.gz
git-c36b5bc2e44c7e53a4c078056f1c40c155d8a87e.tar.xz
do_for_each_ref_in_array(): new function
Extract function do_for_each_ref_in_array() from do_for_each_ref(). The new function will be a useful building block for storing refs hierarchically. 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.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/refs.c b/refs.c
index 86e05dbd8..d9dffc320 100644
--- a/refs.c
+++ b/refs.c
@@ -269,6 +269,25 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
}
/*
+ * Call fn for each reference in array that has index in the range
+ * offset <= index < array->nr. This function does not sort the
+ * array; sorting should be done by the caller.
+ */
+static int do_for_each_ref_in_array(struct ref_array *array, int offset,
+ const char *base,
+ each_ref_fn fn, int trim, int flags, void *cb_data)
+{
+ int i;
+ assert(array->sorted == array->nr);
+ for (i = offset; i < array->nr; i++) {
+ int retval = do_one_ref(base, fn, trim, flags, cb_data, array->refs[i]);
+ if (retval)
+ return retval;
+ }
+ return 0;
+}
+
+/*
* Return true iff a reference named refname could be created without
* conflicting with the name of an existing reference. If oldrefname
* is non-NULL, ignore potential conflicts with oldrefname (e.g.,
@@ -878,16 +897,10 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
return retval;
}
- if (l < loose->nr) {
- p = l;
- packed = loose;
- }
-
- for (; p < packed->nr; p++) {
- retval = do_one_ref(base, fn, trim, flags, cb_data, packed->refs[p]);
- if (retval)
- return retval;
- }
+ if (l < loose->nr)
+ return do_for_each_ref_in_array(loose, l, base, fn, trim, flags, cb_data);
+ if (p < packed->nr)
+ return do_for_each_ref_in_array(packed, p, base, fn, trim, flags, cb_data);
return 0;
}