object-store: move packed_git and packed_git_mru to object store

In a process with multiple repositories open, packfile accessors
should be associated to a single repository and not shared globally.
Move packed_git and packed_git_mru into the_repository and adjust
callers to reflect this.

[nd: while at there, wrap access to these two fields in get_packed_git()
and get_packed_git_mru(). This allows us to lazily initialize these
fields without caller doing that explicitly]

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>
This commit is contained in:
Stefan Beller
2018-03-23 18:20:59 +01:00
committed by Junio C Hamano
parent 97501e933a
commit a80d72db2a
22 changed files with 128 additions and 74 deletions

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "repository.h"
#include "config.h"
#include "attr.h"
#include "object.h"
@ -28,6 +29,7 @@
#include "argv-array.h"
#include "list.h"
#include "packfile.h"
#include "object-store.h"
static const char *pack_usage[] = {
N_("git pack-objects --stdout [<options>...] [< <ref-list> | < <object-list>]"),
@ -1025,8 +1027,7 @@ static int want_object_in_pack(const struct object_id *oid,
if (want != -1)
return want;
}
list_for_each(pos, &packed_git_mru) {
list_for_each(pos, get_packed_git_mru(the_repository)) {
struct packed_git *p = list_entry(pos, struct packed_git, mru);
off_t offset;
@ -1044,7 +1045,8 @@ static int want_object_in_pack(const struct object_id *oid,
}
want = want_found_object(exclude, p);
if (!exclude && want > 0)
list_move(&p->mru, &packed_git_mru);
list_move(&p->mru,
get_packed_git_mru(the_repository));
if (want != -1)
return want;
}
@ -2673,7 +2675,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
memset(&in_pack, 0, sizeof(in_pack));
for (p = packed_git; p; p = p->next) {
for (p = get_packed_git(the_repository); p; p = p->next) {
struct object_id oid;
struct object *o;
@ -2736,7 +2738,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
static struct packed_git *last_found = (void *)1;
struct packed_git *p;
p = (last_found != (void *)1) ? last_found : packed_git;
p = (last_found != (void *)1) ? last_found :
get_packed_git(the_repository);
while (p) {
if ((!p->pack_local || p->pack_keep) &&
@ -2745,7 +2748,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
return 1;
}
if (p == last_found)
p = packed_git;
p = get_packed_git(the_repository);
else
p = p->next;
if (p == last_found)
@ -2781,7 +2784,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
uint32_t i;
struct object_id oid;
for (p = packed_git; p; p = p->next) {
for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local || p->pack_keep)
continue;
@ -3152,7 +3155,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
prepare_packed_git();
if (ignore_packed_keep) {
struct packed_git *p;
for (p = packed_git; p; p = p->next)
for (p = get_packed_git(the_repository); p; p = p->next)
if (p->pack_local && p->pack_keep)
break;
if (!p) /* no keep-able packs found */
@ -3165,7 +3168,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
* also covers non-local objects
*/
struct packed_git *p;
for (p = packed_git; p; p = p->next) {
for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local) {
have_non_local_packs = 1;
break;