Skip to content

Commit 4f02735

Browse files
ttaylorrgitster
authored andcommitted
builtin/commit-graph.c: support for '--split[=<strategy>]'
With '--split', the commit-graph machinery writes new commits in another incremental commit-graph which is part of the existing chain, and optionally decides to condense the chain into a single commit-graph. This is done to ensure that the asymptotic behavior of looking up a commit in an incremental chain is not dominated by the number of incrementals in that chain. It can be controlled by the '--max-commits' and '--size-multiple' options. In the next two commits, we will introduce additional splitting strategies that can exert additional control over: - when a split commit-graph is and isn't written, and - when the existing commit-graph chain is discarded completely and replaced with another graph To prepare for this, make '--split' take an optional strategy (as in '--split[=<strategy>]'), and add a new enum to describe which strategy is being used. For now, no strategies are given, and the only enumerated value is 'COMMIT_GRAPH_SPLIT_UNSPECIFIED', indicating the absence of a strategy. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fa05f3 commit 4f02735

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

Documentation/git-commit-graph.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ 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:
6566
+
6667
* If `--size-multiple=<X>` is not specified, let `X` equal 2. If the new
6768
tip file would have `N` commits and the previous tip has `M` commits and

builtin/commit-graph.c

Lines changed: 22 additions & 4 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

@@ -111,6 +115,18 @@ static int graph_verify(int argc, const char **argv)
111115
extern int read_replace_refs;
112116
static struct split_commit_graph_opts split_opts;
113117

118+
static int write_option_parse_split(const struct option *opt, const char *arg,
119+
int unset)
120+
{
121+
opts.split = 1;
122+
if (!arg)
123+
return 0;
124+
125+
die(_("unrecognized --split argument, %s"), arg);
126+
127+
return 0;
128+
}
129+
114130
static int graph_write(int argc, const char **argv)
115131
{
116132
struct string_list *pack_indexes = NULL;
@@ -133,8 +149,10 @@ static int graph_write(int argc, const char **argv)
133149
OPT_BOOL(0, "append", &opts.append,
134150
N_("include all commits already in the commit-graph file")),
135151
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
136-
OPT_BOOL(0, "split", &opts.split,
137-
N_("allow writing an incremental commit-graph file")),
152+
OPT_CALLBACK_F(0, "split", &split_opts.flags, NULL,
153+
N_("allow writing an incremental commit-graph file"),
154+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
155+
write_option_parse_split),
138156
OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
139157
N_("maximum number of commits in a non-base split commit-graph")),
140158
OPT_INTEGER(0, "size-multiple", &split_opts.size_multiple,

commit-graph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ enum commit_graph_write_flags {
8282
COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
8383
};
8484

85+
enum commit_graph_split_flags {
86+
COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0
87+
};
88+
8589
struct split_commit_graph_opts {
8690
int size_multiple;
8791
int max_commits;
8892
timestamp_t expire_time;
93+
enum commit_graph_split_flags flags;
8994
};
9095

9196
/*

0 commit comments

Comments
 (0)