Skip to content

Commit fbdeea4

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 d574768 commit fbdeea4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
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: 11 additions & 2 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

@@ -170,6 +173,12 @@ static int graph_write(int argc, const char **argv)
170173
if (opts.append)
171174
flags |= COMMIT_GRAPH_APPEND;
172175

176+
switch (opts.version) {
177+
case 1:
178+
flags |= COMMIT_GRAPH_VERSION_1;
179+
break;
180+
}
181+
173182
read_replace_refs = 0;
174183

175184
if (opts.reachable)

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)