diff options
author | Stefan Beller <sbeller@google.com> | 2018-03-23 20:20:57 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-23 21:06:01 +0300 |
commit | 031dc927f443fa5274e794c12ac34f19a0e0d318 (patch) | |
tree | 07acd9769fb07037595e1ac0643984f43c8b3641 /sha1_file.c | |
parent | 0d4a132144a14ae6801523960cbc1939a9bab6c1 (diff) |
object-store: move alt_odb_list and alt_odb_tail to object store
In a process with multiple repositories open, alternates should be
associated to a single repository and not shared globally. Move
alt_odb_list and alt_odb_tail into the_repository and adjust callers
to reflect this.
Now that the alternative object data base is per repository, we're
leaking its memory upon freeing a repository. The next patch plugs
this hole.
No functional change intended.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c index af5aa83db5..84b361c125 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -22,6 +22,7 @@ #include "pack-revindex.h" #include "sha1-lookup.h" #include "bulk-checkin.h" +#include "repository.h" #include "streaming.h" #include "dir.h" #include "list.h" @@ -343,9 +344,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt, return buf->buf; } -struct alternate_object_database *alt_odb_list; -static struct alternate_object_database **alt_odb_tail; - /* * Return non-zero iff the path is usable as an alternate object database. */ @@ -365,7 +363,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir) * Prevent the common mistake of listing the same * thing twice, or object directory itself. */ - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) { if (!fspathcmp(path->buf, alt->path)) return 0; } @@ -425,8 +423,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, ent = alloc_alt_odb(pathbuf.buf); /* add the alternate entry */ - *alt_odb_tail = ent; - alt_odb_tail = &(ent->next); + *the_repository->objects->alt_odb_tail = ent; + the_repository->objects->alt_odb_tail = &(ent->next); ent->next = NULL; /* recursively add alternates */ @@ -560,7 +558,7 @@ void add_to_alternates_file(const char *reference) fprintf_or_die(out, "%s\n", reference); if (commit_lock_file(&lock)) die_errno("unable to move new alternates file into place"); - if (alt_odb_tail) + if (the_repository->objects->alt_odb_tail) link_alt_odb_entries(reference, '\n', NULL, 0); } free(alts); @@ -658,7 +656,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb) int r = 0; prepare_alt_odb(); - for (ent = alt_odb_list; ent; ent = ent->next) { + for (ent = the_repository->objects->alt_odb_list; ent; ent = ent->next) { r = fn(ent, cb); if (r) break; @@ -668,10 +666,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb) void prepare_alt_odb(void) { - if (alt_odb_tail) + if (the_repository->objects->alt_odb_tail) return; - alt_odb_tail = &alt_odb_list; + the_repository->objects->alt_odb_tail = + &the_repository->objects->alt_odb_list; link_alt_odb_entries(the_repository->objects->alternate_db, PATH_SEP, NULL, 0); @@ -716,7 +715,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen) { struct alternate_object_database *alt; prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) { const char *path = alt_sha1_path(alt, sha1); if (check_and_freshen_file(path, freshen)) return 1; @@ -876,7 +875,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st, prepare_alt_odb(); errno = ENOENT; - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) { *path = alt_sha1_path(alt, sha1); if (!lstat(*path, st)) return 0; @@ -906,7 +905,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path) most_interesting_errno = errno; prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) { *path = alt_sha1_path(alt, sha1); fd = git_open(*path); if (fd >= 0) |