Skip to content

Commit 1cec8c6

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 82c9d66 commit 1cec8c6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

cache.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,15 @@ extern void pack_report(void);
15681568
*/
15691569
extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
15701570

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+
15711580
/*
15721581
* Create a pack .keep file in the object database's pack directory, for
15731582
* a pack with checksum "sha1". The return value is a file descriptor opened

sha1_file.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,31 +203,26 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
203203
return buf->buf;
204204
}
205205

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)
214209
{
215210
strbuf_reset(buf);
216211
strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
217-
sha1_to_hex(sha1), which);
212+
sha1_to_hex(sha1), ext);
218213
return buf->buf;
219214
}
220215

221216
char *sha1_pack_name(const unsigned char *sha1)
222217
{
223218
static struct strbuf buf = STRBUF_INIT;
224-
return sha1_get_pack_name(sha1, &buf, "pack");
219+
return odb_pack_name(&buf, sha1, "pack");
225220
}
226221

227222
char *sha1_pack_index_name(const unsigned char *sha1)
228223
{
229224
static struct strbuf buf = STRBUF_INIT;
230-
return sha1_get_pack_name(sha1, &buf, "idx");
225+
return odb_pack_name(&buf, sha1, "idx");
231226
}
232227

233228
struct alternate_object_database *alt_odb_list;

0 commit comments

Comments
 (0)