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>
Michael Haggerty committed
Apr 10, 2012 at 07:30 UTC
c36b5bc2e44c7e53a4c078056f1c40c155d8a87e
1 file changed
+23
-10
refs.c
+23
-10
@@ -268,6 +268,25 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
268
return retval;
269
}
270
271
+/*
272
+ * Call fn for each reference in array that has index in the range
273
+ * offset <= index < array->nr. This function does not sort the
274
+ * array; sorting should be done by the caller.
275
+ */
276
+static int do_for_each_ref_in_array(struct ref_array *array, int offset,
277
+ const char *base,
278
+ each_ref_fn fn, int trim, int flags, void *cb_data)
279
+{
280
+ int i;
281
+ assert(array->sorted == array->nr);
282
+ for (i = offset; i < array->nr; i++) {
283
+ int retval = do_one_ref(base, fn, trim, flags, cb_data, array->refs[i]);
284
+ if (retval)
285
+ return retval;
286
+ }
287
+ return 0;
288
+}
289
+
290
/*
291
* Return true iff a reference named refname could be created without
292
* conflicting with the name of an existing reference. If oldrefname
@@ -878,16 +897,10 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
897
return retval;
898
}
899
881
- if (l < loose->nr) {
882
- p = l;
883
- packed = loose;
884
- }
885
-
886
- for (; p < packed->nr; p++) {
887
- retval = do_one_ref(base, fn, trim, flags, cb_data, packed->refs[p]);
888
- if (retval)
889
- return retval;
890
- }
900
+ if (l < loose->nr)
901
+ return do_for_each_ref_in_array(loose, l, base, fn, trim, flags, cb_data);
902
+ if (p < packed->nr)
903
+ return do_for_each_ref_in_array(packed, p, base, fn, trim, flags, cb_data);
904
905
return 0;
906
}