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

test-tool: use 'read-graph' helper

The 'git commit-graph read' subcommand is used in test scripts to check that the commit-graph contents match the expected data. Mostly, this helps check the header information and the list of chunks. Users do not need this information, so move the functionality to a test helper. Reported-by: Bryan Turner <bturner@atlassian.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Nov 12, 2019 at 16:58 UTC 4bd0593e0f9149b0e72886c0a2d85bb22fc5404a
8 files changed +58 -82
Documentation/git-commit-graph.txt
-12
@@ -9,7 +9,6 @@ git-commit-graph - Write and verify Git commit-graph files
9 SYNOPSIS
10 --------
11 [verse]
12 -'git commit-graph read' [--object-dir <dir>]
12 'git commit-graph verify' [--object-dir <dir>] [--shallow] [--[no-]progress]
13 'git commit-graph write' <options> [--object-dir <dir>] [--[no-]progress]
14
@@ -74,11 +73,6 @@ Finally, if `--expire-time=<datetime>` is not specified, let `datetime`
73 be the current time. After writing the split commit-graph, delete all
74 unused commit-graph whose modified times are older than `datetime`.
75
77 -'read'::
78 -
79 -Read the commit-graph file and output basic details about it.
80 -Used for debugging purposes.
81 -
76 'verify'::
77
78 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
112 $ git rev-parse HEAD | git commit-graph write --stdin-commits --append
113 ------------------------------------------------
114
121 -* Read basic information from the commit-graph file.
122 -+
123 -------------------------------------------------
124 -$ git commit-graph read
125 -------------------------------------------------
126 -
115
116 GIT
117 ---
Makefile
+1
@@ -727,6 +727,7 @@ TEST_BUILTINS_OBJS += test-prio-queue.o
727 TEST_BUILTINS_OBJS += test-progress.o
728 TEST_BUILTINS_OBJS += test-reach.o
729 TEST_BUILTINS_OBJS += test-read-cache.o
730 +TEST_BUILTINS_OBJS += test-read-graph.o
731 TEST_BUILTINS_OBJS += test-read-midx.o
732 TEST_BUILTINS_OBJS += test-ref-store.o
733 TEST_BUILTINS_OBJS += test-regex.o
builtin/commit-graph.c
-68
@@ -8,7 +8,6 @@
8 #include "object-store.h"
9
10 static char const * const builtin_commit_graph_usage[] = {
11 - N_("git commit-graph read [--object-dir <objdir>]"),
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>"),
13 NULL
@@ -19,11 +18,6 @@ static const char * const builtin_commit_graph_verify_usage[] = {
18 NULL
19 };
20
22 -static const char * const builtin_commit_graph_read_usage[] = {
23 - N_("git commit-graph read [--object-dir <objdir>]"),
24 - NULL
25 -};
26 -
21 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>"),
23 NULL
@@ -93,66 +87,6 @@ static int graph_verify(int argc, const char **argv)
87 return verify_commit_graph(the_repository, graph, flags);
88 }
89
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 -
90 extern int read_replace_refs;
91 static struct split_commit_graph_opts split_opts;
92
@@ -268,8 +202,6 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
202 save_commit_buffer = 0;
203
204 if (argc > 0) {
271 - if (!strcmp(argv[0], "read"))
272 - return graph_read(argc, argv);
205 if (!strcmp(argv[0], "verify"))
206 return graph_verify(argc, argv);
207 if (!strcmp(argv[0], "write"))
t/helper/test-read-graph.c new
+53
@@ -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
+1
@@ -45,6 +45,7 @@ static struct test_cmd cmds[] = {
45 { "progress", cmd__progress },
46 { "reach", cmd__reach },
47 { "read-cache", cmd__read_cache },
48 + { "read-graph", cmd__read_graph },
49 { "read-midx", cmd__read_midx },
50 { "ref-store", cmd__ref_store },
51 { "regex", cmd__regex },
t/helper/test-tool.h
+1
@@ -35,6 +35,7 @@ int cmd__prio_queue(int argc, const char **argv);
35 int cmd__progress(int argc, const char **argv);
36 int cmd__reach(int argc, const char **argv);
37 int cmd__read_cache(int argc, const char **argv);
38 +int cmd__read_graph(int argc, const char **argv);
39 int cmd__read_midx(int argc, const char **argv);
40 int cmd__ref_store(int argc, const char **argv);
41 int cmd__regex(int argc, const char **argv);
t/t5318-commit-graph.sh
+1 -1
@@ -85,7 +85,7 @@ graph_read_expect() {
85 num_commits: $1
86 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
87 EOF
88 - git commit-graph read >output &&
88 + test-tool read-graph >output &&
89 test_cmp expect output
90 }
91
t/t5324-split-commit-graph.sh
+1 -1
@@ -25,7 +25,7 @@ graph_read_expect() {
25 num_commits: $1
26 chunks: oid_fanout oid_lookup commit_metadata
27 EOF
28 - git commit-graph read >output &&
28 + test-tool read-graph >output &&
29 test_cmp expect output
30 }
31