From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>
Subject: [RFC PATCH 09/10] pack: move add_packed_git()
Date: Tue, 8 Aug 2017 12:32:39 -0700 [thread overview]
Message-ID: <8b10ea3dbd2c6e9f5ed6ae9fb55f7b15fe74e7d4.1502220307.git.jonathantanmy@google.com> (raw)
In-Reply-To: <cover.1502220307.git.jonathantanmy@google.com>
In-Reply-To: <cover.1502220307.git.jonathantanmy@google.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
cache.h | 1 -
connected.c | 1 +
pack.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
pack.h | 1 +
sha1_file.c | 61 -------------------------------------------------------------
5 files changed, 55 insertions(+), 62 deletions(-)
diff --git a/cache.h b/cache.h
index 4812f3a63..bf93477e8 100644
--- a/cache.h
+++ b/cache.h
@@ -1638,7 +1638,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,
diff --git a/connected.c b/connected.c
index 136c2ac16..3e3f0148c 100644
--- a/connected.c
+++ b/connected.c
@@ -3,6 +3,7 @@
#include "sigchain.h"
#include "connected.h"
#include "transport.h"
+#include "pack.h"
/*
* If we feed all the commits we want to verify to this command
diff --git a/pack.c b/pack.c
index 93526ea7b..efe0ed3e8 100644
--- a/pack.c
+++ b/pack.c
@@ -605,3 +605,56 @@ void unuse_pack(struct pack_window **w_cursor)
*w_cursor = NULL;
}
}
+
+static void try_to_free_pack_memory(size_t size)
+{
+ release_pack_memory(size);
+}
+
+struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
+{
+ static int have_set_try_to_free_routine;
+ struct stat st;
+ size_t alloc;
+ struct packed_git *p;
+
+ if (!have_set_try_to_free_routine) {
+ have_set_try_to_free_routine = 1;
+ set_try_to_free_routine(try_to_free_pack_memory);
+ }
+
+ /*
+ * Make sure a corresponding .pack file exists and that
+ * the index looks sane.
+ */
+ if (!strip_suffix_mem(path, &path_len, ".idx"))
+ return NULL;
+
+ /*
+ * ".pack" is long enough to hold any suffix we're adding (and
+ * the use xsnprintf double-checks that)
+ */
+ alloc = st_add3(path_len, strlen(".pack"), 1);
+ p = alloc_packed_git(alloc);
+ memcpy(p->pack_name, path, path_len);
+
+ xsnprintf(p->pack_name + path_len, alloc - path_len, ".keep");
+ if (!access(p->pack_name, F_OK))
+ p->pack_keep = 1;
+
+ xsnprintf(p->pack_name + path_len, alloc - path_len, ".pack");
+ if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
+ free(p);
+ return NULL;
+ }
+
+ /* ok, it looks sane as far as we can check without
+ * actually mapping the pack file.
+ */
+ p->pack_size = st.st_size;
+ p->pack_local = local;
+ p->mtime = st.st_mtime;
+ if (path_len < 40 || get_sha1_hex(path + path_len - 40, p->sha1))
+ hashclr(p->sha1);
+ return p;
+}
diff --git a/pack.h b/pack.h
index 3876e9ae6..c1f3ff32d 100644
--- a/pack.h
+++ b/pack.h
@@ -150,5 +150,6 @@ extern int open_packed_git(struct packed_git *p);
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
extern void unuse_pack(struct pack_window **);
+extern struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
#endif
diff --git a/sha1_file.c b/sha1_file.c
index 12501ef06..7f12b1ee0 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -717,67 +717,6 @@ void *xmmap(void *start, size_t length,
return ret;
}
-static struct packed_git *alloc_packed_git(int extra)
-{
- struct packed_git *p = xmalloc(st_add(sizeof(*p), extra));
- memset(p, 0, sizeof(*p));
- p->pack_fd = -1;
- return p;
-}
-
-static void try_to_free_pack_memory(size_t size)
-{
- release_pack_memory(size);
-}
-
-struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
-{
- static int have_set_try_to_free_routine;
- struct stat st;
- size_t alloc;
- struct packed_git *p;
-
- if (!have_set_try_to_free_routine) {
- have_set_try_to_free_routine = 1;
- set_try_to_free_routine(try_to_free_pack_memory);
- }
-
- /*
- * Make sure a corresponding .pack file exists and that
- * the index looks sane.
- */
- if (!strip_suffix_mem(path, &path_len, ".idx"))
- return NULL;
-
- /*
- * ".pack" is long enough to hold any suffix we're adding (and
- * the use xsnprintf double-checks that)
- */
- alloc = st_add3(path_len, strlen(".pack"), 1);
- p = alloc_packed_git(alloc);
- memcpy(p->pack_name, path, path_len);
-
- xsnprintf(p->pack_name + path_len, alloc - path_len, ".keep");
- if (!access(p->pack_name, F_OK))
- p->pack_keep = 1;
-
- xsnprintf(p->pack_name + path_len, alloc - path_len, ".pack");
- if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) {
- free(p);
- return NULL;
- }
-
- /* ok, it looks sane as far as we can check without
- * actually mapping the pack file.
- */
- p->pack_size = st.st_size;
- p->pack_local = local;
- p->mtime = st.st_mtime;
- if (path_len < 40 || get_sha1_hex(path + path_len - 40, p->sha1))
- hashclr(p->sha1);
- return p;
-}
-
void install_packed_git(struct packed_git *pack)
{
if (pack->pack_fd != -1)
--
2.14.0.434.g98096fd7a8-goog
next prev parent reply other threads:[~2017-08-08 19:33 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 19:32 [RFC PATCH 00/10] An attempt to move packfile funcs to its own file Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 01/10] pack: move pack name-related functions Jonathan Tan
2017-08-08 20:36 ` Stefan Beller
2017-08-08 20:50 ` Jonathan Tan
2017-08-09 12:00 ` Christian Couder
2017-08-09 17:16 ` Jonathan Tan
2017-08-11 19:38 ` Ben Peart
2017-08-11 21:34 ` Junio C Hamano
2017-08-16 22:53 ` Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 02/10] pack: move static state variables Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 03/10] pack: move pack_report() Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 04/10] pack: move open_pack_index(), parse_pack_index() Jonathan Tan
2017-08-08 20:19 ` Junio C Hamano
2017-08-08 20:45 ` Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 05/10] pack: move release_pack_memory() Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 06/10] pack: move pack-closing functions Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 07/10] pack: move use_pack() Jonathan Tan
2017-08-08 19:32 ` [RFC PATCH 08/10] pack: move unuse_pack() Jonathan Tan
2017-08-08 19:32 ` Jonathan Tan [this message]
2017-08-08 19:32 ` [RFC PATCH 10/10] pack: move install_packed_git() Jonathan Tan
2017-08-08 20:05 ` [RFC PATCH 00/10] An attempt to move packfile funcs to its own file Junio C Hamano
2017-08-08 20:43 ` Jonathan Tan
2017-08-08 21:04 ` Junio C Hamano
2017-08-09 1:22 ` [PATCH v2 00/25] Move exported " Jonathan Tan
2017-08-10 17:21 ` Stefan Beller
2017-08-10 21:19 ` Junio C Hamano
2017-08-10 21:59 ` Jonathan Tan
2017-08-10 22:40 ` Junio C Hamano
2017-08-11 20:36 ` [PATCH 0/2] non-move patches in preparation for packfile.c Jonathan Tan
2017-08-11 20:36 ` [PATCH 1/2] sha1_file: set whence in storage-specific info fn Jonathan Tan
2017-08-11 21:52 ` Junio C Hamano
2017-08-11 20:36 ` [PATCH 2/2] sha1_file: remove read_packed_sha1() Jonathan Tan
2017-08-11 22:06 ` Junio C Hamano
2017-08-11 19:41 ` [PATCH v2 00/25] Move exported packfile funcs to its own file Ben Peart
2017-08-18 23:36 ` Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 01/25] pack: move pack name-related functions Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 02/25] pack: move static state variables Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 03/25] pack: move pack_report() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 04/25] pack: move open_pack_index(), parse_pack_index() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 05/25] pack: move release_pack_memory() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 06/25] pack: move pack-closing functions Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 07/25] pack: move use_pack() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 08/25] pack: move unuse_pack() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 09/25] pack: move add_packed_git() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 10/25] pack: move install_packed_git() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 11/25] pack: move {,re}prepare_packed_git and approximate_object_count Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 12/25] pack: move unpack_object_header() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 13/25] pack: move get_size_from_delta() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 14/25] pack: move unpack_object_header() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 15/25] sha1_file: set whence in storage-specific info fn Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 16/25] sha1_file: remove read_packed_sha1() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 17/25] pack: move packed_object_info(), unpack_entry() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 18/25] pack: move nth_packed_object_{sha1,oid} Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 19/25] pack: move check_pack_index_ptr(), nth_packed_object_offset() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 20/25] pack: move find_pack_entry_one(), is_pack_valid() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 21/25] pack: move find_sha1_pack() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 22/25] pack: move find_pack_entry() and make it global Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 23/25] pack: move has_sha1_pack() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 24/25] pack: move has_pack_index() Jonathan Tan
2017-08-09 1:22 ` [PATCH v2 25/25] pack: move for_each_packed_object() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 00/23] Move exported packfile funcs to its own file Jonathan Tan
2017-08-19 7:33 ` Junio C Hamano
2017-08-20 6:40 ` Junio C Hamano
2017-08-21 18:40 ` Jonathan Tan
2017-08-21 22:55 ` Junio C Hamano
2017-08-18 22:20 ` [PATCH v3 01/23] pack: move pack name-related functions Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 02/23] pack: move static state variables Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 03/23] pack: move pack_report() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 04/23] pack: move open_pack_index(), parse_pack_index() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 05/23] pack: move release_pack_memory() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 06/23] pack: move pack-closing functions Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 07/23] pack: move use_pack() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 08/23] pack: move unuse_pack() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 09/23] pack: move add_packed_git() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 10/23] pack: move install_packed_git() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 11/23] pack: move {,re}prepare_packed_git and approximate_object_count Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 12/23] pack: move unpack_object_header_buffer() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 13/23] pack: move get_size_from_delta() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 14/23] pack: move unpack_object_header() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 15/23] pack: move clear_delta_base_cache(), packed_object_info(), unpack_entry() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 16/23] pack: move nth_packed_object_{sha1,oid} Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 17/23] pack: move check_pack_index_ptr(), nth_packed_object_offset() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 18/23] pack: move find_pack_entry_one(), is_pack_valid() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 19/23] pack: move find_sha1_pack() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 20/23] pack: move find_pack_entry() and make it global Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 21/23] pack: move has_sha1_pack() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 22/23] pack: move has_pack_index() Jonathan Tan
2017-08-18 22:20 ` [PATCH v3 23/23] pack: move for_each_packed_object() Jonathan Tan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8b10ea3dbd2c6e9f5ed6ae9fb55f7b15fe74e7d4.1502220307.git.jonathantanmy@google.com \
--to=jonathantanmy@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).