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

[PATCH v2 5/6] index-pack: avoid collision test when verifying in-repo pack

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 23, 2012, 14:09 UTC
Message-ID
<1337782191-10091-5-git-send-email-pclouds@gmail.com>
In-Reply-To
<1337782191-10091-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 not part of the original goal, but while i'm touching this code..
 builtin/index-pack.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 05b1d35..641edb5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -78,6 +78,7 @@ static int nr_threads;
 static int from_stdin;
 static int strict;
 static int verbose;
+static int verify;
 
 static struct progress *progress;
 
@@ -688,11 +689,13 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 	int collision_test_needed = 1;
 	enum object_type has_type;
 	unsigned long has_size;
+	struct object_info oi;
 
 	assert(data || obj_entry);
 
+	oi.sizep = &has_size;
 	read_lock();
-	has_type = sha1_object_info(sha1, &has_size);
+	has_type = sha1_object_info_extended(sha1, &oi);
 	read_unlock();
 
 	if (has_type < 0)
@@ -703,6 +706,30 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
 			collision_test_needed = 0;
 		read_unlock();
 	}
+	read_lock();
+	if (collision_test_needed && oi.whence == OI_PACKED &&
+	    verify && !from_stdin &&
+	    is_pack_valid(oi.u.packed.pack)) {
+		static int good_stats = -1;
+		static struct stat st1, st2;
+
+		good_stats = good_stats == -1 &&
+			fstat_is_reliable() &&
+			!fstat(pack_fd, &st2) &&
+			!stat(oi.u.packed.pack->pack_name, &st1);
+		read_unlock();
+
+		/*
+		 * Windows builds do not support inode info. Inode
+		 * comparison would be wrong. Luckily in all Windows
+		 * builds set UNRELIABLE_FSTAT and good_stats would
+		 * always be 0, so we never get to inode comparison
+		 * test.
+		 */
+		if (good_stats && st1.st_ino == st2.st_ino)
+			collision_test_needed = 0;
+	} else
+		read_unlock();
 	if (collision_test_needed) {
 		void *has_data;
 		if (has_type != type || has_size != size)
@@ -1459,7 +1486,7 @@ static void show_pack_info(int stat_only)
 
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
 {
-	int i, fix_thin_pack = 0, verify = 0, stat_only = 0, stat = 0;
+	int i, fix_thin_pack = 0, stat_only = 0, stat = 0;
 	const char *curr_pack, *curr_index;
 	const char *index_name = NULL, *pack_name = NULL;
 	const char *keep_name = NULL, *keep_msg = NULL;
-- 
1.7.10.2.549.g9354186
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 16 in “index-pack: hash non-delta objects while reading from stream”
  1. 1/2 index-pack: hash non-delta objects while reading from streamNguyễn Thái Ngọc Duy, May 16, 2012
  2. 2/2 index-pack: use streaming interface on large blobs (most of the time)Nguyễn Thái Ngọc Duy, May 16, 2012
  3. Junio C HamanoMay 18, 2012
  4. Nguyen Thai Ngoc DuyMay 19, 2012
  5. Junio C HamanoMay 18, 2012
  6. 1/6 index-pack: hash non-delta objects while reading from streamNguyễn Thái Ngọc Duy, May 23, 2012
  7. 2/6 index-pack: use streaming interface on large blobs (most of the time)Nguyễn Thái Ngọc Duy, May 23, 2012
  8. 3/6 index-pack: factor out unpack core from get_data_from_packNguyễn Thái Ngọc Duy, May 23, 2012
  9. 4/6 index-pack: use streaming interface for collision test on large blobsNguyễn Thái Ngọc Duy, May 23, 2012
  10. Junio C HamanoMay 23, 2012
  11. 4/6 index-pack: use streaming interface for collision test on large blobsNguyễn Thái Ngọc Duy, May 24, 2012
  12. 5/6 index-pack: avoid collision test when verifying in-repo packNguyễn Thái Ngọc Duy, May 23, 2012
  13. 6/6 sha1_loose_object_info: do not complain out loud on non-existent objectsNguyễn Thái Ngọc Duy, May 23, 2012
  14. Nguyen Thai Ngoc DuyMay 23, 2012
  15. Junio C HamanoMay 23, 2012
  16. Nguyen Thai Ngoc DuyMay 24, 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.