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

[PATCH 2/7] clone.c: move more code into the "if (refs)" conditional

From
mhagger@alum.mit.edu <mhagger@alum.mit.edu>
Date
Feb 11, 2012, 06:20 UTC
Message-ID
<1328941261-29746-3-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1328941261-29746-1-git-send-email-mhagger@alum.mit.edu>
From: Michael Haggerty <mhagger@alum.mit.edu>

The bahavior of a bunch of code before the "if (refs)" statement also depends on whether refs is set, so make the logic clearer by shifting this code into the if statement.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/clone.c |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index c62d4b5..279fdf0 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -813,28 +813,28 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 
 	refs = transport_get_remote_refs(transport);
-	mapped_refs = refs ? wanted_peer_refs(refs, refspec) : NULL;
 
-	/*
-	 * transport_get_remote_refs() may return refs with null sha-1
-	 * in mapped_refs (see struct transport->get_refs_list
-	 * comment). In that case we need fetch it early because
-	 * remote_head code below relies on it.
-	 *
-	 * for normal clones, transport_get_remote_refs() should
-	 * return reliable ref set, we can delay cloning until after
-	 * remote HEAD check.
-	 */
-	for (ref = refs; ref; ref = ref->next)
-		if (is_null_sha1(ref->old_sha1)) {
-			complete_refs_before_fetch = 0;
-			break;
-		}
+	if (refs) {
+		mapped_refs = wanted_peer_refs(refs, refspec);
+		/*
+		 * transport_get_remote_refs() may return refs with null sha-1
+		 * in mapped_refs (see struct transport->get_refs_list
+		 * comment). In that case we need fetch it early because
+		 * remote_head code below relies on it.
+		 *
+		 * for normal clones, transport_get_remote_refs() should
+		 * return reliable ref set, we can delay cloning until after
+		 * remote HEAD check.
+		 */
+		for (ref = refs; ref; ref = ref->next)
+			if (is_null_sha1(ref->old_sha1)) {
+				complete_refs_before_fetch = 0;
+				break;
+			}
 
-	if (!is_local && !complete_refs_before_fetch && refs)
-		transport_fetch_refs(transport, mapped_refs);
+		if (!is_local && !complete_refs_before_fetch)
+			transport_fetch_refs(transport, mapped_refs);
 
-	if (refs) {
 		remote_head = find_ref_by_name(refs, "HEAD");
 		remote_head_points_at =
 			guess_remote_head(remote_head, mapped_refs, 0);
@@ -852,6 +852,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	}
 	else {
 		warning(_("You appear to have cloned an empty repository."));
+		mapped_refs = NULL;
 		our_head_points_at = NULL;
 		remote_head_points_at = NULL;
 		remote_head = NULL;
-- 
1.7.9
Previous: Michael HaggertyNext: Junio C Hamano
Message 5 of 14 in “Make alternates affect fetch behavior”
  1. 0/7 Make alternates affect fetch behaviormhagger@alum.mit.edu, Feb 11, 2012
  2. 1/7 t5700: document a failure of alternates to affect fetchmhagger@alum.mit.edu, Feb 11, 2012
  3. Junio C HamanoFeb 13, 2012
  4. Michael HaggertyFeb 13, 2012
  5. 2/7 clone.c: move more code into the "if (refs)" conditionalmhagger@alum.mit.edu, Feb 11, 2012
  6. Junio C HamanoFeb 13, 2012
  7. 3/7 fetch-pack.c: rename some parameters from "path" to "refname"mhagger@alum.mit.edu, Feb 11, 2012
  8. Junio C HamanoFeb 13, 2012
  9. 4/7 fetch-pack.c: inline insert_alternate_refs()mhagger@alum.mit.edu, Feb 11, 2012
  10. 5/7 everything_local(): mark alternate refs as completemhagger@alum.mit.edu, Feb 11, 2012
  11. 6/7 clone: do not add alternate references to extra_refsmhagger@alum.mit.edu, Feb 11, 2012
  12. Junio C HamanoFeb 13, 2012
  13. 7/7 refs: remove the extra_refs APImhagger@alum.mit.edu, Feb 11, 2012
  14. Jeff KingFeb 14, 2012

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.