From 4f39cd821d1756f5f6d145f987576660136931ee Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:16 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- cache.h | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ab3b52ff92..dbc02ad817 100644 --- a/cache.h +++ b/cache.h @@ -902,20 +902,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 @@ -1650,15 +1636,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 -- cgit v1.2.1 From 8e21176c3cff203c1b991fda55df3ac7904d09fa Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:18 -0700 Subject: pack: move pack_report() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index dbc02ad817..aaf825fb7b 100644 --- a/cache.h +++ b/cache.h @@ -1626,8 +1626,6 @@ unsigned long approximate_object_count(void); extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); -extern void pack_report(void); - /* * Create a temporary file rooted in the object database directory, or * die on failure. The filename is taken from "pattern", which should have the -- cgit v1.2.1 From 0317f45576a0b48c90c4b023fa572a000633946c Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:19 -0700 Subject: pack: move open_pack_index(), parse_pack_index() alloc_packed_git() in packfile.c is duplicated from sha1_file.c. In a subsequent commit, alloc_packed_git() will be removed from sha1_file.c. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index aaf825fb7b..9fd61e9ea0 100644 --- a/cache.h +++ b/cache.h @@ -1605,8 +1605,6 @@ struct pack_entry { struct packed_git *p; }; -extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path); - /* A hook to report invalid files in pack directory */ #define PACKDIR_FILE_PACK 1 #define PACKDIR_FILE_IDX 2 @@ -1641,12 +1639,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -/* - * mmap the index file for the specified packfile (if it is not - * already mmapped). Return 0 on success. - */ -extern int open_pack_index(struct packed_git *); - /* * munmap the index file for the specified packfile (if it is * currently mmapped). -- cgit v1.2.1 From 3836d88ae575cf2321fb17296f748c0bb35ba268 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:21 -0700 Subject: pack: move pack-closing functions The function close_pack_fd() needs to be temporarily made global. Its scope will be restored to static in a subsequent commit. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9fd61e9ea0..48f44959d2 100644 --- a/cache.h +++ b/cache.h @@ -1639,15 +1639,7 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -/* - * munmap the index file for the specified packfile (if it is - * currently mmapped). - */ -extern void close_pack_index(struct packed_git *); - extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *); -extern void close_pack_windows(struct packed_git *); -extern void close_all_packs(void); extern void unuse_pack(struct pack_window **); extern void clear_delta_base_cache(void); extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local); -- cgit v1.2.1 From 84f80ad5e11d29b61570269a25cf447f34c5aeba Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:22 -0700 Subject: pack: move use_pack() The function open_packed_git() needs to be temporarily made global. Its scope will be restored to static in a subsequent commit. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 48f44959d2..2e02b02d17 100644 --- a/cache.h +++ b/cache.h @@ -1639,7 +1639,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *); extern void unuse_pack(struct pack_window **); extern void clear_delta_base_cache(void); extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local); -- cgit v1.2.1 From 97de1803f8972c41703424bb1697c224deb2b558 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:23 -0700 Subject: pack: move unuse_pack() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2e02b02d17..52deb9fa4e 100644 --- a/cache.h +++ b/cache.h @@ -1639,7 +1639,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -extern void unuse_pack(struct pack_window **); extern void clear_delta_base_cache(void); extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local); -- cgit v1.2.1 From 9a4286537489f77b6e68f0ad0fc4398c4ec9846b Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:24 -0700 Subject: pack: move add_packed_git() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 52deb9fa4e..3b1526b9ba 100644 --- a/cache.h +++ b/cache.h @@ -1640,7 +1640,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); extern int odb_pack_keep(const char *name); extern void clear_delta_base_cache(void); -extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local); /* * Make sure that a pointer access into an mmap'd index file is within bounds, -- cgit v1.2.1 From e65f186242ccda24616e40681f46ad8d33da63e2 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:25 -0700 Subject: pack: move install_packed_git() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3b1526b9ba..51b231833a 100644 --- a/cache.h +++ b/cache.h @@ -1613,7 +1613,6 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path); extern void prepare_packed_git(void); extern void reprepare_packed_git(void); -extern void install_packed_git(struct packed_git *pack); /* * Give a rough count of objects in the repository. This sacrifices accuracy -- cgit v1.2.1 From 0abe14f6a5b7681b4ea02d1bd0a64332587ae053 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:26 -0700 Subject: pack: move {,re}prepare_packed_git and approximate_object_count Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 51b231833a..a9f45512dc 100644 --- a/cache.h +++ b/cache.h @@ -1605,21 +1605,6 @@ struct pack_entry { struct packed_git *p; }; -/* A hook to report invalid files in pack directory */ -#define PACKDIR_FILE_PACK 1 -#define PACKDIR_FILE_IDX 2 -#define PACKDIR_FILE_GARBAGE 4 -extern void (*report_garbage)(unsigned seen_bits, const char *path); - -extern void prepare_packed_git(void); -extern void reprepare_packed_git(void); - -/* - * Give a rough count of objects in the repository. This sacrifices accuracy - * for speed. - */ -unsigned long approximate_object_count(void); - extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); -- cgit v1.2.1 From 32b42e152fcc453273fadb5a7d639e4e9b506783 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:27 -0700 Subject: pack: move unpack_object_header_buffer() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a9f45512dc..faa8940aff 100644 --- a/cache.h +++ b/cache.h @@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *) extern int is_pack_valid(struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); -- cgit v1.2.1 From 7b3aa75df7db72a283a11b9ce41658b89576db2b Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:28 -0700 Subject: pack: move get_size_from_delta() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index faa8940aff..fe2d90b772 100644 --- a/cache.h +++ b/cache.h @@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *) extern int is_pack_valid(struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); /* -- cgit v1.2.1 From 3588dd6e994b38b02c2f60544fe2f69ce5fdf927 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:29 -0700 Subject: pack: move unpack_object_header() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fe2d90b772..4818f25597 100644 --- a/cache.h +++ b/cache.h @@ -1663,7 +1663,6 @@ extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *) extern int is_pack_valid(struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -extern int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); /* * Iterate over the files in the loose-object parts of the object -- cgit v1.2.1 From f1d8130be0a7229b215b76eac54c561a0124bc99 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:30 -0700 Subject: pack: move clear_delta_base_cache(), packed_object_info(), unpack_entry() Both sha1_file.c and packfile.c now need read_object(), so a copy of read_object() was created in packfile.c. This patch makes both mark_bad_packed_object() and has_packed_and_bad() global. Unlike most of the other patches in this series, these 2 functions need to remain global. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4818f25597..79457975fe 100644 --- a/cache.h +++ b/cache.h @@ -1187,9 +1187,6 @@ extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size); extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); extern int parse_sha1_header(const char *hdr, unsigned long *sizep); -/* global flag to enable extra checks when accessing packed objects */ -extern int do_check_packed_object_crc; - extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); extern int finalize_object_file(const char *tmpfile, const char *filename); @@ -1623,8 +1620,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -extern void clear_delta_base_cache(void); - /* * Make sure that a pointer access into an mmap'd index file is within bounds, * and can provide at least 8 bytes of data. @@ -1662,7 +1657,6 @@ extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); extern int is_pack_valid(struct packed_git *); -extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); /* * Iterate over the files in the loose-object parts of the object @@ -1773,7 +1767,6 @@ struct object_info { /* Do not retry packed storage after checking packed and loose storage */ #define OBJECT_INFO_QUICK 8 extern int sha1_object_info_extended(const unsigned char *, struct object_info *, unsigned flags); -extern int packed_object_info(struct packed_git *pack, off_t offset, struct object_info *); /* Dumb servers support */ extern int update_server_info(int); -- cgit v1.2.1 From d5a16761820f2539bf8610c8f0c64f610e29314e Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:31 -0700 Subject: pack: move nth_packed_object_{sha1,oid} Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 79457975fe..42a8283365 100644 --- a/cache.h +++ b/cache.h @@ -1630,20 +1630,6 @@ extern int odb_pack_keep(const char *name); */ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr); -/* - * Return the SHA-1 of the nth object within the specified packfile. - * Open the index if it is not already open. The return value points - * at the SHA-1 within the mmapped index. Return NULL if there is an - * error. - */ -extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n); -/* - * Like nth_packed_object_sha1, but write the data into the object specified by - * the the first argument. Returns the first argument on success, and NULL on - * error. - */ -extern const struct object_id *nth_packed_object_oid(struct object_id *, struct packed_git *, uint32_t n); - /* * Return the offset of the nth object within the specified packfile. * The index must already be opened. -- cgit v1.2.1 From 9e0f45f5a61d9d0556e6004198dd6a650be14bd9 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:32 -0700 Subject: pack: move check_pack_index_ptr(), nth_packed_object_offset() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 42a8283365..1a8b22779a 100644 --- a/cache.h +++ b/cache.h @@ -1620,22 +1620,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -/* - * Make sure that a pointer access into an mmap'd index file is within bounds, - * and can provide at least 8 bytes of data. - * - * Note that this is only necessary for variable-length segments of the file - * (like the 64-bit extended offset table), as we compare the size to the - * fixed-length parts when we open the file. - */ -extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr); - -/* - * Return the offset of the nth object within the specified packfile. - * The index must already be opened. - */ -extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); - /* * If the object named sha1 is present in the specified packfile, * return its offset within the packfile; otherwise, return 0. -- cgit v1.2.1 From a2551953b9619b285128c1e9cf35120fb7555d8f Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:33 -0700 Subject: pack: move find_pack_entry_one(), is_pack_valid() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1a8b22779a..c13345d641 100644 --- a/cache.h +++ b/cache.h @@ -1620,14 +1620,6 @@ extern int odb_mkstemp(struct strbuf *template, const char *pattern); */ extern int odb_pack_keep(const char *name); -/* - * If the object named sha1 is present in the specified packfile, - * return its offset within the packfile; otherwise, return 0. - */ -extern off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); - -extern int is_pack_valid(struct packed_git *); - /* * Iterate over the files in the loose-object parts of the object * directory "path", triggering the following callbacks: -- cgit v1.2.1 From d6fe0036fd5e0cf7f51aa84381ebd321e898350a Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:34 -0700 Subject: pack: move find_sha1_pack() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c13345d641..0f435cb3e5 100644 --- a/cache.h +++ b/cache.h @@ -1602,9 +1602,6 @@ struct pack_entry { struct packed_git *p; }; -extern struct packed_git *find_sha1_pack(const unsigned char *sha1, - struct packed_git *packs); - /* * Create a temporary file rooted in the object database directory, or * die on failure. The filename is taken from "pattern", which should have the -- cgit v1.2.1 From 150e3001d0c5cc69db72a10f3e0cd1e14f11acba Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:36 -0700 Subject: pack: move has_sha1_pack() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0f435cb3e5..a2897bc7d1 100644 --- a/cache.h +++ b/cache.h @@ -1191,8 +1191,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int finalize_object_file(const char *tmpfile, const char *filename); -extern int has_sha1_pack(const unsigned char *sha1); - /* * Open the loose object at path, check its sha1, and return the contents, * type, and size. If the object is a blob, then "contents" may return NULL, -- cgit v1.2.1 From f9a8672a81277b83cabd59c6705089351c4f3ec4 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:37 -0700 Subject: pack: move has_pack_index() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index a2897bc7d1..c057d3fed3 100644 --- a/cache.h +++ b/cache.h @@ -1226,8 +1226,6 @@ extern int has_object_file_with_flags(const struct object_id *oid, int flags); */ extern int has_loose_object_nonlocal(const unsigned char *sha1); -extern int has_pack_index(const unsigned char *sha1); - extern void assert_sha1_type(const unsigned char *sha1, enum object_type expect); /* Helper to check and "touch" a file */ -- cgit v1.2.1 From 7709f468fdeece2a99d60a581a4ced65cd2844df Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Fri, 18 Aug 2017 15:20:38 -0700 Subject: pack: move for_each_packed_object() Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- cache.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c057d3fed3..2f09f8814a 100644 --- a/cache.h +++ b/cache.h @@ -1662,17 +1662,12 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path, void *data); /* - * Iterate over loose and packed objects in both the local + * Iterate over loose objects in both the local * repository and any alternates repositories (unless the * LOCAL_ONLY flag is set). */ #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1 -typedef int each_packed_object_fn(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, - void *data); extern int for_each_loose_object(each_loose_object_fn, void *, unsigned flags); -extern int for_each_packed_object(each_packed_object_fn, void *, unsigned flags); struct object_info { /* Request */ -- cgit v1.2.1