diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2017-08-18 15:20:16 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-08-23 15:12:06 -0700 |
commit | 4f39cd821d1756f5f6d145f987576660136931ee (patch) | |
tree | c7a0b1de6a17b1336f82bbbd598d766e6d0030e3 | |
parent | 39566494226919aa18951f2abff6491f5547d377 (diff) | |
download | git-4f39cd821d1756f5f6d145f987576660136931ee.tar.gz git-4f39cd821d1756f5f6d145f987576660136931ee.tar.xz |
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>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | builtin/index-pack.c | 1 | ||||
-rw-r--r-- | builtin/pack-redundant.c | 1 | ||||
-rw-r--r-- | cache.h | 23 | ||||
-rw-r--r-- | fast-import.c | 1 | ||||
-rw-r--r-- | http.c | 1 | ||||
-rw-r--r-- | outgoing/packfile.h | 0 | ||||
-rw-r--r-- | packfile.c | 23 | ||||
-rw-r--r-- | packfile.h | 27 | ||||
-rw-r--r-- | sha1_file.c | 23 |
10 files changed, 56 insertions, 45 deletions
@@ -816,6 +816,7 @@ LIB_OBJS += notes-merge.o LIB_OBJS += notes-utils.o LIB_OBJS += object.o LIB_OBJS += oidset.o +LIB_OBJS += packfile.o LIB_OBJS += pack-bitmap.o LIB_OBJS += pack-bitmap-write.o LIB_OBJS += pack-check.o diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 26828c1d8..f2be145e1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -12,6 +12,7 @@ #include "exec_cmd.h" #include "streaming.h" #include "thread-utils.h" +#include "packfile.h" static const char index_pack_usage[] = "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])"; diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index cb1df1c76..aaa813632 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -7,6 +7,7 @@ */ #include "builtin.h" +#include "packfile.h" #define BLKSIZE 512 @@ -903,20 +903,6 @@ extern void check_repository_format(void); extern const char *sha1_file_name(const unsigned char *sha1); /* - * Return the name of the (local) packfile with the specified sha1 in - * its name. The return value is a pointer to memory that is - * overwritten each time this function is called. - */ -extern char *sha1_pack_name(const unsigned char *sha1); - -/* - * 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. - */ -extern char *sha1_pack_index_name(const unsigned char *sha1); - -/* * Return an abbreviated sha1 unique within this repository's object database. * The result will be at least `len` characters long, and will be NUL * terminated. @@ -1651,15 +1637,6 @@ extern void pack_report(void); extern int odb_mkstemp(struct strbuf *template, const char *pattern); /* - * Generate the filename to be used for a pack file with checksum "sha1" and - * extension "ext". The result is written into the strbuf "buf", overwriting - * any existing contents. A pointer to buf->buf is returned as a convenience. - * - * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx" - */ -extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); - -/* * Create a pack .keep file named "name" (which should generally be the output * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on * error. diff --git a/fast-import.c b/fast-import.c index a959161b4..49516d60e 100644 --- a/fast-import.c +++ b/fast-import.c @@ -167,6 +167,7 @@ Format of STDIN stream: #include "quote.h" #include "dir.h" #include "run-command.h" +#include "packfile.h" #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1) @@ -11,6 +11,7 @@ #include "pkt-line.h" #include "gettext.h" #include "transport.h" +#include "packfile.h" static struct trace_key trace_curl = TRACE_KEY_INIT(CURL); #if LIBCURL_VERSION_NUM >= 0x070a08 diff --git a/outgoing/packfile.h b/outgoing/packfile.h new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/outgoing/packfile.h diff --git a/packfile.c b/packfile.c new file mode 100644 index 000000000..0d191dfd6 --- /dev/null +++ b/packfile.c @@ -0,0 +1,23 @@ +#include "cache.h" + +char *odb_pack_name(struct strbuf *buf, + const unsigned char *sha1, + const char *ext) +{ + strbuf_reset(buf); + strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(), + sha1_to_hex(sha1), ext); + return buf->buf; +} + +char *sha1_pack_name(const unsigned char *sha1) +{ + static struct strbuf buf = STRBUF_INIT; + return odb_pack_name(&buf, sha1, "pack"); +} + +char *sha1_pack_index_name(const unsigned char *sha1) +{ + static struct strbuf buf = STRBUF_INIT; + return odb_pack_name(&buf, sha1, "idx"); +} diff --git a/packfile.h b/packfile.h new file mode 100644 index 000000000..3c4a0dbd7 --- /dev/null +++ b/packfile.h @@ -0,0 +1,27 @@ +#ifndef PACKFILE_H +#define PACKFILE_H + +/* + * Generate the filename to be used for a pack file with checksum "sha1" and + * extension "ext". The result is written into the strbuf "buf", overwriting + * any existing contents. A pointer to buf->buf is returned as a convenience. + * + * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx" + */ +extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); + +/* + * Return the name of the (local) packfile with the specified sha1 in + * its name. The return value is a pointer to memory that is + * overwritten each time this function is called. + */ +extern char *sha1_pack_name(const unsigned char *sha1); + +/* + * 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. + */ +extern char *sha1_pack_index_name(const unsigned char *sha1); + +#endif diff --git a/sha1_file.c b/sha1_file.c index 189a1c3cd..063409fe0 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -28,6 +28,7 @@ #include "list.h" #include "mergesort.h" #include "quote.h" +#include "packfile.h" #define SZ_FMT PRIuMAX 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, return buf->buf; } - char *odb_pack_name(struct strbuf *buf, - const unsigned char *sha1, - const char *ext) -{ - strbuf_reset(buf); - strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(), - sha1_to_hex(sha1), ext); - return buf->buf; -} - -char *sha1_pack_name(const unsigned char *sha1) -{ - static struct strbuf buf = STRBUF_INIT; - return odb_pack_name(&buf, sha1, "pack"); -} - -char *sha1_pack_index_name(const unsigned char *sha1) -{ - static struct strbuf buf = STRBUF_INIT; - return odb_pack_name(&buf, sha1, "idx"); -} - struct alternate_object_database *alt_odb_list; static struct alternate_object_database **alt_odb_tail; |