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

[PATCH 4/9] fetch: Move deepening fetch check into builtin/fetch.c

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Mar 16, 2010, 15:45 UTC
Message-ID
<672662f82e19ab268bd83f2b48980f43f126c089.1268913163.git.agruen@suse.de>
In-Reply-To
<b7762c1e05412618584e38b868bcc870676f6e62.1268913163.git.agruen@suse.de>

Check if we are doing a deepening fetch in fetch instead of guessing in transport_fetch_refs().

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
 builtin/fetch.c |   34 ++++++++++++++++++++++++++++++++--
 cache.h         |    3 ++-
 transport.c     |   38 +++++++++++++-------------------------
 3 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 957be9f..fc6efc7 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -489,11 +489,41 @@ static int quickfetch(struct ref *ref_map)
 	return finish_command(&revlist) || err;
 }
 
+static void check_existing_refs(struct ref *ref_map) {
+	struct ref *ref;
+	int done = 1;
+
+	if (!depth) {
+		for (ref = ref_map; ref; ref = ref->next) {
+			if (ref->peer_ref &&
+			    !is_null_sha1(ref->old_sha1) &&
+			    !hashcmp(ref->peer_ref->old_sha1, ref->old_sha1))
+				ref->dont_fetch = 1;
+			else
+				done = 0;
+		}
+	}
+	if (done) {
+		/*
+		 * When deepening of a shallow repository is requested, local
+		 * and remote refs are likely to still be equal.  In addition,
+		 * we get here if all refs are up to date but quickfetch() did
+		 * not succeed.  In both cases, fetch all refs.
+		 */
+		for (ref = ref_map; ref; ref = ref->next)
+			ref->dont_fetch = 0;
+	}
+}
+
 static int fetch_refs(struct transport *transport, struct ref *ref_map)
 {
-	int ret = quickfetch(ref_map);
-	if (ret)
+	int ret;
+
+	ret = quickfetch(ref_map);
+	if (ret) {
+		check_existing_refs(ref_map);
 		ret = transport_fetch_refs(transport, ref_map);
+	}
 	if (!ret)
 		ret |= store_updated_refs(transport->url,
 				transport->remote->name,
diff --git a/cache.h b/cache.h
index 89f6a40..abfc682 100644
--- a/cache.h
+++ b/cache.h
@@ -869,7 +869,8 @@ struct ref {
 	unsigned int force:1,
 		merge:1,
 		nonfastforward:1,
-		deletion:1;
+		deletion:1,
+		dont_fetch:1;
 	enum {
 		REF_STATUS_NONE = 0,
 		REF_STATUS_OK,
diff --git a/transport.c b/transport.c
index 8ce3936..d1288af 100644
--- a/transport.c
+++ b/transport.c
@@ -1127,36 +1127,24 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
 
 int transport_fetch_refs(struct transport *transport, struct ref *refs)
 {
-	int rc;
-	int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
-	struct ref **heads = NULL;
+	int rc = 0;
+	int nr_heads;
+	struct ref **heads;
 	struct ref *rm;
 
-	for (rm = refs; rm; rm = rm->next) {
-		nr_refs++;
-		if (rm->peer_ref &&
-		    !is_null_sha1(rm->old_sha1) &&
-		    !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
+	for (nr_heads = 0, rm = refs; rm; rm = rm->next) {
+		if (rm->dont_fetch)
 			continue;
-		ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
-		heads[nr_heads++] = rm;
+		nr_heads++;
 	}
-
-	if (!nr_heads) {
-		/*
-		 * When deepening of a shallow repository is requested,
-		 * then local and remote refs are likely to still be equal.
-		 * Just feed them all to the fetch method in that case.
-		 * This condition shouldn't be met in a non-deepening fetch
-		 * (see builtin-fetch.c:quickfetch()).
-		 */
-		heads = xmalloc(nr_refs * sizeof(*heads));
-		for (rm = refs; rm; rm = rm->next)
-			heads[nr_heads++] = rm;
+	heads = xmalloc(nr_heads * sizeof(*heads));
+	for (nr_heads = 0, rm = refs; rm; rm = rm->next) {
+		if (rm->dont_fetch)
+			continue;
+		heads[nr_heads++] = rm;
 	}
-
-	rc = transport->fetch(transport, nr_heads, heads);
-
+	if (nr_heads)
+		rc = transport->fetch(transport, nr_heads, heads);
 	free(heads);
 	return rc;
 }
-- 
1.7.0.2.273.gc2413
Previous: Andreas GruenbacherNext: Andreas Gruenbacher
Message 5 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.