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

[PATCH v2 2/4] cmd_fetch_pack(): handle non-option arguments outside of the loop

From
mhagger@alum.mit.edu <mhagger@alum.mit.edu>
Date
May 21, 2012, 07:59 UTC
Message-ID
<1337587199-21099-3-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1337587199-21099-1-git-send-email-mhagger@alum.mit.edu>
From: Michael Haggerty <mhagger@alum.mit.edu>

This makes it more obvious that the code is always executed unless there is an error, and that the first initialization of nr_heads is unnecessary.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/fetch-pack.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 7e9d62f..dabf5e9 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -910,7 +910,6 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 
 	packet_trace_identity("fetch-pack");
 
-	nr_heads = 0;
 	heads = NULL;
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
@@ -972,14 +971,17 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 			}
 			usage(fetch_pack_usage);
 		}
-		dest = arg;
-		heads = (char **)(argv + i + 1);
-		nr_heads = argc - i - 1;
 		break;
 	}
-	if (!dest)
+
+	if (i < argc)
+		dest = argv[i++];
+	else
 		usage(fetch_pack_usage);
 
+	heads = (char **)(argv + i);
+	nr_heads = argc - i;
+
 	if (args.stdin_refs) {
 		/*
 		 * Copy refs from cmdline to new growable list, then
-- 
1.7.10
Previous: mhagger@alum.mit.eduNext: mhagger@alum.mit.edu
Message 3 of 5 in “Fix some constness errors in fetch-pack”
  1. 0/4 Fix some constness errors in fetch-packmhagger@alum.mit.edu, May 21, 2012
  2. 1/4 cmd_fetch_pack(): declare dest to be constmhagger@alum.mit.edu, May 21, 2012
  3. 2/4 cmd_fetch_pack(): handle non-option arguments outside of the loopmhagger@alum.mit.edu, May 21, 2012
  4. 3/4 cmd_fetch_pack(): combine the loop termination conditionsmhagger@alum.mit.edu, May 21, 2012
  5. 4/4 cmd_fetch_pack(): respect constness of argv parametermhagger@alum.mit.edu, May 21, 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.