summaryrefslogtreecommitdiff
path: root/builtin/commit-graph.c
diff options
context:
space:
mode:
authorLibravatar Taylor Blau <me@ttaylorr.com>2020-02-03 21:51:50 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-02-04 11:36:37 -0800
commit0bd52e27e315a76d6950fa30ce602eef15d90571 (patch)
treeb47e3464304a349b0e1223e682feb89449b312d8 /builtin/commit-graph.c
parentt5318: don't pass non-object directory to '--object-dir' (diff)
downloadtgif-0bd52e27e315a76d6950fa30ce602eef15d90571.tar.xz
commit-graph.h: store an odb in 'struct write_commit_graph_context'
There are lots of places in 'commit-graph.h' where a function either has (or almost has) a full 'struct object_directory *', accesses '->path', and then throws away the rest of the struct. This can cause headaches when comparing the locations of object directories across alternates (e.g., in the case of deciding if two commit-graph layers can be merged). These paths are normalized with 'normalize_path_copy()' which mitigates some comparison issues, but not all [1]. Replace usage of 'char *object_dir' with 'odb->path' by storing a 'struct object_directory *' in the 'write_commit_graph_context' structure. This is an intermediate step towards getting rid of all path normalization in 'commit-graph.c'. Resolving a user-provided '--object-dir' argument now requires that we compare it to the known alternates for equality. Prior to this patch, an unknown '--object-dir' argument would silently exit with status zero. This can clearly lead to unintended behavior, such as verifying commit-graphs that aren't in a repository's own object store (or one of its alternates), or causing a typo to mask a legitimate commit-graph verification failure. Make this error non-silent by 'die()'-ing when the given '--object-dir' does not match any known alternate object store. [1]: In my testing, for example, I can get one side of the commit-graph code to fill object_dir with "./objects" and the other with just "objects". Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit-graph.c')
-rw-r--r--builtin/commit-graph.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index e0c6fc4bbf..20a3d31b76 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -34,9 +34,29 @@ static struct opts_commit_graph {
int progress;
} opts;
+static struct object_directory *find_odb(struct repository *r,
+ const char *obj_dir)
+{
+ struct object_directory *odb;
+ char *obj_dir_real = real_pathdup(obj_dir, 1);
+
+ prepare_alt_odb(r);
+ for (odb = r->objects->odb; odb; odb = odb->next) {
+ if (!strcmp(obj_dir_real, real_path(odb->path)))
+ break;
+ }
+
+ free(obj_dir_real);
+
+ if (!odb)
+ die(_("could not find object directory matching %s"), obj_dir);
+ return odb;
+}
+
static int graph_verify(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
+ struct object_directory *odb = NULL;
char *graph_name;
int open_ok;
int fd;
@@ -67,7 +87,8 @@ static int graph_verify(int argc, const char **argv)
if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
- graph_name = get_commit_graph_filename(opts.obj_dir);
+ odb = find_odb(the_repository, opts.obj_dir);
+ graph_name = get_commit_graph_filename(odb->path);
open_ok = open_commit_graph(graph_name, &fd, &st);
if (!open_ok && errno != ENOENT)
die_errno(_("Could not open commit-graph '%s'"), graph_name);
@@ -76,8 +97,8 @@ static int graph_verify(int argc, const char **argv)
if (open_ok)
graph = load_commit_graph_one_fd_st(fd, &st);
- else
- graph = read_commit_graph_one(the_repository, opts.obj_dir);
+ else
+ graph = read_commit_graph_one(the_repository, odb->path);
/* Return failure if open_ok predicted success */
if (!graph)
@@ -94,6 +115,7 @@ static int graph_write(int argc, const char **argv)
{
struct string_list *pack_indexes = NULL;
struct string_list *commit_hex = NULL;
+ struct object_directory *odb = NULL;
struct string_list lines;
int result = 0;
enum commit_graph_write_flags flags = 0;
@@ -145,9 +167,10 @@ static int graph_write(int argc, const char **argv)
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
read_replace_refs = 0;
+ odb = find_odb(the_repository, opts.obj_dir);
if (opts.reachable) {
- if (write_commit_graph_reachable(opts.obj_dir, flags, &split_opts))
+ if (write_commit_graph_reachable(odb, flags, &split_opts))
return 1;
return 0;
}
@@ -169,7 +192,7 @@ static int graph_write(int argc, const char **argv)
UNLEAK(buf);
}
- if (write_commit_graph(opts.obj_dir,
+ if (write_commit_graph(odb,
pack_indexes,
commit_hex,
flags,