sha1_file.c: make pack-name helper globally accessible

We provide sha1_pack_name() and sha1_pack_index_name(), but the more generic form (which takes its own strbuf and an arbitrary extension) is only used to implement the other two. Let's make it available, but clean up a few things: 1. Name it odb_pack_name(), as the original sha1_get_pack_name() is long but not all that descriptive. 2. Switch the strbuf argument to the beginning, so that it matches similar path-building functions like git_path_buf(). 3. Clean up the out-dated docstring and move it to the public declaration. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 16, 2017 at 10:27 UTC 1cec8c634fb76ecee862ff88066f55b63b7d5ff7
2 files changed +15 -11
cache.h
+9
@@ -1568,6 +1568,15 @@ extern void pack_report(void);
1568 */
1569 extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
1570
1571 +/*
1572 + * Generate the filename to be used for a pack file with checksum "sha1" and
1573 + * extension "ext". The result is written into the strbuf "buf", overwriting
1574 + * any existing contents. A pointer to buf->buf is returned as a convenience.
1575 + *
1576 + * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
1577 + */
1578 +extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
1579 +
1580 /*
1581 * Create a pack .keep file in the object database's pack directory, for
1582 * a pack with checksum "sha1". The return value is a file descriptor opened
sha1_file.c
+6 -11
@@ -203,31 +203,26 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
203 return buf->buf;
204 }
205
206 -/*
207 - * Return the name of the pack or index file with the specified sha1
208 - * in its filename. *base and *name are scratch space that must be
209 - * provided by the caller. which should be "pack" or "idx".
210 - */
211 -static char *sha1_get_pack_name(const unsigned char *sha1,
212 - struct strbuf *buf,
213 - const char *which)
206 + char *odb_pack_name(struct strbuf *buf,
207 + const unsigned char *sha1,
208 + const char *ext)
209 {
210 strbuf_reset(buf);
211 strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
217 - sha1_to_hex(sha1), which);
212 + sha1_to_hex(sha1), ext);
213 return buf->buf;
214 }
215
216 char *sha1_pack_name(const unsigned char *sha1)
217 {
218 static struct strbuf buf = STRBUF_INIT;
224 - return sha1_get_pack_name(sha1, &buf, "pack");
219 + return odb_pack_name(&buf, sha1, "pack");
220 }
221
222 char *sha1_pack_index_name(const unsigned char *sha1)
223 {
224 static struct strbuf buf = STRBUF_INIT;
230 - return sha1_get_pack_name(sha1, &buf, "idx");
225 + return odb_pack_name(&buf, sha1, "idx");
226 }
227
228 struct alternate_object_database *alt_odb_list;