Skip to content

Commit 723a8ad

Browse files
committed
Merge branch 'ds/test-read-graph'
Dev support for commit-graph feature. * ds/test-read-graph: test-tool: use 'read-graph' helper
2 parents 9da3948 + 4bd0593 commit 723a8ad

File tree

8 files changed

+58
-82
lines changed

8 files changed

+58
-82
lines changed

Documentation/git-commit-graph.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ git-commit-graph - Write and verify Git commit-graph files
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git commit-graph read' [--object-dir <dir>]
1312
'git commit-graph verify' [--object-dir <dir>] [--shallow] [--[no-]progress]
1413
'git commit-graph write' <options> [--object-dir <dir>] [--[no-]progress]
1514

@@ -74,11 +73,6 @@ Finally, if `--expire-time=<datetime>` is not specified, let `datetime`
7473
be the current time. After writing the split commit-graph, delete all
7574
unused commit-graph whose modified times are older than `datetime`.
7675

77-
'read'::
78-
79-
Read the commit-graph file and output basic details about it.
80-
Used for debugging purposes.
81-
8276
'verify'::
8377

8478
Read the commit-graph file and verify its contents against the object
@@ -118,12 +112,6 @@ $ git show-ref -s | git commit-graph write --stdin-commits
118112
$ git rev-parse HEAD | git commit-graph write --stdin-commits --append
119113
------------------------------------------------
120114

121-
* Read basic information from the commit-graph file.
122-
+
123-
------------------------------------------------
124-
$ git commit-graph read
125-
------------------------------------------------
126-
127115

128116
GIT
129117
---

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ TEST_BUILTINS_OBJS += test-prio-queue.o
727727
TEST_BUILTINS_OBJS += test-progress.o
728728
TEST_BUILTINS_OBJS += test-reach.o
729729
TEST_BUILTINS_OBJS += test-read-cache.o
730+
TEST_BUILTINS_OBJS += test-read-graph.o
730731
TEST_BUILTINS_OBJS += test-read-midx.o
731732
TEST_BUILTINS_OBJS += test-ref-store.o
732733
TEST_BUILTINS_OBJS += test-regex.o

builtin/commit-graph.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "object-store.h"
99

