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>
Taylor Blau committed
Sep 9, 2020 at 11:22 UTC
ab14d0676c58389e6f0ccbb9569b07045a05b6df
4 files changed
+18
-12
builtin/commit-graph.c
+1
-1
@@ -106,7 +106,7 @@ static int graph_verify(int argc, const char **argv)
106
FREE_AND_NULL(graph_name);
107
108
if (open_ok)
109
- graph = load_commit_graph_one_fd_st(fd, &st, odb);
109
+ graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb);
110
else
111
graph = read_commit_graph_one(the_repository, odb);
112
commit-graph.c
+10
-7
@@ -224,7 +224,8 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
224
return 1;
225
}
226
227
-struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
227
+struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
228
+ int fd, struct stat *st,
229
struct object_directory *odb)
230
{
231
void *graph_map;
@@ -240,7 +241,7 @@ struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
241
}
242
graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
243
close(fd);
243
- ret = parse_commit_graph(graph_map, graph_size);
244
+ ret = parse_commit_graph(r, graph_map, graph_size);
245
246
if (ret)
247
ret->odb = odb;
@@ -280,7 +281,8 @@ static int verify_commit_graph_lite(struct commit_graph *g)
281
return 0;
282
}
283
283
-struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size)
284
+struct commit_graph *parse_commit_graph(struct repository *r,
285
+ void *graph_map, size_t graph_size)
286
{
287
const unsigned char *data, *chunk_lookup;
288
uint32_t i;
@@ -445,7 +447,8 @@ free_and_return:
447
return NULL;
448
}
449
448
-static struct commit_graph *load_commit_graph_one(const char *graph_file,
450
+static struct commit_graph *load_commit_graph_one(struct repository *r,
451
+ const char *graph_file,
452
struct object_directory *odb)
453
{
454
@@ -457,7 +460,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file,
460
if (!open_ok)
461
return NULL;
462
460
- g = load_commit_graph_one_fd_st(fd, &st, odb);
463
+ g = load_commit_graph_one_fd_st(r, fd, &st, odb);
464
465
if (g)
466
g->filename = xstrdup(graph_file);
@@ -469,7 +472,7 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
472
struct object_directory *odb)
473
{
474
char *graph_name = get_commit_graph_filename(odb);
472
- struct commit_graph *g = load_commit_graph_one(graph_name, odb);
475
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
476
free(graph_name);
477
478
return g;
@@ -550,7 +553,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
553
valid = 0;
554
for (odb = r->objects->odb; odb; odb = odb->next) {
555
char *graph_name = get_split_graph_filename(odb, line.buf);
553
- struct commit_graph *g = load_commit_graph_one(graph_name, odb);
556
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
557
558
free(graph_name);
559
commit-graph.h
+4
-2
@@ -75,11 +75,13 @@ struct commit_graph {
75
struct bloom_filter_settings *bloom_filter_settings;
76
};
77
78
-struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
78
+struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
79
+ int fd, struct stat *st,
80
struct object_directory *odb);
81
struct commit_graph *read_commit_graph_one(struct repository *r,
82
struct object_directory *odb);
82
-struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size);
83
+struct commit_graph *parse_commit_graph(struct repository *r,
84
+ void *graph_map, size_t graph_size);
85
86
/*
87
* Return 1 if and only if the repository has a commit-graph
fuzz-commit-graph.c
+3
-2
@@ -1,7 +1,8 @@
1
#include "commit-graph.h"
2
#include "repository.h"
3
4
-struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size);
4
+struct commit_graph *parse_commit_graph(struct repository *r,
5
+ void *graph_map, size_t graph_size);
6
7
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
8
@@ -10,7 +11,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
11
struct commit_graph *g;
12
13
initialize_the_repository();
13
- g = parse_commit_graph((void *)data, size);
14
+ g = parse_commit_graph(the_repository, (void *)data, size);
15
repo_clear(the_repository);
16
free_commit_graph(g);
17