Skip to content

Commit ac00247

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: add --version=<n> option
Allow the commit-graph builtin to specify the file format version using the '--version=<n>' option. Specify the version exactly in the verification tests as using a different version would change the offsets used in those tests. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0be0712 commit ac00247

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Documentation/git-commit-graph.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ or `--stdin-packs`.)
5151
+
5252
With the `--append` option, include all commits that are present in the
5353
existing commit-graph file.
54+
+
55+
With the `--version=<n>` option, specify the file format version. Used
56+
only for testing.
5457

5558
'read'::
5659

builtin/commit-graph.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static char const * const builtin_commit_graph_usage[] = {
1010
N_("git commit-graph [--object-dir <objdir>]"),
1111
N_("git commit-graph read [--object-dir <objdir>]"),
1212
N_("git commit-graph verify [--object-dir <objdir>]"),
13-
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
13+
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits] [--version=<n>]"),
1414
NULL
1515
};
1616

@@ -25,7 +25,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
2525
};
2626

2727
static const char * const builtin_commit_graph_write_usage[] = {
28-
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]"),
28+
N_("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits] [--version=<n>]"),
2929
NULL
3030
};
3131

@@ -35,6 +35,7 @@ static struct opts_commit_graph {
3535
int stdin_packs;
3636
int stdin_commits;
3737
int append;
38+
int version;
3839
} opts;
3940

4041

@@ -156,6 +157,8 @@ static int graph_write(int argc, const char **argv)
156157
N_("start walk at commits listed by stdin")),
157158
OPT_BOOL(0, "append", &opts.append,
158159
N_("include all commits already in the commit-graph file")),
160+
OPT_INTEGER(0, "version", &opts.version,
161+
N_("specify the file format version")),
159162
OPT_END(),
160163
};
161164

@@ -173,7 +176,7 @@ static int graph_write(int argc, const char **argv)
173176
read_replace_refs = 0;
174177

175178
if (opts.reachable)
176-
return write_commit_graph_reachable(opts.obj_dir, flags, 0);
179+
return write_commit_graph_reachable(opts.obj_dir, flags, opts.version);
177180

178181
string_list_init(&lines, 0);
179182
if (opts.stdin_packs || opts.stdin_commits) {
@@ -193,7 +196,7 @@ static int graph_write(int argc, const char **argv)
193196
result = write_commit_graph(opts.obj_dir,
194197
pack_indexes,
195198
commit_hex,
196-
flags, 0);
199+
flags, opts.version);
197200

198201
UNLEAK(lines);
199202
return result;

t/t5318-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ test_expect_success 'replace-objects invalidates commit-graph' '
328328

329329
test_expect_success 'git commit-graph verify' '
330330
cd "$TRASH_DIRECTORY/full" &&
331-
git rev-parse commits/8 | git commit-graph write --stdin-commits &&
331+
git rev-parse commits/8 | git commit-graph write --stdin-commits --version=1 &&
332332
git commit-graph verify >output
333333
'
334334

0 commit comments

Comments
 (0)