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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Andreas Gruenbacher <agruen@xxxxxxx>
---
 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


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]