summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorStefan Zager <szager@chromium.org>2014-02-10 16:55:12 -0800
committerJunio C Hamano <gitster@pobox.com>2014-02-12 13:44:05 -0800
commit3f164f662aaeee63ca5d9e082a90fa2d5326875c (patch)
treedd0288c9909e8ed843302725f8c00c4a002d3a6e /sha1_file.c
parent79fcbf7e703ca5805ebd46b2c7e09d0703f1c1ff (diff)
downloadgit-sz/packed-git-static.tar.gz
sha1_file.c: the global packed_git variable static to the filesz/packed-git-static
This is a first step in making the codebase thread-safe. By and large, the operations which might benefit from threading are those that work with pack files (e.g., checkout, blame), so the focus of this patch is stop leaking the global list of pack files outside of sha1_file.c. The next step will be to control access to the list of pack files with a mutex. However, that alone is not enough to make pack file access thread safe. Even in a read-only operation, the window list associated with each pack file will need to be controlled. Additionally, the global counters in sha1_file.c will need to be controlled. This patch is a pure refactor with no functional changes, so it shouldn't require any additional tests. Adding the actual locks will be a functional change, and will require additional tests. [jc: with minimul style fixes before a full review] Signed-off-by: Stefan Zager <szager@chromium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index e13bd2c3ee..6bca45c9f6 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -60,6 +60,7 @@ static struct cached_object empty_tree = {
0
};
+static struct packed_git *packed_git;
static struct packed_git *last_found_pack;
static struct cached_object *find_cached_object(const unsigned char *sha1)
@@ -455,7 +456,6 @@ static unsigned int pack_open_fds;
static unsigned int pack_max_fds;
static size_t peak_pack_mapped;
static size_t pack_mapped;
-struct packed_git *packed_git;
void pack_report(void)
{
@@ -1078,6 +1078,37 @@ struct packed_git *add_packed_git(const char *path, int path_len, int local)
return p;
}
+void foreach_packed_git(packed_git_foreach_fn fn, struct packed_git *hint, void *data)
+{
+ struct packed_git *p;
+ if (hint && ((*fn)(hint, data)))
+ return;
+ for (p = packed_git; p; p = p->next)
+ if (p != hint && (*fn)(p, data))
+ return;
+}
+
+size_t packed_git_count(void)
+{
+ size_t res = 0;
+ struct packed_git *p;
+
+ for (p = packed_git; p; p = p->next)
+ ++res;
+ return res;
+}
+
+size_t packed_git_local_count(void)
+{
+ size_t res = 0;
+ struct packed_git *p;
+
+ for (p = packed_git; p; p = p->next)
+ if (p->pack_local)
+ ++res;
+ return res;
+}
+
struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)
{
const char *path = sha1_pack_name(sha1);
@@ -2461,6 +2492,8 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
{
struct packed_git *p;
+ if (!packs)
+ packs = packed_git;
for (p = packs; p; p = p->next) {
if (find_pack_entry_one(sha1, p))
return p;