]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph.h: use odb in 'load_commit_graph_one_fd_st'
authorTaylor Blau <me@ttaylorr.com>
Mon, 3 Feb 2020 21:18:04 +0000 (13:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Feb 2020 19:36:51 +0000 (11:36 -0800)
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>
builtin/commit-graph.c
commit-graph.c
commit-graph.h
t/helper/test-read-graph.c

index e622ed90b89c3793604ad1567803b12526504012..4a70b33fb5f1359397742fcf8601c4c1d49109fe 100644 (file)
@@ -96,7 +96,7 @@ static int graph_verify(int argc, const char **argv)
        FREE_AND_NULL(graph_name);
 
        if (open_ok)
-               graph = load_commit_graph_one_fd_st(fd, &st);
+               graph = load_commit_graph_one_fd_st(fd, &st, odb);
        else
                graph = read_commit_graph_one(the_repository, odb);
 
index 49541760b5deecf09e97edafeeddf6ecc56b2c05..656dd647d53b89d67a2d7222ba0e19d00eaa8dbc 100644 (file)
@@ -108,7 +108,8 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
        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;
        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);
        ret = parse_commit_graph(graph_map, fd, graph_size);
 
-       if (!ret) {
+       if (ret)
+               ret->odb = odb;
+       else {
                munmap(graph_map, graph_size);
                close(fd);
        }
@@ -299,7 +302,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
        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;
@@ -310,7 +314,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file)
        if (!open_ok)
                return NULL;
 
-       g = load_commit_graph_one_fd_st(fd, &st);
+       g = load_commit_graph_one_fd_st(fd, &st, odb);
 
        if (g)
                g->filename = xstrdup(graph_file);
@@ -322,12 +326,9 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
                                                 struct object_directory *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);
 
-       if (g)
-               g->odb = odb;
-
        return g;
 }
 
@@ -406,13 +407,11 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
                valid = 0;
                for (odb = r->objects->odb; odb; odb = odb->next) {
                        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);
 
                        if (g) {
-                               g->odb = odb;
-
                                if (add_graph_to_chain(g, graph_chain, oids, i)) {
                                        graph_chain = g;
                                        valid = 1;
index 5a690723b00a2739d7cc4c36916478fac155f1ee..e87a6f636000d68137fe3ec437b02e439a8171a5 100644 (file)
@@ -61,7 +61,8 @@ struct commit_graph {
        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 object_directory *odb);
 struct commit_graph *parse_commit_graph(void *graph_map, int fd,
index 2c2f65f06c460031e4a3ec9e9b8d2ff651924f36..f8a461767ca44571193005e3c3d2fb74d775f9de 100644 (file)
@@ -22,7 +22,7 @@ int cmd__read_graph(int argc, const char **argv)
        if (!open_ok)
                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)
                return 1;