Skip to content

Commit 59dd3aa

Browse files
ttaylorrgitster
authored andcommitted
builtin/commit-graph.c: support '--input=none'
In the previous commit, we introduced '--split=<no-merge|merge-all>', and alluded to the fact that '--split=merge-all' would be useful for callers who wish to always trigger a merge of an incremental chain. There is a problem with the above approach, which is that there is no way to specify to the commit-graph builtin that a caller only wants to include commits already in the graph. One can specify '--input=append' to include all commits in the existing graphs, but the absence of '--input=stdin-{commits,packs}' causes the builtin to call 'fill_oids_from_all_packs()'. Passing '--input=reachable' (as in 'git commit-graph write --split=merge-all --input=reachable --input=append') works around this issue by making '--input=reachable' effectively a no-op, but this can be prohibitively expensive in large repositories, making it an undesirable choice for some users. Teach '--input=none' as an option to behave as if '--input=append' were given, but to consider no other sources in addition. This, in conjunction with the option introduced in the previous patch offers the convenient way to force the commit-graph machinery to condense a chain of incrementals without requiring any new commits: $ git commit-graph write --split=merge-all --input=none Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f91b48 commit 59dd3aa

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

Documentation/git-commit-graph.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ COMMANDS
3939
--------
4040
'write'::
4141

