Skip to content

Commit 2309b5b

Browse files
ttaylorrgitster
authored andcommitted
builtin/commit-graph.c: support '--input=none'
In the previous commit, we introduced '--[no-]merge', and alluded to the fact that '--merge' 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 881b17c commit 2309b5b

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

Documentation/git-commit-graph.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,29 @@ 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 commits specified:
43+
* With the `--input=stdin-packs` option, generate the new commit graph
44+
by walking objects only in the specified pack-indexes. (Cannot be
45+
combined with `--input=stdin-commits` or `--input=reachable`.)
4346
+
44-
With the `--input=stdin-packs` option, generate the new commit graph by
45-
walking objects only in the specified pack-indexes. (Cannot be combined
46-
with `--input=stdin-commits` or `--input=reachable`.)
47-
+
48-
With the `--input=stdin-commits` option, generate the new commit graph
47+
* With the `--input=stdin-commits` option, generate the new commit graph
4948
by walking commits starting at the commits specified in stdin as a list
5049
of OIDs in hex, one OID per line. (Cannot be combined with
5150
`--input=stdin-packs` or `--input=reachable`.)
5251
+
53-
With the `--input=reachable` option, generate the new commit graph by
52+
* With the `--input=reachable` option, generate the new commit graph by
5453
walking commits starting at all refs. (Cannot be combined with
5554
`--input=stdin-commits` or `--input=stdin-packs`.)
5655
+
57-
With the `--input=append` option, include all commits that are present
56+
* With the `--input=append` option, include all commits that are present
5857
in the existing commit-graph file.
5958
+
59+
* With the `--input=none` option, behave as if `input=append` were
60+
given, but do not walk other packs to find additional commits.
61+
62+
If none of the above options are given, then commits found in
63+
packfiles are specified.
64+
+
6065
With the `--split[=<strategy>]` option, write the commit-graph as a
6166
chain of multiple commit-graph files stored in
6267
`<dir>/info/commit-graphs`. Commit-graph layers are merged based on the

builtin/commit-graph.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
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>] [--append] "
13-
"[--split[=<strategy>]] [--input=<reachable|stdin-packs|stdin-commits>] "
13+
"[--split[=<strategy>]] "
14+
"[--input=<reachable|stdin-packs|stdin-commits|none>] "
1415
"[--[no-]progress] <split options>"),
1516
NULL
1617
};
@@ -22,7 +23,8 @@ static const char * const builtin_commit_graph_verify_usage[] = {
2223

2324
static const char * const builtin_commit_graph_write_usage[] = {
2425
N_("git commit-graph write [--object-dir <objdir>] [--append] "
25-
"[--split[=<strategy>]] [--input=<reachable|stdin-packs|stdin-commits>] "
26+
"[--split[=<strategy>]] "
27+
"[--input=<reachable|stdin-packs|stdin-commits|none>] "
2628
"[--[no-]progress] <split options>"),
2729
NULL
2830
};
@@ -31,7 +33,8 @@ enum commit_graph_input {
3133
COMMIT_GRAPH_INPUT_REACHABLE = (1 << 1),
3234
COMMIT_GRAPH_INPUT_STDIN_PACKS = (1 << 2),
3335
COMMIT_GRAPH_INPUT_STDIN_COMMITS = (1 << 3),
34-
COMMIT_GRAPH_INPUT_APPEND = (1 << 4)
36+
COMMIT_GRAPH_INPUT_APPEND = (1 << 4),
37+
COMMIT_GRAPH_INPUT_NONE = (1 << 5)
3538
};
3639

3740
static struct opts_commit_graph {
@@ -59,6 +62,8 @@ static int option_parse_input(const struct option *opt, const char *arg,
5962
*to |= COMMIT_GRAPH_INPUT_STDIN_COMMITS;
6063
else if (!strcmp(arg, "append"))
6164
*to |= COMMIT_GRAPH_INPUT_APPEND;
65+
else if (!strcmp(arg, "none"))
66+
*to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_NONE);
6267
else
6368
die(_("unrecognized --input source, %s"), arg);
6469
return 0;
@@ -211,6 +216,8 @@ static int graph_write(int argc, const char **argv)
211216
opts.obj_dir = get_object_directory();
212217
if (opts.input & COMMIT_GRAPH_INPUT_APPEND)
213218
flags |= COMMIT_GRAPH_WRITE_APPEND;
219+
if (opts.input & COMMIT_GRAPH_INPUT_NONE)
220+
flags |= COMMIT_GRAPH_WRITE_NO_INPUT;
214221
if (opts.split)
215222
flags |= COMMIT_GRAPH_WRITE_SPLIT;
216223
if (opts.progress)

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ struct write_commit_graph_context {
808808
unsigned append:1,
809809
report_progress:1,
810810
split:1,
811-
check_oids:1;
811+
check_oids:1,
812+
no_input:1;
812813

813814
const struct split_commit_graph_opts *split_opts;
814815
};
@@ -1802,6 +1803,7 @@ int write_commit_graph(struct object_directory *odb,
18021803
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
18031804
ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
18041805
ctx->split_opts = split_opts;
1806+
ctx->no_input = flags & COMMIT_GRAPH_WRITE_NO_INPUT ? 1 : 0;
18051807

18061808
if (ctx->split) {
18071809
struct commit_graph *g;
@@ -1860,7 +1862,7 @@ int write_commit_graph(struct object_directory *odb,
18601862
goto cleanup;
18611863
}
18621864

1863-
if (!pack_indexes && !commit_hex)
1865+
if (!ctx->no_input && !pack_indexes && !commit_hex)
18641866
fill_oids_from_all_packs(ctx);
18651867

18661868
close_reachable(ctx);

commit-graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ enum commit_graph_write_flags {
8181
COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
8282
COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
8383
/* Make sure that each OID in the input is a valid commit OID. */
84-
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
84+
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
85+
COMMIT_GRAPH_WRITE_NO_INPUT = (1 << 4)
8586
};
8687

8788
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)