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

[PATCH v3 2/4] sha1_file: reorder code in prepare_packed_git_one()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 12, 2013, 09:27 UTC
Message-ID
<1360661277-17273-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1360661277-17273-1-git-send-email-pclouds@gmail.com>
The current loop does
	while (...) {
		if (!not .idx file)
			continue;
		process .idx file;
	}
and is reordered to
	while (...) {
		if (!.idx file) {
			process .idx file;
		}
	}
This makes it easier to add new extension file processing.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1_file.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 40b2329..8d7da1d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1024,27 +1024,28 @@ static void prepare_packed_git_one(char *objdir, int local)
 		int namelen = strlen(de->d_name);
 		struct packed_git *p;
 
-		if (!has_extension(de->d_name, ".idx"))
-			continue;
-
 		if (len + namelen + 1 > sizeof(path))
 			continue;
 
-		/* Don't reopen a pack we already have. */
 		strcpy(path + len, de->d_name);
-		for (p = packed_git; p; p = p->next) {
-			if (!memcmp(path, p->pack_name, len + namelen - 4))
-				break;
+
+		if (has_extension(de->d_name, ".idx")) {
+			/* Don't reopen a pack we already have. */
+			for (p = packed_git; p; p = p->next) {
+				if (!memcmp(path, p->pack_name, len + namelen - 4))
+					break;
+			}
+			if (p)
+				continue;
+			/*
+			 * See if it really is a valid .idx file with
+			 * corresponding .pack file that we can map.
+			 */
+			p = add_packed_git(path, len + namelen, local);
+			if (!p)
+				continue;
+			install_packed_git(p);
 		}
-		if (p)
-			continue;
-		/* See if it really is a valid .idx file with corresponding
-		 * .pack file that we can map.
-		 */
-		p = add_packed_git(path, len + namelen, local);
-		if (!p)
-			continue;
-		install_packed_git(p);
 	}
 	closedir(dir);
 }
-- 
1.8.1.2.536.gf441e6d
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 17 in “count-objects improvements”
  1. 0/4 count-objects improvementsNguyễn Thái Ngọc Duy, Feb 12, 2013
  2. 1/4 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 12, 2013
  3. 2/4 sha1_file: reorder code in prepare_packed_git_one()Nguyễn Thái Ngọc Duy, Feb 12, 2013
  4. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 12, 2013
  5. Junio C HamanoFeb 12, 2013
  6. 0/4 count-objects improvementsNguyễn Thái Ngọc Duy, Feb 13, 2013
  7. 1/4 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 13, 2013
  8. 2/4 sha1_file: reorder code in prepare_packed_git_one()Nguyễn Thái Ngọc Duy, Feb 13, 2013
  9. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 13, 2013
  10. Junio C HamanoFeb 13, 2013
  11. Junio C HamanoFeb 13, 2013
  12. Duy NguyenFeb 14, 2013
  13. Junio C HamanoFeb 14, 2013
  14. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 15, 2013
  15. Junio C HamanoFeb 15, 2013
  16. 4/4 count-objects: report how much disk space taken by garbage filesNguyễn Thái Ngọc Duy, Feb 13, 2013
  17. 4/4 count-objects: report how much disk space taken by garbage filesNguyễn Thái Ngọc Duy, Feb 12, 2013

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.