]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-tool: use 'read-graph' helper
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 12 Nov 2019 16:58:20 +0000 (16:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 13 Nov 2019 02:14:16 +0000 (11:14 +0900)
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>
Documentation/git-commit-graph.txt
Makefile
builtin/commit-graph.c
t/helper/test-read-graph.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h
t/t5318-commit-graph.sh
t/t5324-split-commit-graph.sh

index 8c708a7a16ece24dfb3d617f2c8117c12d234655..bcd85c1976769376477fe43f5b15ec1394a31f05 100644 (file)
@@ -9,7 +9,6 @@ git-commit-graph - Write and verify Git commit-graph files
 SYNOPSIS
 --------
 [verse]
-'git commit-graph read' [--object-dir <dir>]
 'git commit-graph verify' [--object-dir <dir>] [--shallow] [--[no-]progress]
 'git commit-graph write' <options> [--object-dir <dir>] [--[no-]progress]
 
@@ -74,11 +73,6 @@ Finally, if `--expire-time=<datetime>` is not specified, let `datetime`
 be the current time. After writing the split commit-graph, delete all
 unused commit-graph whose modified times are older than `datetime`.
 
-'read'::
-
-Read the commit-graph file and output basic details about it.
-Used for debugging purposes.
-
 'verify'::
 
 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
 $ git rev-parse HEAD | git commit-graph write --stdin-commits --append
 ------------------------------------------------
 
-* Read basic information from the commit-graph file.
-+
-------------------------------------------------
-$ git commit-graph read
-------------------------------------------------
-
 
 GIT
 ---
index 58b92af54b2af48c132bf3d7beb8feaf05a450ed..44997f6f57349d46f9f9fa675f2261d10e37d6fb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -727,6 +727,7 @@ TEST_BUILTINS_OBJS += test-prio-queue.o
 TEST_BUILTINS_OBJS += test-progress.o
 TEST_BUILTINS_OBJS += test-reach.o
 TEST_BUILTINS_OBJS += test-read-cache.o
+TEST_BUILTINS_OBJS += test-read-graph.o
 TEST_BUILTINS_OBJS += test-read-midx.o
 TEST_BUILTINS_OBJS += test-ref-store.o
 TEST_BUILTINS_OBJS += test-regex.o
index ec0fc93d39b5a6ee3cf942ce086c48b1907cec58..e0c6fc4bbf6d42d704c84b5c888282a4e163767f 100644 (file)
@@ -8,7 +8,6 @@
 #include "object-store.h"
 
 static char const * const builtin_commit_graph_usage[] = {
-       N_("git commit-graph read [--object-dir <objdir>]"),
        N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
        N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
        NULL
@@ -19,11 +18,6 @@ static const char * const builtin_commit_graph_verify_usage[] = {
        NULL
 };
 
-static const char * const builtin_commit_graph_read_usage[] = {
-       N_("git commit-graph read [--object-dir <objdir>]"),
-       NULL
-};
-
 static const char * const builtin_commit_graph_write_usage[] = {
        N_("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>"),
        NULL
@@ -93,66 +87,6 @@ static int graph_verify(int argc, const char **argv)
        return verify_commit_graph(the_repository, graph, flags);
 }
 
-static int graph_read(int argc, const char **argv)
-{
-       struct commit_graph *graph = NULL;
-       char *graph_name;
-       int open_ok;
-       int fd;
-       struct stat st;
-
-       static struct option builtin_commit_graph_read_options[] = {
-               OPT_STRING(0, "object-dir", &opts.obj_dir,
-                       N_("dir"),
-                       N_("The object directory to store the graph")),
-               OPT_END(),
-       };
-
-       trace2_cmd_mode("read");
-
-       argc = parse_options(argc, argv, NULL,
-                            builtin_commit_graph_read_options,
-                            builtin_commit_graph_read_usage, 0);
-
-       if (!opts.obj_dir)
-               opts.obj_dir = get_object_directory();
-
-       graph_name = get_commit_graph_filename(opts.obj_dir);
-
-       open_ok = open_commit_graph(graph_name, &fd, &st);
-       if (!open_ok)
-               die_errno(_("Could not open commit-graph '%s'"), graph_name);
-
-       graph = load_commit_graph_one_fd_st(fd, &st);
-       if (!graph)
-               return 1;
-
-       FREE_AND_NULL(graph_name);
-
-       printf("header: %08x %d %d %d %d\n",
-               ntohl(*(uint32_t*)graph->data),
-               *(unsigned char*)(graph->data + 4),
-               *(unsigned char*)(graph->data + 5),
-               *(unsigned char*)(graph->data + 6),
-               *(unsigned char*)(graph->data + 7));
-       printf("num_commits: %u\n", graph->num_commits);
-       printf("chunks:");
-
-       if (graph->chunk_oid_fanout)
-               printf(" oid_fanout");
-       if (graph->chunk_oid_lookup)
-               printf(" oid_lookup");
-       if (graph->chunk_commit_data)
-               printf(" commit_metadata");
-       if (graph->chunk_extra_edges)
-               printf(" extra_edges");
-       printf("\n");
-
-       UNLEAK(graph);
-
-       return 0;
-}
-
 extern int read_replace_refs;
 static struct split_commit_graph_opts split_opts;
 
@@ -268,8 +202,6 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
        save_commit_buffer = 0;
 
        if (argc > 0) {
-               if (!strcmp(argv[0], "read"))
-                       return graph_read(argc, argv);
                if (!strcmp(argv[0], "verify"))
                        return graph_verify(argc, argv);
                if (!strcmp(argv[0], "write"))
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
new file mode 100644 (file)
index 0000000..d2884ef
--- /dev/null
@@ -0,0 +1,53 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "commit-graph.h"
+#include "repository.h"
+#include "object-store.h"
+
+int cmd__read_graph(int argc, const char **argv)
+{
+       struct commit_graph *graph = NULL;
+       char *graph_name;
+       int open_ok;
+       int fd;
+       struct stat st;
+       const char *object_dir;
+
+       setup_git_directory();
+       object_dir = get_object_directory();
+
+       graph_name = get_commit_graph_filename(object_dir);
+
+       open_ok = open_commit_graph(graph_name, &fd, &st);
+       if (!open_ok)
+               die_errno(_("Could not open commit-graph '%s'"), graph_name);
+
+       graph = load_commit_graph_one_fd_st(fd, &st);
+       if (!graph)
+               return 1;
+
+       FREE_AND_NULL(graph_name);
+
+       printf("header: %08x %d %d %d %d\n",
+               ntohl(*(uint32_t*)graph->data),
+               *(unsigned char*)(graph->data + 4),
+               *(unsigned char*)(graph->data + 5),
+               *(unsigned char*)(graph->data + 6),
+               *(unsigned char*)(graph->data + 7));
+       printf("num_commits: %u\n", graph->num_commits);
+       printf("chunks:");
+
+       if (graph->chunk_oid_fanout)
+               printf(" oid_fanout");
+       if (graph->chunk_oid_lookup)
+               printf(" oid_lookup");
+       if (graph->chunk_commit_data)
+               printf(" commit_metadata");
+       if (graph->chunk_extra_edges)
+               printf(" extra_edges");
+       printf("\n");
+
+       UNLEAK(graph);
+
+       return 0;
+}
index 19ee26d931d9fb5cff2e4b2d0de55b503daaf571..f20989d4497b596685abfb72bad1f048e41b212c 100644 (file)
@@ -45,6 +45,7 @@ static struct test_cmd cmds[] = {
        { "progress", cmd__progress },
        { "reach", cmd__reach },
        { "read-cache", cmd__read_cache },
+       { "read-graph", cmd__read_graph },
        { "read-midx", cmd__read_midx },
        { "ref-store", cmd__ref_store },
        { "regex", cmd__regex },
index c2aa56ef50d90fc61db8720bbbc9955264036b73..8ed2af71d1b2382def4215862a6b5585876a62cc 100644 (file)
@@ -35,6 +35,7 @@ int cmd__prio_queue(int argc, const char **argv);
 int cmd__progress(int argc, const char **argv);
 int cmd__reach(int argc, const char **argv);
 int cmd__read_cache(int argc, const char **argv);
+int cmd__read_graph(int argc, const char **argv);
 int cmd__read_midx(int argc, const char **argv);
 int cmd__ref_store(int argc, const char **argv);
 int cmd__regex(int argc, const char **argv);
index d42b3efe39183627aaeb3eef461e6593dd762e4a..798968374f54c822615da3aab57fcf4a62dfc969 100755 (executable)
@@ -85,7 +85,7 @@ graph_read_expect() {
        num_commits: $1
        chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
        EOF
-       git commit-graph read >output &&
+       test-tool read-graph >output &&
        test_cmp expect output
 }
 
index 115aabd1416b8f3e243282aa811c273ca2a15e41..c24823431f2314169874adc705188f40da4c1618 100755 (executable)
@@ -25,7 +25,7 @@ graph_read_expect() {
        num_commits: $1
        chunks: oid_fanout oid_lookup commit_metadata
        EOF
-       git commit-graph read >output &&
+       test-tool read-graph >output &&
        test_cmp expect output
 }