Skip to content

Commit 4390fea

Browse files
peffttaylorr
authored andcommitted
packfile: drop sha1_pack_index_name()
Like sha1_pack_name() that we dropped in the previous commit, this function uses an error-prone static strbuf and the somewhat misleading name "sha1". The only caller left is in pack-redundant.c. While this command is marked for potential removal in our BreakingChanges document, we still have it for now. But it's simple enough to convert it to use its own strbuf with the underlying odb_pack_name() function, letting us drop the otherwise obsolete function. Note that odb_pack_name() does its own strbuf_reset(), so it's safe to use directly within a loop like this. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent c2dc4c9 commit 4390fea

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

builtin/pack-redundant.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "packfile.h"
1515
#include "object-store-ll.h"
16+
#include "strbuf.h"
1617

1718
#define BLKSIZE 512
1819

@@ -591,6 +592,7 @@ static void load_all(void)
591592
int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
592593
int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
593594
struct llist *ignore;
595+
struct strbuf idx_name = STRBUF_INIT;
594596
char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
595597

596598
if (argc == 2 && !strcmp(argv[1], "-h"))
@@ -688,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
688690
pl = red = pack_list_difference(local_packs, min);
689691
while (pl) {
690692
printf("%s\n%s\n",
691-
sha1_pack_index_name(pl->pack->hash),
693+
odb_pack_name(&idx_name, pl->pack->hash, "idx"),
692694
pl->pack->pack_name);
693695
pl = pl->next;
694696
}
@@ -699,5 +701,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
699701
pack_list_free(red);
700702
pack_list_free(min);
701703
llist_free(ignore);
704+
strbuf_release(&idx_name);
702705
return 0;
703706
}

packfile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ char *odb_pack_name(struct strbuf *buf,
3535
return buf->buf;
3636
}
3737

38-
char *sha1_pack_index_name(const unsigned char *sha1)
39-
{
40-
static struct strbuf buf = STRBUF_INIT;
41-
return odb_pack_name(&buf, sha1, "idx");
42-
}
43-
4438
static unsigned int pack_used_ctr;
4539
static unsigned int pack_mmap_calls;
4640
static unsigned int peak_pack_open_windows;

packfile.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ struct pack_entry {
3131
*/
3232
char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
3333

34-
/*
35-
* Return the name of the (local) pack index file with the specified
36-
* sha1 in its name. The return value is a pointer to memory that is
37-
* overwritten each time this function is called.
38-
*/
39-
char *sha1_pack_index_name(const unsigned char *sha1);
40-
4134
/*
4235
* Return the basename of the packfile, omitting any containing directory
4336
* (e.g., "pack-1234abcd[...].pack").

0 commit comments

Comments
 (0)