From: Derrick Stolee <dsto...@microsoft.com>

Signed-off-by: Derrick Stolee <dsto...@microsoft.com>
---
 builtin/commit-graph.c  | 10 +++++++---
 t/t5318-commit-graph.sh | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 828b1a713f..c2c07d3917 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -10,7 +10,7 @@ static char const * const builtin_commit_graph_usage[] = {
        N_("git commit-graph [--object-dir <objdir>]"),
        N_("git commit-graph read [--object-dir <objdir>]"),
        N_("git commit-graph verify [--object-dir <objdir>]"),
-       N_("git commit-graph write [--object-dir <objdir>] [--append] 
[--reachable|--stdin-packs|--stdin-commits]"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] 
[--reachable|--stdin-packs|--stdin-commits]"),
        NULL
 };
 
@@ -25,7 +25,7 @@ static const char * const builtin_commit_graph_read_usage[] = 
{
 };
 
 static const char * const builtin_commit_graph_write_usage[] = {
-       N_("git commit-graph write [--object-dir <objdir>] [--append] 
[--reachable|--stdin-packs|--stdin-commits]"),
+       N_("git commit-graph write [--object-dir <objdir>] [--append|--split] 
[--reachable|--stdin-packs|--stdin-commits]"),
        NULL
 };
 
@@ -35,9 +35,9 @@ static struct opts_commit_graph {
        int stdin_packs;
        int stdin_commits;
        int append;
+       int split;
 } opts;
 
-
 static int graph_verify(int argc, const char **argv)
 {
        struct commit_graph *graph = NULL;
@@ -156,6 +156,8 @@ static int graph_write(int argc, const char **argv)
                        N_("start walk at commits listed by stdin")),
                OPT_BOOL(0, "append", &opts.append,
                        N_("include all commits already in the commit-graph 
file")),
+               OPT_BOOL(0, "split", &opts.split,
+                       N_("allow writing an incremental commit-graph file")),
                OPT_END(),
        };
 
@@ -169,6 +171,8 @@ static int graph_write(int argc, const char **argv)
                opts.obj_dir = get_object_directory();
        if (opts.append)
                flags |= COMMIT_GRAPH_APPEND;
+       if (opts.split)
+               flags |= COMMIT_GRAPH_SPLIT;
 
        read_replace_refs = 0;
 
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index d621608500..9dfd4cc9b1 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -260,6 +260,32 @@ test_expect_success 'check that gc computes commit-graph' '
        test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
 '
 
+test_expect_success 'write split commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       git clone full split &&
+       cd split &&
+       git config core.commitGraph true &&
+       for i in $(test_seq 1 20); do
+               test_commit padding-$i
+       done &&
+       git commit-graph write --reachable &&
+       test_commit split-commit &&
+       git branch -f split-commit &&
+       git commit-graph write --reachable --split &&
+       test_path_is_file .git/objects/info/commit-graphs/commit-graph-1
+'
+
+graph_git_behavior 'split graph, split-commit vs merge 1' bare split-commit 
merge/1
+
+test_expect_success 'collapse split commit-graph' '
+       cd "$TRASH_DIRECTORY/split" &&
+       git commit-graph write --reachable &&
+       test_path_is_missing .git/objects/info/commit-graphs/commit-graph-1 &&
+       test_path_is_file .git/objects/info/commit-graph
+'
+
+graph_git_behavior 'collapsed graph, split-commit vs merge 1' bare 
split-commit merge/1
+
 test_expect_success 'replace-objects invalidates commit-graph' '
        cd "$TRASH_DIRECTORY" &&
        test_when_finished rm -rf replace &&
-- 
gitgitgadget

Reply via email to