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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Aug 18, 2017 at 15:20 UTC
4f39cd821d1756f5f6d145f987576660136931ee
10 files changed
+56
-45
Makefile
+1
@@ -816,6 +816,7 @@ LIB_OBJS += notes-merge.o
816
LIB_OBJS += notes-utils.o
817
LIB_OBJS += object.o
818
LIB_OBJS += oidset.o
819
+LIB_OBJS += packfile.o
820
LIB_OBJS += pack-bitmap.o
821
LIB_OBJS += pack-bitmap-write.o
822
LIB_OBJS += pack-check.o
builtin/index-pack.c
+1
@@ -12,6 +12,7 @@
12
#include "exec_cmd.h"
13
#include "streaming.h"
14
#include "thread-utils.h"
15
+#include "packfile.h"
16
17
static const char index_pack_usage[] =
18
"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
builtin/pack-redundant.c
+1
@@ -7,6 +7,7 @@
7
*/
8
9
#include "builtin.h"
10
+#include "packfile.h"
11
12
#define BLKSIZE 512
13
cache.h
-23
@@ -902,20 +902,6 @@ extern void check_repository_format(void);
902
*/
903
extern const char *sha1_file_name(const unsigned char *sha1);
904
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
-
905
/*
906
* Return an abbreviated sha1 unique within this repository's object database.
907
* The result will be at least `len` characters long, and will be NUL
@@ -1650,15 +1636,6 @@ extern void pack_report(void);
1636
*/
1637
extern int odb_mkstemp(struct strbuf *template, const char *pattern);
1638
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
-
1639
/*
1640
* Create a pack .keep file named "name" (which should generally be the output
1641
* of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
fast-import.c
+1
@@ -167,6 +167,7 @@ Format of STDIN stream:
167
#include "quote.h"
168
#include "dir.h"
169
#include "run-command.h"
170
+#include "packfile.h"
171
172
#define PACK_ID_BITS 16
173
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
http.c
+1
@@ -11,6 +11,7 @@
11
#include "pkt-line.h"
12
#include "gettext.h"
13
#include "transport.h"
14
+#include "packfile.h"
15
16
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
17
#if LIBCURL_VERSION_NUM >= 0x070a08
outgoing/packfile.h
packfile.c
new
+23
@@ -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
new
+27
@@ -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
+1
-22
@@ -28,6 +28,7 @@
28
#include "list.h"
29
#include "mergesort.h"
30
#include "quote.h"
31
+#include "packfile.h"
32
33
#define SZ_FMT PRIuMAX
34
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,
279
return buf->buf;
280
}
281
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
-
282
struct alternate_object_database *alt_odb_list;
283
static struct alternate_object_database **alt_odb_tail;
284