summaryrefslogtreecommitdiff
path: root/cache.h
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 /cache.h
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 'cache.h')
-rw-r--r--cache.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/cache.h b/cache.h
index c9efe88e9e..0b5040e316 100644
--- a/cache.h
+++ b/cache.h
@@ -1020,7 +1020,7 @@ struct pack_window {
unsigned int inuse_cnt;
};
-extern struct packed_git {
+struct packed_git {
struct packed_git *next;
struct pack_window *windows;
off_t pack_size;
@@ -1038,7 +1038,7 @@ extern struct packed_git {
unsigned char sha1[20];
/* something like ".git/objects/pack/xxxxx.pack" */
char pack_name[FLEX_ARRAY]; /* more */
-} *packed_git;
+};
struct pack_entry {
off_t offset;
@@ -1046,6 +1046,20 @@ struct pack_entry {
struct packed_git *p;
};
+/*
+ * packed_git_foreach_fn implementations should return zero
+ * to continue the traversal, non-zero to halt.
+ */
+typedef int (*packed_git_foreach_fn)(struct packed_git *, void *);
+
+/*
+ * The 'hint' argument is for the commonly-used 'last found pack' optimization.
+ * It can be NULL.
+ */
+extern void foreach_packed_git(packed_git_foreach_fn fn, struct packed_git *hint, void *data);
+
+extern size_t packed_git_count(void);
+extern size_t packed_git_local_count(void);
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
/* A hook for count-objects to report invalid files in pack directory */