git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 07/12] do_for_each_ref_in_array(): new function

From
mhagger@alum.mit.edu <mhagger@alum.mit.edu>
Date
Oct 28, 2011, 11:27 UTC
Message-ID
<1319801284-15625-8-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1319801284-15625-1-git-send-email-mhagger@alum.mit.edu>
From: Michael Haggerty <mhagger@alum.mit.edu>
Extract function do_for_each_ref_in_array() from do_for_each_ref().
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/refs.c b/refs.c
index 8043436..24a7a4d 100644
--- a/refs.c
+++ b/refs.c
@@ -700,21 +700,31 @@ fallback:
 	return -1;
 }
 
+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;
+	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;
+}
+
 static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn fn,
 			   int trim, int flags, void *cb_data)
 {
-	int retval = 0, i, p = 0, l = 0;
+	int retval = 0, p = 0, l = 0;
 	struct ref_cache *refs = get_ref_cache(submodule);
 	struct ref_array *packed = get_packed_refs(refs);
 	struct ref_array *loose = get_loose_refs(refs);
 
-	struct ref_array *extra = &extra_refs;
-
-	for (i = 0; i < extra->nr; i++) {
-		retval = do_one_ref(base, fn, trim, flags, cb_data, extra->refs[i]);
-		if (retval)
-			goto end_each;
-	}
+	retval = do_for_each_ref_in_array(&extra_refs, 0,
+					  base, fn, trim, flags, cb_data);
+	if (retval)
+		goto end_each;
 
 	while (p < packed->nr && l < loose->nr) {
 		struct ref_entry *entry;
@@ -734,14 +744,11 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
 	}
 
 	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)
-			goto end_each;
+		retval = do_for_each_ref_in_array(loose, l,
+						  base, fn, trim, flags, cb_data);
+	} else {
+		retval = do_for_each_ref_in_array(packed, p,
+						  base, fn, trim, flags, cb_data);
 	}
 
 end_each:
-- 
1.7.7
Previous: mhagger@alum.mit.eduNext: mhagger@alum.mit.edu
Message 8 of 13 in “Use refs API more consistently”
  1. 00/12 Use refs API more consistentlymhagger@alum.mit.edu, Oct 28, 2011
  2. 01/12 Rename another local variable name -> refnamemhagger@alum.mit.edu, Oct 28, 2011
  3. 02/12 repack_without_ref(): remove temporarymhagger@alum.mit.edu, Oct 28, 2011
  4. 03/12 parse_ref_line(): add a check that the refname is properly formattedmhagger@alum.mit.edu, Oct 28, 2011
  5. 04/12 create_ref_entry(): extract function from add_ref()mhagger@alum.mit.edu, Oct 28, 2011
  6. 05/12 add_ref(): take a (struct ref_entry *) parametermhagger@alum.mit.edu, Oct 28, 2011
  7. 06/12 do_for_each_ref(): correctly terminate while processesing extra_refsmhagger@alum.mit.edu, Oct 28, 2011
  8. 07/12 do_for_each_ref_in_array(): new functionmhagger@alum.mit.edu, Oct 28, 2011
  9. 08/12 do_for_each_ref_in_arrays(): new functionmhagger@alum.mit.edu, Oct 28, 2011
  10. 09/12 repack_without_ref(): reimplement using do_for_each_ref_in_array()mhagger@alum.mit.edu, Oct 28, 2011
  11. 10/12 names_conflict(): new function, extracted from is_refname_available()mhagger@alum.mit.edu, Oct 28, 2011
  12. 11/12 names_conflict(): simplify implementationmhagger@alum.mit.edu, Oct 28, 2011
  13. 12/12 is_refname_available(): reimplement using do_for_each_ref_in_array()mhagger@alum.mit.edu, Oct 28, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.