Skip to content

Commit 6a1c17d

Browse files
committed
Merge branch 'tb/commit-graph-split-strategy'
"git commit-graph write" learned different ways to write out split files. * tb/commit-graph-split-strategy: Revert "commit-graph.c: introduce '--[no-]check-oids'" commit-graph.c: introduce '--[no-]check-oids' commit-graph.h: replace 'commit_hex' with 'commits' oidset: introduce 'oidset_size' builtin/commit-graph.c: introduce split strategy 'replace' builtin/commit-graph.c: introduce split strategy 'no-merge' builtin/commit-graph.c: support for '--split[=<strategy>]' t/helper/test-read-graph.c: support commit-graph chains
2 parents 2b4ff3d + dbd5e0a commit 6a1c17d

9 files changed

+192
-73
lines changed

Documentation/git-commit-graph.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,18 @@ or `--stdin-packs`.)
5757
With the `--append` option, include all commits that are present in the
5858
existing commit-graph file.
5959
+
60-
With the `--split` option, write the commit-graph as a chain of multiple
61-
commit-graph files stored in `<dir>/info/commit-graphs`. The new commits
62-
not already in the commit-graph are added in a new "tip" file. This file
63-
is merged with the existing file if the following merge conditions are
64-
met:
60+
With the `--split[=<strategy>]` option, write the commit-graph as a
61+
chain of multiple commit-graph files stored in
62+
`<dir>/info/commit-graphs`. Commit-graph layers are merged based on the
63+
strategy and other splitting options. The new commits not already in the
64+
commit-graph are added in a new "tip" file. This file is merged with the
65+
existing file if the following merge conditions are met:
66+
* If `--split=no-merge` is specified, a merge is never performed, and
67+
the remaining options are ignored. `--split=replace` overwrites the
68+
existing chain with a new one. A bare `--split` defers to the remaining
69+
options. (Note that merging a chain of commit graphs replaces the
70+
existing chain with a length-1 chain where the first and only
71+
incremental holds the entire graph).
6572
+
6673
* If `--size-multiple=<X>` is not specified, let `X` equal 2. If the new
6774
tip file would have `N` commits and the previous tip has `M` commits and

builtin/commit-graph.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
static char const * const builtin_commit_graph_usage[] = {
1111
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
12-
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
12+
N_("git commit-graph write [--object-dir <objdir>] [--append] "
13+
"[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
14+
"[--[no-]progress] <split options>"),
1315
NULL
1416
};
1517

@@ -19,7 +21,9 @@ static const char * const builtin_commit_graph_verify_usage[] = {
1921
};
2022

2123
static const char * const builtin_commit_graph_write_usage[] = {
22-
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
24+
N_("git commit-graph write [--object-dir <objdir>] [--append] "
25+
"[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
26+
"[--[no-]progress] <split options>"),
2327
NULL
2428
};
2529

@@ -114,10 +118,29 @@ static int graph_verify(int argc, const char **argv)
114118
extern int read_replace_refs;
115119
static struct split_commit_graph_opts split_opts;
116120

121+
static int write_option_parse_split(const struct option *opt, const char *arg,
122+
int unset)
123+
{
124+
enum commit_graph_split_flags *flags = opt->value;
125+
126+
opts.split = 1;
127+
if (!arg)
128+
return 0;
129+
130+
if (!strcmp(arg, "no-merge"))
131+
*flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;
132+
else if (!strcmp(arg, "replace"))
133+
*flags = COMMIT_GRAPH_SPLIT_REPLACE;
134+
else
135+
die(_("unrecognized --split argument, %s"), arg);
136+
137+
return 0;
138+
}
139+
117140
static int graph_write(int argc, const char **argv)
118141
{
119142
struct string_list *pack_indexes = NULL;
120-
struct string_list *commit_hex = NULL;
143+
struct oidset commits = OIDSET_INIT;
121144
struct object_directory *odb = NULL;
122145
struct string_list lines;
123146
int result = 0;
@@ -136,8 +159,10 @@ static int graph_write(int argc, const char **argv)
136159
OPT_BOOL(0, "append", &opts.append,
137160
N_("include all commits already in the commit-graph file")),
138161
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
139-
OPT_BOOL(0, "split", &opts.split,
140-
N_("allow writing an incremental commit-graph file")),
162+
OPT_CALLBACK_F(0, "split", &split_opts.flags, NULL,
163+
N_("allow writing an incremental commit-graph file"),
164+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
165+
write_option_parse_split),
141166
OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
142167
N_("maximum number of commits in a non-base split commit-graph")),
143168
OPT_INTEGER(0, "size-multiple", &split_opts.size_multiple,
@@ -188,7 +213,20 @@ static int graph_write(int argc, const char **argv)
188213
if (opts.stdin_packs)
189214
pack_indexes = &lines;
190215
if (opts.stdin_commits) {
191-
commit_hex = &lines;
216+
struct string_list_item *item;
217+
oidset_init(&commits, lines.nr);
218+
for_each_string_list_item(item, &lines) {
219+
struct object_id oid;
220+
const char *end;
221+
222+
if (parse_oid_hex(item->string, &oid, &end)) {
223+
error(_("unexpected non-hex object ID: "
224+
"%s"), item->string);
225+
return 1;
226+
}
227+
228+
oidset_insert(&commits, &oid);
229+
}
192230
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS;
193231
}
194232

@@ -197,7 +235,7 @@ static int graph_write(int argc, const char **argv)
197235

198236
if (write_commit_graph(odb,
199237
pack_indexes,
200-
commit_hex,
238+
opts.stdin_commits ? &commits : NULL,
201239
flags,
202240
&split_opts))
203241
result = 1;

0 commit comments

Comments
 (0)