commit-graph.h: use odb in 'load_commit_graph_one_fd_st'
Apply a similar treatment as in the previous patch to pass a 'struct object_directory *' through the 'load_commit_graph_one_fd_st' initializer, too. This prevents a potential bug where a pointer comparison is made to a NULL 'g->odb', which would cause the commit-graph machinery to think that a pair of commit-graphs belonged to different alternates when in fact they do not (i.e., in the case of no '--object-dir'). Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Feb 3, 2020 at 13:18 UTC
a7df60cac834cb7f91c3463205c2b6ba5e694200
4 files changed
+14
-14
builtin/commit-graph.c
+1
-1
@@ -96,7 +96,7 @@ static int graph_verify(int argc, const char **argv)
96
FREE_AND_NULL(graph_name);
97
98
if (open_ok)
99
- graph = load_commit_graph_one_fd_st(fd, &st);
99
+ graph = load_commit_graph_one_fd_st(fd, &st, odb);
100
else
101
graph = read_commit_graph_one(the_repository, odb);
102
commit-graph.c
+10
-11
@@ -108,7 +108,8 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
108
return 1;
109
}
110
111
-struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st)
111
+struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
112
+ struct object_directory *odb)
113
{
114
void *graph_map;
115
size_t graph_size;
@@ -124,7 +125,9 @@ struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st)
125
graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
126
ret = parse_commit_graph(graph_map, fd, graph_size);
127
127
- if (!ret) {
128
+ if (ret)
129
+ ret->odb = odb;
130
+ else {
131
munmap(graph_map, graph_size);
132
close(fd);
133
}
@@ -299,7 +302,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
302
return graph;
303
}
304
302
-static struct commit_graph *load_commit_graph_one(const char *graph_file)
305
+static struct commit_graph *load_commit_graph_one(const char *graph_file,
306
+ struct object_directory *odb)
307
{
308
309
struct stat st;
@@ -310,7 +314,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file)
314
if (!open_ok)
315
return NULL;
316
313
- g = load_commit_graph_one_fd_st(fd, &st);
317
+ g = load_commit_graph_one_fd_st(fd, &st, odb);
318
319
if (g)
320
g->filename = xstrdup(graph_file);
@@ -322,12 +326,9 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
326
struct object_directory *odb)
327
{
328
char *graph_name = get_commit_graph_filename(odb);
325
- struct commit_graph *g = load_commit_graph_one(graph_name);
329
+ struct commit_graph *g = load_commit_graph_one(graph_name, odb);
330
free(graph_name);
331
328
- if (g)
329
- g->odb = odb;
330
-
332
return g;
333
}
334
@@ -406,13 +407,11 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
407
valid = 0;
408
for (odb = r->objects->odb; odb; odb = odb->next) {
409
char *graph_name = get_split_graph_filename(odb, line.buf);
409
- struct commit_graph *g = load_commit_graph_one(graph_name);
410
+ struct commit_graph *g = load_commit_graph_one(graph_name, odb);
411
412
free(graph_name);
413
414
if (g) {
414
- g->odb = odb;
415
-
415
if (add_graph_to_chain(g, graph_chain, oids, i)) {
416
graph_chain = g;
417
valid = 1;
commit-graph.h
+2
-1
@@ -61,7 +61,8 @@ struct commit_graph {
61
const unsigned char *chunk_base_graphs;
62
};
63
64
-struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st);
64
+struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
65
+ struct object_directory *odb);
66
struct commit_graph *read_commit_graph_one(struct repository *r,
67
struct object_directory *odb);
68
struct commit_graph *parse_commit_graph(void *graph_map, int fd,
t/helper/test-read-graph.c
+1
-1
@@ -22,7 +22,7 @@ int cmd__read_graph(int argc, const char **argv)
22
if (!open_ok)
23
die_errno(_("Could not open commit-graph '%s'"), graph_name);
24
25
- graph = load_commit_graph_one_fd_st(fd, &st);
25
+ graph = load_commit_graph_one_fd_st(fd, &st, odb);
26
if (!graph)
27
return 1;
28