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

[PATCH] index-pack: correct --keep[=<msg>]

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2016, 19:14 UTC
Message-ID
<xmqq1t7r2x21.fsf@gitster.mtv.corp.google.com>

When 592ce208 (index-pack: use strip_suffix to avoid magic numbers, 2014-06-30) refactored the code to derive names of .idx and .keep files from the name of .pack file, a copy-and-paste typo crept in, mistakingly attempting to create and store the keep message file in the .idx file we just created, instead of .keep file.

As we create the .keep file with O_CREAT|O_EXCL, and we do so after we write the .idx file, we luckily do not clobber the .idx file, but because we deliberately ignored EEXIST when creating .keep file (which is justifiable because only the existence of .keep file matters), nobody noticed this mistake so far.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * In a later patch, I'll be adding another file to the family of
   .pack/.idx/.keep files, and the body of these if() statements
   would be made into a helper function when it happens.  This is to
   fix it directly on top of the problematic commit without such a
   helper, the result of which could be merged to 2.1.x and later
   maintenance series.
 builtin/index-pack.c   | 2 +-
 t/t5300-pack-object.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d4b77fd..3814731 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1617,7 +1617,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 			die(_("packfile name '%s' does not end with '.pack'"),
 			    pack_name);
 		strbuf_add(&keep_name_buf, pack_name, len);
-		strbuf_addstr(&keep_name_buf, ".idx");
+		strbuf_addstr(&keep_name_buf, ".keep");
 		keep_name = keep_name_buf.buf;
 	}
 	if (verify) {
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index 20c1961..0e3cadf 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -284,6 +284,12 @@ test_expect_success \
      git index-pack test-3.pack &&
      cmp test-3.idx test-3-${packname_3}.idx &&
 
+     cat test-1-${packname_1}.pack >test-4.pack &&
+     rm -f test-4.keep &&
+     git index-pack --keep=why test-4.pack &&
+     cmp test-1-${packname_1}.idx test-4.idx &&
+     test -f test-4.keep &&
+
      :'
 
 test_expect_success 'unpacking with --strict' '
-- 
v2.0.1-6-g592ce20
Next: Jeff King
Message 1 of 9 in “index-pack: correct --keep[=<msg>]”
  1. index-pack: correct --keep[=<msg>]Junio C Hamano, Mar 3, 2016
  2. Jeff KingMar 3, 2016
  3. index-pack: add a helper function to derive .idx/.keep filenameJunio C Hamano, Mar 3, 2016
  4. Jeff KingMar 3, 2016
  5. index-pack: --clone-bundle optionJunio C Hamano, Mar 3, 2016
  6. Junio C HamanoMar 3, 2016
  7. Jeff KingMar 4, 2016
  8. Jeff KingMar 4, 2016
  9. Eric SunshineMar 3, 2016

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.