Skip to content

Commit 53c3be2

Browse files
committed
Merge branch 'tb/commit-graph-object-dir'
The code to compute the commit-graph has been taught to use a more robust way to tell if two object directories refer to the same thing. * tb/commit-graph-object-dir: commit-graph.h: use odb in 'load_commit_graph_one_fd_st' commit-graph.c: remove path normalization, comparison commit-graph.h: store object directory in 'struct commit_graph' commit-graph.h: store an odb in 'struct write_commit_graph_context' t5318: don't pass non-object directory to '--object-dir'
2 parents 7b029eb + a7df60c commit 53c3be2

File tree

9 files changed

+101
-87
lines changed

9 files changed

+101
-87
lines changed

Documentation/git-commit-graph.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ OPTIONS
2626
file. This parameter exists to specify the location of an alternate
2727
that only has the objects directory, not a full `.git` directory. The
2828
commit-graph file is expected to be in the `<dir>/info` directory and
29-
the packfiles are expected to be in `<dir>/pack`.
29+
the packfiles are expected to be in `<dir>/pack`. If the directory
30+
could not be made into an absolute path, or does not match any known
31+
object directory, `git commit-graph ...` will exit with non-zero
32+
status.
3033

3134
--[no-]progress::
3235
Turn progress on/off explicitly. If neither is specified, progress is

builtin/commit-graph.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,29 @@ static struct opts_commit_graph {
3434
int progress;
3535
} opts;
3636

37+
static struct object_directory *find_odb(struct repository *r,
38+
const char *obj_dir)
39+
{
40+
struct object_directory *odb;
41+
char *obj_dir_real = real_pathdup(obj_dir, 1);
42+
43+
prepare_alt_odb(r);
44+
for (odb = r->objects->odb; odb; odb = odb->next) {
45+
if (!strcmp(obj_dir_real, real_path(odb->path)))
46+
break;
47+
}
48+
49+
free(obj_dir_real);
50+
51+
if (!odb)
52+
die(_("could not find object directory matching %s"), obj_dir);
53+
return odb;
54+
}
55+
3756
static int graph_verify(int argc, const char **argv)
3857
{
3958
struct commit_graph *graph = NULL;
59+
struct object_directory *odb = NULL;
4060
char *graph_name;
4161
int open_ok;
4262
int fd;
@@ -67,17 +87,18 @@ static int graph_verify(int argc, const char **argv)
6787
if (opts.progress)
6888
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
6989

70-
graph_name = get_commit_graph_filename(opts.obj_dir);
90+
odb = find_odb(the_repository, opts.obj_dir);
91+
graph_name = get_commit_graph_filename(odb);
7192
open_ok = open_commit_graph(graph_name, &fd, &st);
7293
if (!open_ok && errno != ENOENT)
7394
die_errno(_("Could not open commit-graph '%s'"), graph_name);
7495

7596
FREE_AND_NULL(graph_name);
7697

7798
if (open_ok)
78-
graph = load_commit_graph_one_fd_st(fd, &st);
79-
else
80-
graph = read_commit_graph_one(the_repository, opts.obj_dir);
99+
graph = load_commit_graph_one_fd_st(fd, &st, odb);
100+
else
101+
graph = read_commit_graph_one(the_repository, odb);
81102

82103
/* Return failure if open_ok predicted success */
83104
if (!graph)
@@ -94,6 +115,7 @@ static int graph_write(int argc, const char **argv)
94115
{
95116
struct string_list *pack_indexes = NULL;
96117
struct string_list *commit_hex = NULL;
118+
struct object_directory *odb = NULL;
97119
struct string_list lines;
98120
int result = 0;
99121
enum commit_graph_write_flags flags = 0;
@@ -145,9 +167,10 @@ static int graph_write(int argc, const char **argv)
145167
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
146168

147169
read_replace_refs = 0;
170+
odb = find_odb(the_repository, opts.obj_dir);
148171

149172
if (opts.reachable) {
150-
if (write_commit_graph_reachable(opts.obj_dir, flags, &split_opts))
173+
if (write_commit_graph_reachable(odb, flags, &split_opts))
151174
return 1;
152175
return 0;
153176
}
@@ -169,7 +192,7 @@ static int graph_write(int argc, const char **argv)
169192
UNLEAK(buf);
170193
}
171194

172-
if (write_commit_graph(opts.obj_dir,
195+
if (write_commit_graph(odb,
173196
pack_indexes,
174197
commit_hex,
175198
flags,

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16931693
"not exceeded, and then \"git restore --staged :/\" to recover."));
16941694

16951695
if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
1696-
write_commit_graph_reachable(get_object_directory(), 0, NULL))
1696+
write_commit_graph_reachable(the_repository->objects->odb, 0, NULL))
16971697
return 1;
16981698

16991699
repo_rerere(the_repository, 0);

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
18791879
if (progress)
18801880
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
18811881

1882-
write_commit_graph_reachable(get_object_directory(),
1882+
write_commit_graph_reachable(the_repository->objects->odb,
18831883
commit_graph_flags,
18841884
NULL);
18851885
}

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
686686

687687
prepare_repo_settings(the_repository);
688688
if (the_repository->settings.gc_write_commit_graph == 1)
689-
write_commit_graph_reachable(get_object_directory(),
689+
write_commit_graph_reachable(the_repository->objects->odb,
690690
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
691691
NULL);
692692

0 commit comments

Comments
 (0)