1010
static char const * const builtin_commit_graph_usage[] = {
11-
N_("git commit-graph read [--object-dir <objdir>]"),
1211
N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
1312
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
1413
NULL
@@ -19,11 +18,6 @@ static const char * const builtin_commit_graph_verify_usage[] = {
1918
NULL
2019
};
2120

22-
static const char * const builtin_commit_graph_read_usage[] = {
23-
N_("git commit-graph read [--object-dir <objdir>]"),
24-
NULL
25-
};
26-
2721
static const char * const builtin_commit_graph_write_usage[] = {
2822
N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
2923
NULL
@@ -93,66 +87,6 @@ static int graph_verify(int argc, const char **argv)
9387
return verify_commit_graph(the_repository, graph, flags);
9488
}
9589

96-
static int graph_read(int argc, const char **argv)
97-
{
98-
struct commit_graph *graph = NULL;
99-
char *graph_name;
100-
int open_ok;
101-
int fd;
102-
struct stat st;
103-
104-
static struct option builtin_commit_graph_read_options[] = {
105-
OPT_STRING(0, "object-dir", &opts.obj_dir,
106-
N_("dir"),
107-
N_("The object directory to store the graph")),
108-
OPT_END(),
109-
};
110-
111-
trace2_cmd_mode("read");
112-
113-
argc = parse_options(argc, argv, NULL,
114-
builtin_commit_graph_read_options,
115-
builtin_commit_graph_read_usage, 0);
116-
117-
if (!opts.obj_dir)
118-
opts.obj_dir = get_object_directory();
119-
120-
graph_name = get_commit_graph_filename(opts.obj_dir);
121-
122-
open_ok = open_commit_graph(graph_name, &fd, &st);
123-
if (!open_ok)
124-
die_errno(_("Could not open commit-graph '%s'"), graph_name);
125-
126-
graph = load_commit_graph_one_fd_st(fd, &st);
127-
if (!graph)
128-
return 1;
129-
130-
FREE_AND_NULL(graph_name);
131-
132-
printf("header: %08x %d %d %d %d\n",
133-
ntohl(*(uint32_t*)graph->data),
134-
*(unsigned char*)(graph->data + 4),
135-
*(unsigned char*)(graph->data + 5),
136-
*(unsigned char*)(graph->data + 6),
137-
*(unsigned char*)(graph->data + 7));
138-
printf("num_commits: %u\n", graph->num_commits);
139-
printf("chunks:");
140-
141-
if (graph->chunk_oid_fanout)
142-
printf(" oid_fanout");
143-
if (graph->chunk_oid_lookup)
144-
printf(" oid_lookup");
145-
if (graph->chunk_commit_data)
146-
printf(" commit_metadata");
147-
if (graph->chunk_extra_edges)
148-
printf(" extra_edges");
149-
printf("\n");
150-
151-
UNLEAK(graph);
152-
153-
return 0;
154-
}
155-
15690
extern int read_replace_refs;
15791
static struct split_commit_graph_opts split_opts;
15892

@@ -268,8 +202,6 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
268202
save_commit_buffer = 0;
269203

270204
if (argc > 0) {
271-
if (!strcmp(argv[0], "read"))
272-
return graph_read(argc, argv);
273205
if (!strcmp(argv[0], "verify"))
274206
return graph_verify(argc, argv);
275207
if (!strcmp(argv[0], "write"))

t/helper/test-read-graph.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "test-tool.h"
2+
#include "cache.h"
3+
#include "commit-graph.h"
4+
#include "repository.h"
5+
#include "object-store.h"
6+
7+
int cmd__read_graph(int argc, const char **argv)
8+
{
9+
struct commit_graph *graph = NULL;
10+
char *graph_name;
11+
int open_ok;
12+
int fd;
13+
struct stat st;
14+
const char *object_dir;
15+
16+
setup_git_directory();
17+
object_dir = get_object_directory();
18+
19+
graph_name = get_commit_graph_filename(object_dir);
20+
21+
open_ok = open_commit_graph(graph_name, &fd, &st);
22+
if (!open_ok)
23+
die_errno(_("Could not open commit-graph '%s'"), graph_name);
24+
25+
graph = load_commit_graph_one_fd_st(fd, &st);
26+
if (!graph)
27+
return 1;
28+
29+
FREE_AND_NULL(graph_name);
30+
31+
printf("header: %08x %d %d %d %d\n",
32+
ntohl(*(uint32_t*)graph->data),
33+
*(unsigned char*)(graph->data + 4),
34+
*(unsigned char*)(graph->data + 5),
35+
*(unsigned char*)(graph->data + 6),
36+
*(unsigned char*)(graph->data + 7));
37+
printf("num_commits: %u\n", graph->num_commits);
38+
printf("chunks:");
39+
40+
if (graph->chunk_oid_fanout)
41+
printf(" oid_fanout");
42+
if (graph->chunk_oid_lookup)
43+
printf(" oid_lookup");
44+
if (graph->chunk_commit_data)
45+
printf(" commit_metadata");
46+
if (graph->chunk_extra_edges)
47+
printf(" extra_edges");
48+
printf("\n");
49+
50+
UNLEAK(graph);
51+
52+
return 0;
53+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static struct test_cmd cmds[] = {
4545
{ "progress", cmd__progress },
4646
{ "reach", cmd__reach },
4747
{ "read-cache", cmd__read_cache },
48+
{ "read-graph", cmd__read_graph },
4849
{ "read-midx", cmd__read_midx },
4950
{ "ref-store", cmd__ref_store },
5051
{ "regex", cmd__regex },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int cmd__prio_queue(int argc, const char **argv);
3535
int cmd__progress(int argc, const char **argv);
3636
int cmd__reach(int argc, const char **argv);
3737
int cmd__read_cache(int argc, const char **argv);
38+
int cmd__read_graph(int argc, const char **argv);
3839
int cmd__read_midx(int argc, const char **argv);
3940
int cmd__ref_store(int argc, const char **argv);
4041
int cmd__regex(int argc, const char **argv);

t/t5318-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ graph_read_expect() {
8585
num_commits: $1
8686
chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
8787
EOF
88-
git commit-graph read >output &&
88+
test-tool read-graph >output &&
8989
test_cmp expect output
9090
}
9191

t/t5324-split-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ graph_read_expect() {
2525
num_commits: $1
2626
chunks: oid_fanout oid_lookup commit_metadata
2727
EOF
28-
git commit-graph read >output &&
28+
test-tool read-graph >output &&
2929
test_cmp expect output
3030
}
3131

0 commit comments

Comments
 (0)