1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-27 14:05:10 +02:00

commit-graph: pass a 'struct repository *' in more places

In a future commit, some commit-graph internals will want access to
'r->settings', but we only have the 'struct object_directory *'
corresponding to that repository.

Add an additional parameter to pass the repository around in more
places.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Taylor Blau 2020-09-09 11:22:56 -04:00 committed by Junio C Hamano
parent 025d52943e
commit ab14d0676c
4 changed files with 18 additions and 12 deletions

View File

@ -106,7 +106,7 @@ static int graph_verify(int argc, const char **argv)
FREE_AND_NULL(graph_name); FREE_AND_NULL(graph_name);
if (open_ok) if (open_ok)
graph = load_commit_graph_one_fd_st(fd, &st, odb); graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
else else
graph = read_commit_graph_one(the_repository, odb); graph = read_commit_graph_one(the_repository, odb);

View File

@ -224,7 +224,8 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
return 1; return 1;
} }
struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st, struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
struct object_directory *odb) struct object_directory *odb)
{ {
void *graph_map; void *graph_map;
@ -240,7 +241,7 @@ struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
} }
graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0); graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd); close(fd);
ret = parse_commit_graph(graph_map, graph_size); ret = parse_commit_graph(r, graph_map, graph_size);
if (ret) if (ret)
ret->odb = odb; ret->odb = odb;
@ -280,7 +281,8 @@ static int verify_commit_graph_lite(struct commit_graph *g)
return 0; return 0;
} }
struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size) struct commit_graph *parse_commit_graph(struct repository *r,
void *graph_map, size_t graph_size)
{ {
const unsigned char *data, *chunk_lookup; const unsigned char *data, *chunk_lookup;
uint32_t i; uint32_t i;
@ -445,7 +447,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
return NULL; return NULL;
} }
static struct commit_graph *load_commit_graph_one(const char *graph_file, static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
struct object_directory *odb) struct object_directory *odb)
{ {
@ -457,7 +460,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file,
if (!open_ok) if (!open_ok)
return NULL; return NULL;
g = load_commit_graph_one_fd_st(fd, &st, odb); g = load_commit_graph_one_fd_st(r, fd, &st, odb);
if (g) if (g)
g->filename = xstrdup(graph_file); g->filename = xstrdup(graph_file);
@ -469,7 +472,7 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
struct object_directory *odb) struct object_directory *odb)
{ {
char *graph_name = get_commit_graph_filename(odb); char *graph_name = get_commit_graph_filename(odb);
struct commit_graph *g = load_commit_graph_one(graph_name, odb); struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
free(graph_name); free(graph_name);
return g; return g;
@ -550,7 +553,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
valid = 0; valid = 0;
for (odb = r->objects->odb; odb; odb = odb->next) { for (odb = r->objects->odb; odb; odb = odb->next) {
char *graph_name = get_split_graph_filename(odb, line.buf); char *graph_name = get_split_graph_filename(odb, line.buf);
struct commit_graph *g = load_commit_graph_one(graph_name, odb); struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
free(graph_name); free(graph_name);

View File

@ -75,11 +75,13 @@ struct commit_graph {
struct bloom_filter_settings *bloom_filter_settings; struct bloom_filter_settings *bloom_filter_settings;
}; };
struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st, struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
struct object_directory *odb); struct object_directory *odb);
struct commit_graph *read_commit_graph_one(struct repository *r, struct commit_graph *read_commit_graph_one(struct repository *r,
struct object_directory *odb); struct object_directory *odb);
struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size); struct commit_graph *parse_commit_graph(struct repository *r,
void *graph_map, size_t graph_size);
/* /*
* Return 1 if and only if the repository has a commit-graph * Return 1 if and only if the repository has a commit-graph

View File

@ -1,7 +1,8 @@
#include "commit-graph.h" #include "commit-graph.h"
#include "repository.h" #include "repository.h"
struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size); struct commit_graph *parse_commit_graph(struct repository *r,
void *graph_map, size_t graph_size);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
@ -10,7 +11,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
struct commit_graph *g; struct commit_graph *g;
initialize_the_repository(); initialize_the_repository();
g = parse_commit_graph((void *)data, size); g = parse_commit_graph(the_repository, (void *)data, size);
repo_clear(the_repository); repo_clear(the_repository);
free_commit_graph(g); free_commit_graph(g);