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

[PATCH 5/9] fetch: Move loop checking which refs we have already

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Mar 16, 2010, 17:49 UTC
Message-ID
<dbb0f92deca35a16c898af697dc41affc377ae0b.1268913163.git.agruen@suse.de>
In-Reply-To
<672662f82e19ab268bd83f2b48980f43f126c089.1268913163.git.agruen@suse.de>
This loop fits better into get_ref_map(); move it there.
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
 builtin/fetch.c |   48 ++++++++++++++++++++++++------------------------
 1 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index fc6efc7..6dc75d4 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -115,6 +115,15 @@ static void add_merge_config(struct ref **head,
 	}
 }
 
+static int add_existing(const char *refname, const unsigned char *sha1,
+			int flag, void *cbdata)
+{
+	struct string_list *list = (struct string_list *)cbdata;
+	struct string_list_item *item = string_list_insert(refname, list);
+	item->util = (void *)sha1;
+	return 0;
+}
+
 static void find_non_local_tags(struct transport *transport,
 			struct ref **head,
 			struct ref ***tail);
@@ -123,6 +132,7 @@ static struct ref *get_ref_map(struct transport *transport,
 			       struct refspec *refs, int ref_count, int tags,
 			       int *autotags)
 {
+	struct string_list existing_refs = { NULL, 0, 0, 0 };
 	int i;
 	struct ref *rm;
 	struct ref *ref_map = NULL;
@@ -176,6 +186,20 @@ static struct ref *get_ref_map(struct transport *transport,
 		find_non_local_tags(transport, &ref_map, &tail);
 	ref_remove_duplicates(ref_map);
 
+	for_each_ref(add_existing, &existing_refs);
+	for (rm = ref_map; rm; rm = rm->next) {
+		if (rm->peer_ref) {
+			struct string_list_item *peer_item;
+
+			peer_item = string_list_lookup(rm->peer_ref->name,
+						       &existing_refs);
+			if (peer_item)
+				hashcpy(rm->peer_ref->old_sha1,
+					peer_item->util);
+		}
+	}
+	string_list_clear(&existing_refs, 0);
+
 	return ref_map;
 }
 
@@ -554,15 +578,6 @@ static int prune_refs(struct transport *transport, struct ref *ref_map)
 	return result;
 }
 
-static int add_existing(const char *refname, const unsigned char *sha1,
-			int flag, void *cbdata)
-{
-	struct string_list *list = (struct string_list *)cbdata;
-	struct string_list_item *item = string_list_insert(refname, list);
-	item->util = (void *)sha1;
-	return 0;
-}
-
 static int will_fetch(struct ref **head, const unsigned char *sha1)
 {
 	struct ref *rm = *head;
@@ -696,14 +711,9 @@ static int truncate_fetch_head(void)
 static int do_fetch(struct transport *transport,
 		    struct refspec *refs, int ref_count)
 {
-	struct string_list existing_refs = { NULL, 0, 0, 0 };
-	struct string_list_item *peer_item = NULL;
 	struct ref *ref_map;
-	struct ref *rm;
 	int autotags = (transport->remote->fetch_tags == 1);
 
-	for_each_ref(add_existing, &existing_refs);
-
 	if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
 		tags = TAGS_SET;
 	if (transport->remote->fetch_tags == -1)
@@ -723,16 +733,6 @@ static int do_fetch(struct transport *transport,
 	if (!update_head_ok)
 		check_not_current_branch(ref_map);
 
-	for (rm = ref_map; rm; rm = rm->next) {
-		if (rm->peer_ref) {
-			peer_item = string_list_lookup(rm->peer_ref->name,
-						       &existing_refs);
-			if (peer_item)
-				hashcpy(rm->peer_ref->old_sha1,
-					peer_item->util);
-		}
-	}
-
 	if (tags == TAGS_DEFAULT && autotags)
 		transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
 	if (fetch_refs(transport, ref_map)) {
-- 
1.7.0.2.273.gc2413
Previous: Andreas GruenbacherNext: Andreas Gruenbacher
Message 6 of 14 in “Multiple remotes without conflicts”
  1. 0/9 Multiple remotes without conflictsAndreas Gruenbacher, Mar 18, 2010
  2. 1/9 fetch: Check for a "^{}" suffix with suffixcmp()Andreas Gruenbacher, Mar 13, 2010
  3. 2/9 fetch: Properly initialize refspec on stackAndreas Gruenbacher, Mar 12, 2010
  4. 3/9 fetch: Fix minor memory leakAndreas Gruenbacher, Mar 15, 2010
  5. 4/9 fetch: Move deepening fetch check into builtin/fetch.cAndreas Gruenbacher, Mar 16, 2010
  6. 5/9 fetch: Move loop checking which refs we have alreadyAndreas Gruenbacher, Mar 16, 2010
  7. 6/9 fetch: Check if all objects exist after fetchingAndreas Gruenbacher, Mar 16, 2010
  8. 7/9 fetch: Use the same ref map for all branches and tagsAndreas Gruenbacher, Mar 17, 2010
  9. 8/9 fetch: Don't fetch tags twiceAndreas Gruenbacher, Mar 17, 2010
  10. 9/9 fetch: Make automatic tag following work with arbitrary refspecsAndreas Gruenbacher, Mar 17, 2010
  11. Shawn O. PearceMar 18, 2010
  12. Andreas GruenbacherMar 18, 2010
  13. Shawn O. PearceMar 18, 2010
  14. Andreas GruenbacherMar 18, 2010

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.