Skip to content

Commit

Permalink
Merge branch 'tb/commit-graph-object-dir'
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
gitster committed Feb 14, 2020
2 parents 7b029eb + a7df60c commit 53c3be2
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 87 deletions.
5 changes: 4 additions & 1 deletion Documentation/git-commit-graph.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ OPTIONS
file. This parameter exists to specify the location of an alternate
that only has the objects directory, not a full `.git` directory. The
commit-graph file is expected to be in the `<dir>/info` directory and
the packfiles are expected to be in `<dir>/pack`.
the packfiles are expected to be in `<dir>/pack`. If the directory
could not be made into an absolute path, or does not match any known
object directory, `git commit-graph ...` will exit with non-zero
status.

--[no-]progress::
Turn progress on/off explicitly. If neither is specified, progress is
Expand Down
35 changes: 29 additions & 6 deletions builtin/commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,17 +87,18 @@ 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);
open_ok = open_commit_graph(graph_name, &fd, &st);
if (!open_ok && errno != ENOENT)
die_errno(_("Could not open commit-graph '%s'"), graph_name);

FREE_AND_NULL(graph_name);

if (open_ok)
graph = load_commit_graph_one_fd_st(fd, &st);
else
graph = read_commit_graph_one(the_repository, opts.obj_dir);
graph = load_commit_graph_one_fd_st(fd, &st, odb);
else
graph = read_commit_graph_one(the_repository, odb);

/* Return failure if open_ok predicted success */
if (!graph)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
"not exceeded, and then \"git restore --staged :/\" to recover."));

if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
write_commit_graph_reachable(get_object_directory(), 0, NULL))
write_commit_graph_reachable(the_repository->objects->odb, 0, NULL))
return 1;

repo_rerere(the_repository, 0);
Expand Down
2 changes: 1 addition & 1 deletion builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
if (progress)
commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;

write_commit_graph_reachable(get_object_directory(),
write_commit_graph_reachable(the_repository->objects->odb,
commit_graph_flags,
NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)

prepare_repo_settings(the_repository);
if (the_repository->settings.gc_write_commit_graph == 1)
write_commit_graph_reachable(get_object_directory(),
write_commit_graph_reachable(the_repository->objects->odb,
!quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
NULL);

Expand Down

0 comments on commit 53c3be2

Please sign in to comment.