Skip to content

Commit 4f39cd8

Browse files
jonathantanmygitster
authored andcommitted
pack: move pack name-related functions
Currently, sha1_file.c and cache.h contain many functions, both related to and unrelated to packfiles. This makes both files very large and causes an unclear separation of concerns. Create a new file, packfile.c, to hold all packfile-related functions currently in sha1_file.c. It has a corresponding header packfile.h. In this commit, the pack name-related functions are moved. Subsequent commits will move the other functions. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3956649 commit 4f39cd8

File tree

10 files changed

+56
-45
lines changed

10 files changed

+56
-45
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ LIB_OBJS += notes-merge.o
816816
LIB_OBJS += notes-utils.o
817817
LIB_OBJS += object.o
818818
LIB_OBJS += oidset.o
819+
LIB_OBJS += packfile.o
819820
LIB_OBJS += pack-bitmap.o
820821
LIB_OBJS += pack-bitmap-write.o
821822
LIB_OBJS += pack-check.o

builtin/index-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "exec_cmd.h"
1313
#include "streaming.h"
1414
#include "thread-utils.h"
15+
#include "packfile.h"
1516

1617
static const char index_pack_usage[] =
1718
"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";

builtin/pack-redundant.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "builtin.h"
10+
#include "packfile.h"
1011

1112
#define BLKSIZE 512
1213

cache.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,6 @@ extern void check_repository_format(void);
902902
*/
903903
extern const char *sha1_file_name(const unsigned char *sha1);
904904

905-
/*
906-
* Return the name of the (local) packfile with the specified sha1 in
907-
* its name. The return value is a pointer to memory that is
908-
* overwritten each time this function is called.
909-
*/
910-
extern char *sha1_pack_name(const unsigned char *sha1);
911-
912-
/*
913-
* Return the name of the (local) pack index file with the specified
914-
* sha1 in its name. The return value is a pointer to memory that is
915-
* overwritten each time this function is called.
916-
*/
917-
extern char *sha1_pack_index_name(const unsigned char *sha1);
918-
919905
/*
920906
* Return an abbreviated sha1 unique within this repository's object database.
921907
* The result will be at least `len` characters long, and will be NUL
@@ -1650,15 +1636,6 @@ extern void pack_report(void);
16501636
*/
16511637
extern int odb_mkstemp(struct strbuf *template, const char *pattern);
16521638

1653-
/*
1654-
* Generate the filename to be used for a pack file with checksum "sha1" and
1655-
* extension "ext". The result is written into the strbuf "buf", overwriting
1656-
* any existing contents. A pointer to buf->buf is returned as a convenience.
1657-
*
1658-
* Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
1659-
*/
1660-
extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
1661-
16621639
/*
16631640
* Create a pack .keep file named "name" (which should generally be the output
16641641
* of odb_pack_name). Returns a file descriptor opened for writing, or -1 on

fast-import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Format of STDIN stream:
167167
#include "quote.h"
168168
#include "dir.h"
169169
#include "run-command.h"
170+
#include "packfile.h"
170171

171172
#define PACK_ID_BITS 16
172173
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pkt-line.h"
1212
#include "gettext.h"
1313
#include "transport.h"
14+
#include "packfile.h"
1415

1516
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
1617
#if LIBCURL_VERSION_NUM >= 0x070a08

outgoing/packfile.h

Whitespace-only changes.

packfile.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "cache.h"
2+
3+
char *odb_pack_name(struct strbuf *buf,
4+
const unsigned char *sha1,
5+
const char *ext)
6+
{
7+
strbuf_reset(buf);
8+
strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
9+
sha1_to_hex(sha1), ext);
10+
return buf->buf;
11+
}
12+
13+
char *sha1_pack_name(const unsigned char *sha1)
14+
{
15+
static struct strbuf buf = STRBUF_INIT;
16+
return odb_pack_name(&buf, sha1, "pack");
17+
}
18+
19+
char *sha1_pack_index_name(const unsigned char *sha1)
20+
{
21+
static struct strbuf buf = STRBUF_INIT;
22+
return odb_pack_name(&buf, sha1, "idx");
23+
}

packfile.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef PACKFILE_H
2+
#define PACKFILE_H
3+
4+
/*
5+
* Generate the filename to be used for a pack file with checksum "sha1" and
6+
* extension "ext". The result is written into the strbuf "buf", overwriting
7+
* any existing contents. A pointer to buf->buf is returned as a convenience.
8+
*
9+
* Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
10+
*/
11+
extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
12+
13+
/*
14+
* Return the name of the (local) packfile with the specified sha1 in
15+
* its name. The return value is a pointer to memory that is
16+
* overwritten each time this function is called.
17+
*/
18+
extern char *sha1_pack_name(const unsigned char *sha1);
19+
20+
/*
21+
* Return the name of the (local) pack index file with the specified
22+
* sha1 in its name. The return value is a pointer to memory that is
23+
* overwritten each time this function is called.
24+
*/
25+
extern char *sha1_pack_index_name(const unsigned char *sha1);
26+
27+
#endif

sha1_file.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "list.h"
2929
#include "mergesort.h"
3030
#include "quote.h"
31+
#include "packfile.h"
3132

3233
#define SZ_FMT PRIuMAX
3334
static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -278,28 +279,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
278279
return buf->buf;
279280
}
280281

281-
char *odb_pack_name(struct strbuf *buf,
282-
const unsigned char *sha1,
283-
const char *ext)
284-
{
285-
strbuf_reset(buf);
286-
strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
287-
sha1_to_hex(sha1), ext);
288-
return buf->buf;
289-
}
290-
291-
char *sha1_pack_name(const unsigned char *sha1)
292-
{
293-
static struct strbuf buf = STRBUF_INIT;
294-
return odb_pack_name(&buf, sha1, "pack");
295-
}
296-
297-
char *sha1_pack_index_name(const unsigned char *sha1)
298-
{
299-
static struct strbuf buf = STRBUF_INIT;
300-
return odb_pack_name(&buf, sha1, "idx");
301-
}
302-
303282
struct alternate_object_database *alt_odb_list;
304283
static struct alternate_object_database **alt_odb_tail;
305284

0 commit comments

Comments
 (0)