diff options
author | Stefan Zager <szager@chromium.org> | 2014-02-10 16:55:12 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-02-12 13:44:05 -0800 |
commit | 3f164f662aaeee63ca5d9e082a90fa2d5326875c (patch) | |
tree | dd0288c9909e8ed843302725f8c00c4a002d3a6e /http-backend.c | |
parent | 79fcbf7e703ca5805ebd46b2c7e09d0703f1c1ff (diff) | |
download | git-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 'http-backend.c')
-rw-r--r-- | http-backend.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/http-backend.c b/http-backend.c index d2c0a625ce..cf1f2a4372 100644 --- a/http-backend.c +++ b/http-backend.c @@ -438,25 +438,29 @@ static void get_head(char *arg) strbuf_release(&buf); } +struct pack_info_data { + struct strbuf *buf; + size_t objdirlen; +}; + +static int append_pack_info_fn(struct packed_git *p, void *data) +{ + struct pack_info_data *d = (struct pack_info_data *) data; + if (p->pack_local) + strbuf_addf(d->buf, "P %s\n", p->pack_name + d->objdirlen + 6); + return 0; +} + static void get_info_packs(char *arg) { size_t objdirlen = strlen(get_object_directory()); struct strbuf buf = STRBUF_INIT; - struct packed_git *p; - size_t cnt = 0; + struct pack_info_data d = {&buf, objdirlen}; select_getanyfile(); prepare_packed_git(); - for (p = packed_git; p; p = p->next) { - if (p->pack_local) - cnt++; - } - - strbuf_grow(&buf, cnt * 53 + 2); - for (p = packed_git; p; p = p->next) { - if (p->pack_local) - strbuf_addf(&buf, "P %s\n", p->pack_name + objdirlen + 6); - } + strbuf_grow(&buf, packed_git_local_count() * 53 + 2); + foreach_packed_git(append_pack_info_fn, NULL, &d); strbuf_addch(&buf, '\n'); hdr_nocache(); |