42-
Write a commit-graph file based on the commits found in packfiles.
42+
Write a commit-graph file based on the specified sources of input:
4343
+
4444
With the `--input=stdin-packs` option, generate the new commit graph by
4545
walking objects only in the specified pack-indexes. (Cannot be combined
@@ -57,6 +57,12 @@ walking commits starting at all refs. (Cannot be combined with
5757
With the `--input=append` option, include all commits that are present
5858
in the existing commit-graph file.
5959
+
60+
With the `--input=none` option, behave as if `--input=append` were
61+
given, but do not walk other packs to find additional commits.
62+
63+
If none of the above options are given, then generate the new
64+
commit-graph by walking over all pack-indexes.
65+
+
6066
With the `--split[=<strategy>]` option, write the commit-graph as a
6167
chain of multiple commit-graph files stored in
6268
`<dir>/info/commit-graphs`. Commit-graph layers are merged based on the

builtin/commit-graph.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static char const * const builtin_commit_graph_usage[] = {
1111
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
1212
N_("git commit-graph write [--object-dir <objdir>] "
1313
"[--split[=<strategy>]] "
14-
"[--input=<reachable|stdin-packs|stdin-commits|append>] "
14+
"[--input=<reachable|stdin-packs|stdin-commits|append|none>] "
1515
"[--[no-]progress] <split options>"),
1616
NULL
1717
};
@@ -24,7 +24,7 @@ static const char * const builtin_commit_graph_verify_usage[] = {
2424
static const char * const builtin_commit_graph_write_usage[] = {
2525
N_("git commit-graph write [--object-dir <objdir>] "
2626
"[--split[=<strategy>]] "
27-
"[--input=<reachable|stdin-packs|stdin-commits|append>] "
27+
"[--input=<reachable|stdin-packs|stdin-commits|append|none>] "
2828
"[--[no-]progress] <split options>"),
2929
NULL
3030
};
@@ -33,7 +33,8 @@ enum commit_graph_input {
3333
COMMIT_GRAPH_INPUT_REACHABLE = (1 << 1),
3434
COMMIT_GRAPH_INPUT_STDIN_PACKS = (1 << 2),
3535
COMMIT_GRAPH_INPUT_STDIN_COMMITS = (1 << 3),
36-
COMMIT_GRAPH_INPUT_APPEND = (1 << 4)
36+
COMMIT_GRAPH_INPUT_APPEND = (1 << 4),
37+
COMMIT_GRAPH_INPUT_NONE = (1 << 5)
3738
};
3839

3940
static struct opts_commit_graph {
@@ -80,6 +81,8 @@ static int option_parse_input(const struct option *opt, const char *arg,
8081
*to |= COMMIT_GRAPH_INPUT_STDIN_COMMITS;
8182
else if (!strcmp(arg, "append"))
8283
*to |= COMMIT_GRAPH_INPUT_APPEND;
84+
else if (!strcmp(arg, "none"))
85+
*to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_NONE);
8386
else
8487
die(_("unrecognized --input source, %s"), arg);
8588
return 0;
@@ -225,6 +228,8 @@ static int graph_write(int argc, const char **argv)
225228
opts.obj_dir = get_object_directory();
226229
if (opts.input & COMMIT_GRAPH_INPUT_APPEND)
227230
flags |= COMMIT_GRAPH_WRITE_APPEND;
231+
if (opts.input & COMMIT_GRAPH_INPUT_NONE)
232+
flags |= COMMIT_GRAPH_WRITE_NO_INPUT;
228233
if (opts.split)
229234
flags |= COMMIT_GRAPH_WRITE_SPLIT;
230235
if (opts.progress)

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ struct write_commit_graph_context {
788788
unsigned append:1,
789789
report_progress:1,
790790
split:1,
791-
check_oids:1;
791+
check_oids:1,
792+
no_input:1;
792793

793794
const struct split_commit_graph_opts *split_opts;
794795
};
@@ -1785,6 +1786,7 @@ int write_commit_graph(struct object_directory *odb,
17851786
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
17861787
ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
17871788
ctx->split_opts = split_opts;
1789+
ctx->no_input = flags & COMMIT_GRAPH_WRITE_NO_INPUT ? 1 : 0;
17881790

17891791
if (ctx->split) {
17901792
struct commit_graph *g;
@@ -1843,7 +1845,7 @@ int write_commit_graph(struct object_directory *odb,
18431845
goto cleanup;
18441846
}
18451847

1846-
if (!pack_indexes && !commit_hex)
1848+
if (!ctx->no_input && !pack_indexes && !commit_hex)
18471849
fill_oids_from_all_packs(ctx);
18481850

18491851
close_reachable(ctx);

commit-graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ enum commit_graph_write_flags {
7979
COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
8080
COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
8181
/* Make sure that each OID in the input is a valid commit OID. */
82-
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
82+
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
83+
COMMIT_GRAPH_WRITE_NO_INPUT = (1 << 4)
8384
};
8485

8586
enum commit_graph_split_flags {

t/t5324-split-commit-graph.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,30 @@ test_expect_success '--split=no-merge always writes an incremental' '
369369
test_line_count = 2 $graphdir/commit-graph-chain
370370
'
371371

372+
test_expect_success '--split=no-merge, --input=none writes nothing' '
373+
test_when_finished rm -rf a graphs.before graphs.after &&
374+
rm -rf $graphdir &&
375+
git reset --hard commits/2 &&
376+
git rev-list -1 HEAD~1 >a &&
377+
git commit-graph write --split=no-merge --input=stdin-commits <a &&
378+
ls $graphdir/graph-*.graph >graphs.before &&
379+
test_line_count = 1 $graphdir/commit-graph-chain &&
380+
git commit-graph write --split --input=none &&
381+
ls $graphdir/graph-*.graph >graphs.after &&
382+
test_cmp graphs.before graphs.after
383+
'
384+
385+
test_expect_success '--split=merge-all, --input=none merges the chain' '
386+
test_when_finished rm -rf a b &&
387+
rm -rf $graphdir &&
388+
git reset --hard commits/2 &&
389+
git rev-list -1 HEAD~1 >a &&
390+
git rev-list -1 HEAD >b &&
391+
git commit-graph write --split=no-merge --input=stdin-commits <a &&
392+
git commit-graph write --split=no-merge --input=stdin-commits <b &&
393+
test_line_count = 2 $graphdir/commit-graph-chain &&
394+
git commit-graph write --split=merge-all --input=none &&
395+
test_line_count = 1 $graphdir/commit-graph-chain
396+
'
397+
372398
test_done

0 commit comments

Comments
 (0)