@matheusbsbs / matheus-bagliano / commits / 4f027355f6
Fork 0

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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 13, 2020 at 22:04 UTC 4f027355f6b6b5b2ba69e23ff50cb7313d13dd70
3 files changed +33 -9
Documentation/git-commit-graph.txt
+6 -5
@@ -57,11 +57,12 @@ or `--stdin-packs`.)
57 With the `--append` option, include all commits that are present in the
58 existing commit-graph file.
59 +
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 +
67 * If `--size-multiple=<X>` is not specified, let `X` equal 2. If the new
68 tip file would have `N` commits and the previous tip has `M` commits and
builtin/commit-graph.c
+22 -4
@@ -9,7 +9,9 @@
9
10 static char const * const builtin_commit_graph_usage[] = {
11 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>"),
15 NULL
16 };
17
@@ -19,7 +21,9 @@ static const char * const builtin_commit_graph_verify_usage[] = {
21 };
22
23 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>"),
27 NULL
28 };
29
@@ -111,6 +115,18 @@ static int graph_verify(int argc, const char **argv)
115 extern int read_replace_refs;
116 static struct split_commit_graph_opts split_opts;
117
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 +
130 static int graph_write(int argc, const char **argv)
131 {
132 struct string_list *pack_indexes = NULL;
@@ -133,8 +149,10 @@ static int graph_write(int argc, const char **argv)
149 OPT_BOOL(0, "append", &opts.append,
150 N_("include all commits already in the commit-graph file")),
151 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),
156 OPT_INTEGER(0, "max-commits", &split_opts.max_commits,
157 N_("maximum number of commits in a non-base split commit-graph")),
158 OPT_INTEGER(0, "size-multiple", &split_opts.size_multiple,
commit-graph.h
+5
@@ -82,10 +82,15 @@ enum commit_graph_write_flags {
82 COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
83 };
84
85 +enum commit_graph_split_flags {
86 + COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0
87 +};
88 +
89 struct split_commit_graph_opts {
90 int size_multiple;
91 int max_commits;
92 timestamp_t expire_time;
93 + enum commit_graph_split_flags flags;
94 };
95
96 /*