Skip to content

Commit 7c5bc06

Browse files
committed
commit-graph: add --split option
Signed-off-by: Derrick Stolee <[email protected]>
1 parent aa4a096 commit 7c5bc06

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

builtin/commit-graph.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static char const * const builtin_commit_graph_usage[] = {
1010
N_("git commit-graph [--object-dir <objdir>]"),
1111
N_("git commit-graph read [--object-dir <objdir>]"),
1212
N_("git commit-graph verify [--object-dir <objdir>]"),
13-
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
13+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits]"),
1414
NULL
1515
};
1616

@@ -25,7 +25,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
2525
};
2626

2727
static const char * const builtin_commit_graph_write_usage[] = {
28-
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
28+
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits]"),
2929
NULL
3030
};
3131

@@ -35,9 +35,9 @@ static struct opts_commit_graph {
3535
int stdin_packs;
3636
int stdin_commits;
3737
int append;
38+
int split;
3839
} opts;
3940

40-
4141
static int graph_verify(int argc, const char **argv)
4242
{
4343
struct commit_graph *graph = NULL;
@@ -156,6 +156,8 @@ static int graph_write(int argc, const char **argv)
156156
N_("start walk at commits listed by stdin")),
157157
OPT_BOOL(0, "append", &opts.append,
158158
N_("include all commits already in the commit-graph file")),
159+
OPT_BOOL(0, "split", &opts.split,
160+
N_("allow writing an incremental commit-graph file")),
159161
OPT_END(),
160162
};
161163

@@ -169,6 +171,8 @@ static int graph_write(int argc, const char **argv)
169171
opts.obj_dir = get_object_directory();
170172
if (opts.append)
171173
flags |= COMMIT_GRAPH_APPEND;
174+
if (opts.split)
175+
flags |= COMMIT_GRAPH_SPLIT;
172176

173177
read_replace_refs = 0;
174178

t/t5318-commit-graph.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,32 @@ test_expect_success 'check that gc computes commit-graph' '
260260
test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
261261
'
262262

263+
test_expect_success 'write split commit-graph' '
264+
cd "$TRASH_DIRECTORY" &&
265+
git clone full split &&
266+
cd split &&
267+
git config core.commitGraph true &&
268+
for i in $(test_seq 1 20); do
269+
test_commit padding-$i
270+
done &&
271+
git commit-graph write --reachable &&
272+
test_commit split-commit &&
273+
git branch -f split-commit &&
274+
git commit-graph write --reachable --split &&
275+
test_path_is_file .git/objects/info/commit-graphs/commit-graph-1
276+
'
277+
278+
graph_git_behavior 'split graph, split-commit vs merge 1' bare split-commit merge/1
279+
280+
test_expect_success 'collapse split commit-graph' '
281+
cd "$TRASH_DIRECTORY/split" &&
282+
git commit-graph write --reachable &&
283+
test_path_is_missing .git/objects/info/commit-graphs/commit-graph-1 &&
284+
test_path_is_file .git/objects/info/commit-graph
285+
'
286+
287+
graph_git_behavior 'collapsed graph, split-commit vs merge 1' bare split-commit merge/1
288+
263289
test_expect_success 'replace-objects invalidates commit-graph' '
264290
cd "$TRASH_DIRECTORY" &&
265291
test_when_finished rm -rf replace &&

0 commit comments

Comments
 (0)