Git fork

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 <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>

authored by

Jeff King and committed by
Taylor Blau
4390fea9 c2dc4c9f

+4 -14
+4 -1
builtin/pack-redundant.c
··· 13 14 #include "packfile.h" 15 #include "object-store-ll.h" 16 17 #define BLKSIZE 512 18 ··· 591 int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) { 592 int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl; 593 struct llist *ignore; 594 char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */ 595 596 if (argc == 2 && !strcmp(argv[1], "-h")) ··· 688 pl = red = pack_list_difference(local_packs, min); 689 while (pl) { 690 printf("%s\n%s\n", 691 - sha1_pack_index_name(pl->pack->hash), 692 pl->pack->pack_name); 693 pl = pl->next; 694 } ··· 699 pack_list_free(red); 700 pack_list_free(min); 701 llist_free(ignore); 702 return 0; 703 }
··· 13 14 #include "packfile.h" 15 #include "object-store-ll.h" 16 + #include "strbuf.h" 17 18 #define BLKSIZE 512 19 ··· 592 int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) { 593 int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl; 594 struct llist *ignore; 595 + struct strbuf idx_name = STRBUF_INIT; 596 char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */ 597 598 if (argc == 2 && !strcmp(argv[1], "-h")) ··· 690 pl = red = pack_list_difference(local_packs, min); 691 while (pl) { 692 printf("%s\n%s\n", 693 + odb_pack_name(&idx_name, pl->pack->hash, "idx"), 694 pl->pack->pack_name); 695 pl = pl->next; 696 } ··· 701 pack_list_free(red); 702 pack_list_free(min); 703 llist_free(ignore); 704 + strbuf_release(&idx_name); 705 return 0; 706 }
-6
packfile.c
··· 35 return buf->buf; 36 } 37 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 - 44 static unsigned int pack_used_ctr; 45 static unsigned int pack_mmap_calls; 46 static unsigned int peak_pack_open_windows;
··· 35 return buf->buf; 36 } 37 38 static unsigned int pack_used_ctr; 39 static unsigned int pack_mmap_calls; 40 static unsigned int peak_pack_open_windows;
-7
packfile.h
··· 32 char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); 33 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 - 41 - /* 42 * Return the basename of the packfile, omitting any containing directory 43 * (e.g., "pack-1234abcd[...].pack"). 44 */
··· 32 char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); 33 34 /* 35 * Return the basename of the packfile, omitting any containing directory 36 * (e.g., "pack-1234abcd[...].pack"). 37 */