Skip to content

Commit a7df60c

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad2dd5b commit a7df60c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

builtin/commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int graph_verify(int argc, const char **argv)
9696
FREE_AND_NULL(graph_name);
9797

9898
if (open_ok)
99-
graph = load_commit_graph_one_fd_st(fd, &st);
99+
graph = load_commit_graph_one_fd_st(fd, &st, odb);
100100
else
101101
graph = read_commit_graph_one(the_repository, odb);
102102

commit-graph.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
108108
return 1;
109109
}
110110

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)
112113
{
113114
void *graph_map;
114115
size_t graph_size;
@@ -124,7 +125,9 @@ struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st)
124125
graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
125126
ret = parse_commit_graph(graph_map, fd, graph_size);
126127

127-
if (!ret) {
128+
if (ret)
129+
ret->odb = odb;
130+
else {
128131
munmap(graph_map, graph_size);
129132
close(fd);
130133
}
@@ -299,7 +302,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
299302
return graph;
300303
}
301304

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)
303307
{
304308

305309
struct stat st;
@@ -310,7 +314,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file)
310314
if (!open_ok)
311315
return NULL;
312316

313-
g = load_commit_graph_one_fd_st(fd, &st);
317+
g = load_commit_graph_one_fd_st(fd, &st, odb);
314318

315319
if (g)
316320
g->filename = xstrdup(graph_file);
@@ -322,12 +326,9 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
322326
struct object_directory *odb)
323327
{
324328
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);
326330
free(graph_name);
327331

328-
if (g)
329-
g->odb = odb;
330-
331332
return g;
332333
}
333334

@@ -406,13 +407,11 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
406407
valid = 0;
407408
for (odb = r->objects->odb; odb; odb = odb->next) {
408409
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);
410411

411412
free(graph_name);
412413

413414
if (g) {
414-
g->odb = odb;
415-
416415
if (add_graph_to_chain(g, graph_chain, oids, i)) {
417416
graph_chain = g;
418417
valid = 1;

commit-graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ struct commit_graph {
6161
const unsigned char *chunk_base_graphs;
6262
};
6363

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);
6566
struct commit_graph *read_commit_graph_one(struct repository *r,
6667
struct object_directory *odb);
6768
struct commit_graph *parse_commit_graph(void *graph_map, int fd,

t/helper/test-read-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int cmd__read_graph(int argc, const char **argv)
2222
if (!open_ok)
2323
die_errno(_("Could not open commit-graph '%s'"), graph_name);
2424

25-
graph = load_commit_graph_one_fd_st(fd, &st);
25+
graph = load_commit_graph_one_fd_st(fd, &st, odb);
2626
if (!graph)
2727
return 1;
2828

0 commit comments

Comments
 (0)