Skip to content

Commit 1bb6b90

Browse files
committed
Merge branch 'tb/commit-graph-object-dir' into pu
* 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 an odb in 'struct write_commit_graph_context' builtin/commit-graph.c: die() with unknown '--object-dir' commit-graph.h: store object directory in 'struct commit_graph' t5318: don't pass non-object directory to '--object-dir'
2 parents 6f78d05 + 99aa752 commit 1bb6b90

File tree

9 files changed

+114
-87
lines changed

9 files changed

+114
-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: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ static struct opts_commit_graph {
3434
int progress;
3535
} opts;
3636

37+
static struct object_directory *find_odb_or_die(struct repository *r,
38+
const char *obj_dir)
39+
{
40+
struct object_directory *odb = find_odb(r, obj_dir);
41+
if (!odb)
42+
die(_("could not find object directory matching %s"), obj_dir);
43+
return odb;
44+
}
45+
3746
static int graph_verify(int argc, const char **argv)
3847
{
3948
struct commit_graph *graph = NULL;
49+
struct object_directory *odb = NULL;
4050
char *graph_name;
4151
int open_ok;
4252
int fd;
@@ -67,17 +77,18 @@ static int graph_verify(int argc, const char **argv)
6777
if (opts.progress)
6878
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
6979

70-
graph_name = get_commit_graph_filename(opts.obj_dir);
80+
odb = find_odb_or_die(the_repository, opts.obj_dir);
81+
graph_name = get_commit_graph_filename(odb);
7182
open_ok = open_commit_graph(graph_name, &fd, &st);
7283
if (!open_ok && errno != ENOENT)
7384
die_errno(_("Could not open commit-graph '%s'"), graph_name);
7485

7586
FREE_AND_NULL(graph_name);
7687

7788
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);
89+
graph = load_commit_graph_one_fd_st(fd, &st, odb);
90+
else
91+
graph = read_commit_graph_one(the_repository, odb);
8192

8293
/* Return failure if open_ok predicted success */
8394
if (!graph)
@@ -97,6 +108,7 @@ static int graph_write(int argc, const char **argv)
97108
struct string_list lines;
98109
int result = 0;
99110
enum commit_graph_write_flags flags = 0;
111+
struct object_directory *odb = NULL;
100112

101113
static struct option builtin_commit_graph_write_options[] = {
102114
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -145,9 +157,10 @@ static int graph_write(int argc, const char **argv)
145157
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
146158

147159
read_replace_refs = 0;
160+
odb = find_odb_or_die(the_repository, opts.obj_dir);
148161

149162
if (opts.reachable) {
150-
if (write_commit_graph_reachable(opts.obj_dir, flags, &split_opts))
163+
if (write_commit_graph_reachable(odb, flags, &split_opts))
151164
return 1;
152165
return 0;
153166
}
@@ -169,7 +182,7 @@ static int graph_write(int argc, const char **argv)
169182
UNLEAK(buf);
170183
}
171184

172-
if (write_commit_graph(opts.obj_dir,
185+
if (write_commit_graph(odb,
173186
pack_indexes,
174187
commit_hex,
175188
flags,

builtin/commit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "help.h"
3737
#include "commit-reach.h"
3838
#include "commit-graph.h"
39+
#include "object-store.h"
3940

4041
static const char * const builtin_commit_usage[] = {
4142
N_("git commit [<options>] [--] <pathspec>..."),
@@ -1727,7 +1728,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17271728
"not exceeded, and then \"git restore --staged :/\" to recover."));
17281729

17291730
if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
1730-
write_commit_graph_reachable(get_object_directory(), 0, NULL))
1731+
write_commit_graph_reachable(the_repository->objects->odb, 0, NULL))
17311732
return 1;
17321733

17331734
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)