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>
maint
Taylor Blau 2020-02-03 13:18:04 -08:00 committed by Junio C Hamano
parent ad2dd5bb63
commit a7df60cac8
4 changed files with 14 additions and 14 deletions

View File

@ -96,7 +96,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); graph = load_commit_graph_one_fd_st(fd, &st, odb);
else else
graph = read_commit_graph_one(the_repository, odb); graph = read_commit_graph_one(the_repository, odb);



View File

@ -108,7 +108,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(int fd, struct stat *st,
struct object_directory *odb)
{ {
void *graph_map; void *graph_map;
size_t graph_size; size_t graph_size;
@ -124,7 +125,9 @@ 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);
ret = parse_commit_graph(graph_map, fd, graph_size); ret = parse_commit_graph(graph_map, fd, graph_size);


if (!ret) { if (ret)
ret->odb = odb;
else {
munmap(graph_map, graph_size); munmap(graph_map, graph_size);
close(fd); close(fd);
} }
@ -299,7 +302,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
return graph; return graph;
} }


static struct commit_graph *load_commit_graph_one(const char *graph_file) static struct commit_graph *load_commit_graph_one(const char *graph_file,
struct object_directory *odb)
{ {


struct stat st; struct stat st;
@ -310,7 +314,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); g = load_commit_graph_one_fd_st(fd, &st, odb);


if (g) if (g)
g->filename = xstrdup(graph_file); g->filename = xstrdup(graph_file);
@ -322,12 +326,9 @@ 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); struct commit_graph *g = load_commit_graph_one(graph_name, odb);
free(graph_name); free(graph_name);


if (g)
g->odb = odb;

return g; return g;
} }


@ -406,13 +407,11 @@ 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); struct commit_graph *g = load_commit_graph_one(graph_name, odb);


free(graph_name); free(graph_name);


if (g) { if (g) {
g->odb = odb;

if (add_graph_to_chain(g, graph_chain, oids, i)) { if (add_graph_to_chain(g, graph_chain, oids, i)) {
graph_chain = g; graph_chain = g;
valid = 1; valid = 1;

View File

@ -61,7 +61,8 @@ struct commit_graph {
const unsigned char *chunk_base_graphs; const unsigned char *chunk_base_graphs;
}; };


struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st); struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
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, int fd, struct commit_graph *parse_commit_graph(void *graph_map, int fd,

View File

@ -22,7 +22,7 @@ int cmd__read_graph(int argc, const char **argv)
if (!open_ok) if (!open_ok)
die_errno(_("Could not open commit-graph '%s'"), graph_name); die_errno(_("Could not open commit-graph '%s'"), graph_name);


graph = load_commit_graph_one_fd_st(fd, &st); graph = load_commit_graph_one_fd_st(fd, &st, odb);
if (!graph) if (!graph)
return 1; return 1;