Skip to content

Commit abdd229

Browse files
committed
Merge branch 'ds/commit-graph-write-refactor' into jch
Renamed from commit-graph-format-v2 and changed scope. * ds/commit-graph-write-refactor: commit-graph: extract write_commit_graph_file() commit-graph: extract copy_oids_to_commits() commit-graph: extract count_distinct_commits() commit-graph: extract fill_oids_from_all_packs() commit-graph: extract fill_oids_from_commit_hex() commit-graph: extract fill_oids_from_packs() commit-graph: create write_commit_graph_context commit-graph: remove Future Work section commit-graph: collapse parameters into flags commit-graph: return with errors during write commit-graph: fix the_repository reference
2 parents eb7b070 + 238def5 commit abdd229

File tree

8 files changed

+378
-310
lines changed

8 files changed

+378
-310
lines changed

Documentation/technical/commit-graph.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,6 @@ Design Details
127127
helpful for these clones, anyway. The commit-graph will not be read or
128128
written when shallow commits are present.
129129

130-
Future Work
131-
-----------
132-
133-
- After computing and storing generation numbers, we must make graph
134-
walks aware of generation numbers to gain the performance benefits they
135-
enable. This will mostly be accomplished by swapping a commit-date-ordered
136-
priority queue with one ordered by generation number. The following
137-
operations are important candidates:
138-
139-
- 'log --topo-order'
140-
- 'tag --merged'
141-
142-
- A server could provide a commit-graph file as part of the network protocol
143-
to avoid extra calculations by clients. This feature is only of benefit if
144-
the user is willing to trust the file, because verifying the file is correct
145-
is as hard as computing it from scratch.
146-
147130
Related Links
148131
-------------
149132
[0] https://bugs.chromium.org/p/git/issues/detail?id=8

builtin/commit-graph.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ static int graph_write(int argc, const char **argv)
141141
struct string_list *pack_indexes = NULL;
142142
struct string_list *commit_hex = NULL;
143143
struct string_list lines;
144+
int result = 0;
145+
unsigned int flags = COMMIT_GRAPH_PROGRESS;
144146

145147
static struct option builtin_commit_graph_write_options[] = {
146148
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -165,13 +167,13 @@ static int graph_write(int argc, const char **argv)
165167
die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
166168
if (!opts.obj_dir)
167169
opts.obj_dir = get_object_directory();
170+
if (opts.append)
171+
flags |= COMMIT_GRAPH_APPEND;
168172

169173
read_replace_refs = 0;
170174

171-
if (opts.reachable) {
172-
write_commit_graph_reachable(opts.obj_dir, opts.append, 1);
173-
return 0;
174-
}
175+
if (opts.reachable)
176+
return write_commit_graph_reachable(opts.obj_dir, flags);
175177

176178
string_list_init(&lines, 0);
177179
if (opts.stdin_packs || opts.stdin_commits) {
@@ -188,14 +190,14 @@ static int graph_write(int argc, const char **argv)
188190
UNLEAK(buf);
189191
}
190192

191-
write_commit_graph(opts.obj_dir,
192-
pack_indexes,
193-
commit_hex,
194-
opts.append,
195-
1);
193+
if (write_commit_graph(opts.obj_dir,
194+
pack_indexes,
195+
commit_hex,
196+
flags))
197+
result = 1;
196198

197199
UNLEAK(lines);
198-
return 0;
200+
return result;
199201
}
200202

201203
int cmd_commit_graph(int argc, const char **argv, const char *prefix)

builtin/commit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16691669
"new_index file. Check that disk is not full and quota is\n"
16701670
"not exceeded, and then \"git restore --staged :/\" to recover."));
16711671

1672-
if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
1673-
write_commit_graph_reachable(get_object_directory(), 0, 0);
1672+
if (git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
1673+
write_commit_graph_reachable(get_object_directory(), 0))
1674+
return 1;
16741675

16751676
repo_rerere(the_repository, 0);
16761677
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);

builtin/gc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
685685
clean_pack_garbage();
686686
}
687687

688-
if (gc_write_commit_graph)
689-
write_commit_graph_reachable(get_object_directory(), 0,
690-
!quiet && !daemonized);
688+
if (gc_write_commit_graph &&
689+
write_commit_graph_reachable(get_object_directory(),
690+
!quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0))
691+
return 1;
691692

692693
if (auto_gc && too_many_loose_objects())
693694
warning(_("There are too many unreachable loose objects; "

0 commit comments

Comments
 (0)