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>
This commit is contained in:

committed by
Junio C Hamano

parent
0d4a132144
commit
031dc927f4
@ -1,5 +1,6 @@
|
|||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "repository.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
@ -714,9 +715,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
|||||||
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
|
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
|
||||||
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
|
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
|
||||||
} else {
|
} else {
|
||||||
|
struct alternate_object_database *alt_odb_list;
|
||||||
|
|
||||||
fsck_object_dir(get_object_directory());
|
fsck_object_dir(get_object_directory());
|
||||||
|
|
||||||
prepare_alt_odb();
|
prepare_alt_odb();
|
||||||
|
alt_odb_list = the_repository->objects->alt_odb_list;
|
||||||
for (alt = alt_odb_list; alt; alt = alt->next)
|
for (alt = alt_odb_list; alt; alt = alt->next)
|
||||||
fsck_object_dir(alt->path);
|
fsck_object_dir(alt->path);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef OBJECT_STORE_H
|
#ifndef OBJECT_STORE_H
|
||||||
#define OBJECT_STORE_H
|
#define OBJECT_STORE_H
|
||||||
|
|
||||||
extern struct alternate_object_database {
|
struct alternate_object_database {
|
||||||
struct alternate_object_database *next;
|
struct alternate_object_database *next;
|
||||||
|
|
||||||
/* see alt_scratch_buf() */
|
/* see alt_scratch_buf() */
|
||||||
@ -19,7 +19,7 @@ extern struct alternate_object_database {
|
|||||||
struct oid_array loose_objects_cache;
|
struct oid_array loose_objects_cache;
|
||||||
|
|
||||||
char path[FLEX_ARRAY];
|
char path[FLEX_ARRAY];
|
||||||
} *alt_odb_list;
|
};
|
||||||
void prepare_alt_odb(void);
|
void prepare_alt_odb(void);
|
||||||
char *compute_alternate_path(const char *path, struct strbuf *err);
|
char *compute_alternate_path(const char *path, struct strbuf *err);
|
||||||
typedef int alt_odb_fn(struct alternate_object_database *, void *);
|
typedef int alt_odb_fn(struct alternate_object_database *, void *);
|
||||||
@ -61,6 +61,9 @@ struct raw_object_store {
|
|||||||
|
|
||||||
/* Path to extra alternate object database if not NULL */
|
/* Path to extra alternate object database if not NULL */
|
||||||
char *alternate_db;
|
char *alternate_db;
|
||||||
|
|
||||||
|
struct alternate_object_database *alt_odb_list;
|
||||||
|
struct alternate_object_database **alt_odb_tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct raw_object_store *raw_object_store_new(void);
|
struct raw_object_store *raw_object_store_new(void);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
#include "repository.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "mergesort.h"
|
#include "mergesort.h"
|
||||||
#include "packfile.h"
|
#include "packfile.h"
|
||||||
@ -892,7 +893,7 @@ void prepare_packed_git(void)
|
|||||||
return;
|
return;
|
||||||
prepare_packed_git_one(get_object_directory(), 1);
|
prepare_packed_git_one(get_object_directory(), 1);
|
||||||
prepare_alt_odb();
|
prepare_alt_odb();
|
||||||
for (alt = alt_odb_list; alt; alt = alt->next)
|
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next)
|
||||||
prepare_packed_git_one(alt->path, 0);
|
prepare_packed_git_one(alt->path, 0);
|
||||||
rearrange_packed_git();
|
rearrange_packed_git();
|
||||||
prepare_packed_git_mru();
|
prepare_packed_git_mru();
|
||||||
|
25
sha1_file.c
25
sha1_file.c
@ -22,6 +22,7 @@
|
|||||||
#include "pack-revindex.h"
|
#include "pack-revindex.h"
|
||||||
#include "sha1-lookup.h"
|
#include "sha1-lookup.h"
|
||||||
#include "bulk-checkin.h"
|
#include "bulk-checkin.h"
|
||||||
|
#include "repository.h"
|
||||||
#include "streaming.h"
|
#include "streaming.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
@ -343,9 +344,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
|
|||||||
return buf->buf;
|
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.
|
* 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
|
* Prevent the common mistake of listing the same
|
||||||
* thing twice, or object directory itself.
|
* 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))
|
if (!fspathcmp(path->buf, alt->path))
|
||||||
return 0;
|
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);
|
ent = alloc_alt_odb(pathbuf.buf);
|
||||||
|
|
||||||
/* add the alternate entry */
|
/* add the alternate entry */
|
||||||
*alt_odb_tail = ent;
|
*the_repository->objects->alt_odb_tail = ent;
|
||||||
alt_odb_tail = &(ent->next);
|
the_repository->objects->alt_odb_tail = &(ent->next);
|
||||||
ent->next = NULL;
|
ent->next = NULL;
|
||||||
|
|
||||||
/* recursively add alternates */
|
/* recursively add alternates */
|
||||||
@ -560,7 +558,7 @@ void add_to_alternates_file(const char *reference)
|
|||||||
fprintf_or_die(out, "%s\n", reference);
|
fprintf_or_die(out, "%s\n", reference);
|
||||||
if (commit_lock_file(&lock))
|
if (commit_lock_file(&lock))
|
||||||
die_errno("unable to move new alternates file into place");
|
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);
|
link_alt_odb_entries(reference, '\n', NULL, 0);
|
||||||
}
|
}
|
||||||
free(alts);
|
free(alts);
|
||||||
@ -658,7 +656,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
prepare_alt_odb();
|
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);
|
r = fn(ent, cb);
|
||||||
if (r)
|
if (r)
|
||||||
break;
|
break;
|
||||||
@ -668,10 +666,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
|
|||||||
|
|
||||||
void prepare_alt_odb(void)
|
void prepare_alt_odb(void)
|
||||||
{
|
{
|
||||||
if (alt_odb_tail)
|
if (the_repository->objects->alt_odb_tail)
|
||||||
return;
|
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,
|
link_alt_odb_entries(the_repository->objects->alternate_db,
|
||||||
PATH_SEP, NULL, 0);
|
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;
|
struct alternate_object_database *alt;
|
||||||
prepare_alt_odb();
|
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);
|
const char *path = alt_sha1_path(alt, sha1);
|
||||||
if (check_and_freshen_file(path, freshen))
|
if (check_and_freshen_file(path, freshen))
|
||||||
return 1;
|
return 1;
|
||||||
@ -876,7 +875,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
|
|||||||
|
|
||||||
prepare_alt_odb();
|
prepare_alt_odb();
|
||||||
errno = ENOENT;
|
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);
|
*path = alt_sha1_path(alt, sha1);
|
||||||
if (!lstat(*path, st))
|
if (!lstat(*path, st))
|
||||||
return 0;
|
return 0;
|
||||||
@ -906,7 +905,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
|
|||||||
most_interesting_errno = errno;
|
most_interesting_errno = errno;
|
||||||
|
|
||||||
prepare_alt_odb();
|
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);
|
*path = alt_sha1_path(alt, sha1);
|
||||||
fd = git_open(*path);
|
fd = git_open(*path);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "sha1-array.h"
|
#include "sha1-array.h"
|
||||||
#include "packfile.h"
|
#include "packfile.h"
|
||||||
#include "object-store.h"
|
#include "object-store.h"
|
||||||
|
#include "repository.h"
|
||||||
|
|
||||||
static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
|
static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
|
|||||||
*/
|
*/
|
||||||
fakeent = alloc_alt_odb(get_object_directory());
|
fakeent = alloc_alt_odb(get_object_directory());
|
||||||
}
|
}
|
||||||
fakeent->next = alt_odb_list;
|
fakeent->next = the_repository->objects->alt_odb_list;
|
||||||
|
|
||||||
for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
|
for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) {
|
||||||
int pos;
|
int pos;
|
||||||
|
Reference in New Issue
Block a user