Skip to content

Commit 84d5449

Browse files
ttaylorrgitster
authored andcommitted
builtin/index-pack.c: allow stripping arbitrary extensions
To derive the filename for a .idx file, 'git index-pack' uses derive_filename() to strip the '.pack' suffix and add the new suffix. Prepare for stripping off suffixes other than '.pack' by making the suffix to strip a parameter of derive_filename(). In order to make this consistent with the "suffix" parameter which does not begin with a ".", an additional check in derive_filename. Suggested-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ef50d9 commit 84d5449

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/index-pack.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,15 +1436,15 @@ static void fix_unresolved_deltas(struct hashfile *f)
14361436
free(sorted_by_pos);
14371437
}
14381438

1439-
static const char *derive_filename(const char *pack_name, const char *suffix,
1440-
struct strbuf *buf)
1439+
static const char *derive_filename(const char *pack_name, const char *strip,
1440+
const char *suffix, struct strbuf *buf)
14411441
{
14421442
size_t len;
1443-
if (!strip_suffix(pack_name, ".pack", &len))
1444-
die(_("packfile name '%s' does not end with '.pack'"),
1445-
pack_name);
1443+
if (!strip_suffix(pack_name, strip, &len) || !len ||
1444+
pack_name[len - 1] != '.')
1445+
die(_("packfile name '%s' does not end with '.%s'"),
1446+
pack_name, strip);
14461447
strbuf_add(buf, pack_name, len);
1447-
strbuf_addch(buf, '.');
14481448
strbuf_addstr(buf, suffix);
14491449
return buf->buf;
14501450
}
@@ -1459,7 +1459,7 @@ static void write_special_file(const char *suffix, const char *msg,
14591459
int msg_len = strlen(msg);
14601460

14611461
if (pack_name)
1462-
filename = derive_filename(pack_name, suffix, &name_buf);
1462+
filename = derive_filename(pack_name, "pack", suffix, &name_buf);
14631463
else
14641464
filename = odb_pack_name(&name_buf, hash, suffix);
14651465

@@ -1824,7 +1824,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18241824
if (from_stdin && hash_algo)
18251825
die(_("--object-format cannot be used with --stdin"));
18261826
if (!index_name && pack_name)
1827-
index_name = derive_filename(pack_name, "idx", &index_name_buf);
1827+
index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf);
18281828

18291829
if (verify) {
18301830
if (!index_name)

0 commit comments

Comments
 (0)