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

[PATCH] index-pack: add a helper function to derive .idx/.keep filename

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2016, 21:37 UTC
Message-ID
<xmqqsi071bw1.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqq1t7r2x21.fsf@gitster.mtv.corp.google.com>

These are automatically named by replacing .pack suffix in the name of the packfile. Add a small helper to do so, as I'll be adding another one soonish.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/index-pack.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 285424f..a5588a2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1598,6 +1598,18 @@ static void show_pack_info(int stat_only)
 	}
 }
 
+static const char *derive_filename(const char *pack_name, const char *suffix,
+				   struct strbuf *buf)
+{
+	size_t len;
+	if (!strip_suffix(pack_name, ".pack", &len))
+		die(_("packfile name '%s' does not end with '.pack'"),
+		    pack_name);
+	strbuf_add(buf, pack_name, len);
+	strbuf_addstr(buf, suffix);
+	return buf->buf;
+}
+
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
 {
 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
@@ -1706,24 +1718,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 		usage(index_pack_usage);
 	if (fix_thin_pack && !from_stdin)
 		die(_("--fix-thin cannot be used without --stdin"));
-	if (!index_name && pack_name) {
-		size_t len;
-		if (!strip_suffix(pack_name, ".pack", &len))
-			die(_("packfile name '%s' does not end with '.pack'"),
-			    pack_name);
-		strbuf_add(&index_name_buf, pack_name, len);
-		strbuf_addstr(&index_name_buf, ".idx");
-		index_name = index_name_buf.buf;
-	}
-	if (keep_msg && !keep_name && pack_name) {
-		size_t len;
-		if (!strip_suffix(pack_name, ".pack", &len))
-			die(_("packfile name '%s' does not end with '.pack'"),
-			    pack_name);
-		strbuf_add(&keep_name_buf, pack_name, len);
-		strbuf_addstr(&keep_name_buf, ".keep");
-		keep_name = keep_name_buf.buf;
-	}
+	if (!index_name && pack_name)
+		index_name = derive_filename(pack_name, ".idx", &index_name_buf);
+	if (keep_msg && !keep_name && pack_name)
+		keep_name = derive_filename(pack_name, ".keep", &keep_name_buf);
+
 	if (verify) {
 		if (!index_name)
 			die(_("--verify with no packfile name given"));
-- 
2.8.0-rc0-116-g5beb0d5
Previous: Jeff KingNext: Jeff King
Message 3 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.