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

[PATCH 5/9] git-verify-pack: get rid of while loop

From
Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Aug 10, 2006, 15:02 UTC
Message-ID
<11552221581038-git-send-email-rene.scharfe@lsrfire.ath.cx>
In-Reply-To
<11552221582769-git-send-email-rene.scharfe@lsrfire.ath.cx>

Get rid of that while loop which was apparently used as a way to avoid goto's (why?). It's easy now because there is only one break left at the end of it. Also make the comment clearer.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 verify-pack.c |   32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
diff a/verify-pack.c b/verify-pack.c
--- a/verify-pack.c
+++ b/verify-pack.c
@@ -11,23 +11,23 @@
 	if (len >= PATH_MAX)
 		return error("name too long: %s", path);
 	
-	while (1) {
-		/* Should name foo.idx, but foo.pack may be named;
-		 * convert it to foo.idx
-		 */
-		if (has_extension(arg, len, ".pack")) {
-			strcpy(arg + len - 5, ".idx");
-			len--;
-		} else if (!has_extension(arg, len, ".idx")) {
-			if (len + 4 >= PATH_MAX)
-				return error("name too long: %s.idx", arg);
-			strcpy(arg + len, ".idx");
-			len += 4;
-		}
-		if ((g = add_packed_git(arg, len, 1)))
-			break;
-		return error("packfile %s not found.", arg);
+	/*
+	 * In addition to "foo.idx" we accept "foo.pack" and "foo";
+	 * normalize these forms to "foo.idx" for add_packed_git().
+	 */
+	if (has_extension(arg, len, ".pack")) {
+		strcpy(arg + len - 5, ".idx");
+		len--;
+	} else if (!has_extension(arg, len, ".idx")) {
+		if (len + 4 >= PATH_MAX)
+			return error("name too long: %s.idx", arg);
+		strcpy(arg + len, ".idx");
+		len += 4;
 	}
+
+	if (!(g = add_packed_git(arg, len, 1)))
+		return error("packfile %s not found.", arg);
+
 	return verify_pack(g, verbose);
 }
 
Previous: Rene ScharfeNext: Rene Scharfe
Message 11 of 18 in “git-verify-pack: clean up and make builtin”
  1. 0/9 git-verify-pack: clean up and make builtinRene Scharfe, Aug 10, 2006
  2. 1/9 Add has_extension()Rene Scharfe, Aug 10, 2006
  3. Johannes SchindelinAug 10, 2006
  4. Rene ScharfeAug 10, 2006
  5. Fredrik KuivinenAug 10, 2006
  6. Rene ScharfeAug 10, 2006
  7. Fredrik KuivinenAug 10, 2006
  8. 2/9 git-verify-pack: show usage when no pack was specifiedRene Scharfe, Aug 10, 2006
  9. 3/9 git-verify-pack: more careful path handlingRene Scharfe, Aug 10, 2006
  10. 4/9 git-verify-pack: insist on .idx extensionRene Scharfe, Aug 10, 2006
  11. 5/9 git-verify-pack: get rid of while loopRene Scharfe, Aug 10, 2006
  12. 6/9 git-verify-pack: free pack after use and a cleanupRene Scharfe, Aug 10, 2006
  13. 7/9 git-verify-pack: buffer overrun paranoiaRene Scharfe, Aug 10, 2006
  14. 8/9 git-verify-pack: no need to count errorsRene Scharfe, Aug 10, 2006
  15. Johannes SchindelinAug 10, 2006
  16. Rene ScharfeAug 10, 2006
  17. 9/9 git-verify-pack: make builtinRene Scharfe, Aug 10, 2006
  18. Johannes SchindelinAug 10, 2006

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.