]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: drop sha1_pack_index_name()
authorJeff King <peff@peff.net>
Fri, 25 Oct 2024 07:01:25 +0000 (03:01 -0400)
committerTaylor Blau <me@ttaylorr.com>
Fri, 25 Oct 2024 21:35:46 +0000 (17:35 -0400)
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>
builtin/pack-redundant.c
packfile.c
packfile.h

index 580961300283a40ff5de87deaa32bf1b0a3a56bc..d2c1c4e5ec14711a54b8483106e9ed05fbe960bf 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "packfile.h"
 #include "object-store-ll.h"
+#include "strbuf.h"
 
 #define BLKSIZE 512
 
@@ -591,6 +592,7 @@ static void load_all(void)
 int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
        int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
        struct llist *ignore;
+       struct strbuf idx_name = STRBUF_INIT;
        char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */
 
        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
        pl = red = pack_list_difference(local_packs, min);
        while (pl) {
                printf("%s\n%s\n",
-                      sha1_pack_index_name(pl->pack->hash),
+                      odb_pack_name(&idx_name, pl->pack->hash, "idx"),
                       pl->pack->pack_name);
                pl = pl->next;
        }
@@ -699,5 +701,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
        pack_list_free(red);
        pack_list_free(min);
        llist_free(ignore);
+       strbuf_release(&idx_name);
        return 0;
 }
index 48d650161f27e6ac2877b7fc4706659ec236458a..0d4fd2737acd2c6ebf86b456d78699bd01f3c603 100644 (file)
@@ -35,12 +35,6 @@ char *odb_pack_name(struct strbuf *buf,
        return buf->buf;
 }
 
-char *sha1_pack_index_name(const unsigned char *sha1)
-{
-       static struct strbuf buf = STRBUF_INIT;
-       return odb_pack_name(&buf, sha1, "idx");
-}
-
 static unsigned int pack_used_ctr;
 static unsigned int pack_mmap_calls;
 static unsigned int peak_pack_open_windows;
index 2bbcc585719f2e050fd474d836658d49146f92ac..6812abaae0bce79fe561dcadd6f79aa69c3db0ff 100644 (file)
@@ -31,13 +31,6 @@ struct pack_entry {
  */
 char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
 
-/*
- * Return the name of the (local) pack index file with the specified
- * sha1 in its name.  The return value is a pointer to memory that is
- * overwritten each time this function is called.
- */
-char *sha1_pack_index_name(const unsigned char *sha1);
-
 /*
  * Return the basename of the packfile, omitting any containing directory
  * (e.g., "pack-1234abcd[...].pack").