5 #include "parse-options.h"
6 #include "commit-graph.h"
8 static char const * const builtin_commit_graph_usage[] = {
9 N_("git commit-graph [--object-dir <objdir>]"),
10 N_("git commit-graph read [--object-dir <objdir>]"),
11 N_("git commit-graph write [--object-dir <objdir>]"),
15 static const char * const builtin_commit_graph_read_usage[] = {
16 N_("git commit-graph read [--object-dir <objdir>]"),
20 static const char * const builtin_commit_graph_write_usage[] = {
21 N_("git commit-graph write [--object-dir <objdir>]"),
25 static struct opts_commit_graph {
29 static int graph_read(int argc, const char **argv)
31 struct commit_graph *graph = NULL;
34 static struct option builtin_commit_graph_read_options[] = {
35 OPT_STRING(0, "object-dir", &opts.obj_dir,
37 N_("The object directory to store the graph")),
41 argc = parse_options(argc, argv, NULL,
42 builtin_commit_graph_read_options,
43 builtin_commit_graph_read_usage, 0);
46 opts.obj_dir = get_object_directory();
48 graph_name = get_commit_graph_filename(opts.obj_dir);
49 graph = load_commit_graph_one(graph_name);
52 die("graph file %s does not exist", graph_name);
53 FREE_AND_NULL(graph_name);
55 printf("header: %08x %d %d %d %d\n",
56 ntohl(*(uint32_t*)graph->data),
57 *(unsigned char*)(graph->data + 4),
58 *(unsigned char*)(graph->data + 5),
59 *(unsigned char*)(graph->data + 6),
60 *(unsigned char*)(graph->data + 7));
61 printf("num_commits: %u\n", graph->num_commits);
64 if (graph->chunk_oid_fanout)
65 printf(" oid_fanout");
66 if (graph->chunk_oid_lookup)
67 printf(" oid_lookup");
68 if (graph->chunk_commit_data)
69 printf(" commit_metadata");
70 if (graph->chunk_large_edges)
71 printf(" large_edges");
77 static int graph_write(int argc, const char **argv)
79 static struct option builtin_commit_graph_write_options[] = {
80 OPT_STRING(0, "object-dir", &opts.obj_dir,
82 N_("The object directory to store the graph")),
86 argc = parse_options(argc, argv, NULL,
87 builtin_commit_graph_write_options,
88 builtin_commit_graph_write_usage, 0);
91 opts.obj_dir = get_object_directory();
93 write_commit_graph(opts.obj_dir);
97 int cmd_commit_graph(int argc, const char **argv, const char *prefix)
99 static struct option builtin_commit_graph_options[] = {
100 OPT_STRING(0, "object-dir", &opts.obj_dir,
102 N_("The object directory to store the graph")),
106 if (argc == 2 && !strcmp(argv[1], "-h"))
107 usage_with_options(builtin_commit_graph_usage,
108 builtin_commit_graph_options);
110 git_config(git_default_config, NULL);
111 argc = parse_options(argc, argv, prefix,
112 builtin_commit_graph_options,
113 builtin_commit_graph_usage,
114 PARSE_OPT_STOP_AT_NON_OPTION);
117 if (!strcmp(argv[0], "read"))
118 return graph_read(argc, argv);
119 if (!strcmp(argv[0], "write"))
120 return graph_write(argc, argv);
123 usage_with_options(builtin_commit_graph_usage,
124 builtin_commit_graph_options);