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>] [--file=<hash>]"),
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>] [--file=<hash>]"),
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 {
27 const char *graph_file;
30 static int graph_read(int argc, const char **argv)
32 struct commit_graph *graph = 0;
33 struct strbuf full_path = STRBUF_INIT;
35 static struct option builtin_commit_graph_read_options[] = {
36 { OPTION_STRING, 'o', "object-dir", &opts.obj_dir,
38 N_("The object directory to store the graph") },
39 { OPTION_STRING, 'H', "file", &opts.graph_file,
41 N_("The filename for a specific commit graph file in the object directory."),
42 PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
46 argc = parse_options(argc, argv, NULL,
47 builtin_commit_graph_read_options,
48 builtin_commit_graph_read_usage, 0);
51 opts.obj_dir = get_object_directory();
54 die("no graph hash specified");
56 strbuf_addf(&full_path, "%s/info/%s", opts.obj_dir, opts.graph_file);
57 graph = load_commit_graph_one(full_path.buf);
60 die("graph file %s does not exist", full_path.buf);
62 printf("header: %08x %d %d %d %d\n",
63 ntohl(*(uint32_t*)graph->data),
64 *(unsigned char*)(graph->data + 4),
65 *(unsigned char*)(graph->data + 5),
66 *(unsigned char*)(graph->data + 6),
67 *(unsigned char*)(graph->data + 7));
68 printf("num_commits: %u\n", graph->num_commits);
71 if (graph->chunk_oid_fanout)
72 printf(" oid_fanout");
73 if (graph->chunk_oid_lookup)
74 printf(" oid_lookup");
75 if (graph->chunk_commit_data)
76 printf(" commit_metadata");
77 if (graph->chunk_large_edges)
78 printf(" large_edges");
84 static int graph_write(int argc, const char **argv)
88 static struct option builtin_commit_graph_write_options[] = {
89 { OPTION_STRING, 'o', "object-dir", &opts.obj_dir,
91 N_("The object directory to store the graph") },
95 argc = parse_options(argc, argv, NULL,
96 builtin_commit_graph_write_options,
97 builtin_commit_graph_write_usage, 0);
100 opts.obj_dir = get_object_directory();
102 graph_name = write_commit_graph(opts.obj_dir);
105 printf("%s\n", graph_name);
106 FREE_AND_NULL(graph_name);
112 int cmd_commit_graph(int argc, const char **argv, const char *prefix)
114 static struct option builtin_commit_graph_options[] = {
115 { OPTION_STRING, 'o', "object-dir", &opts.obj_dir,
117 N_("The object directory to store the graph") },
121 if (argc == 2 && !strcmp(argv[1], "-h"))
122 usage_with_options(builtin_commit_graph_usage,
123 builtin_commit_graph_options);
125 git_config(git_default_config, NULL);
126 argc = parse_options(argc, argv, prefix,
127 builtin_commit_graph_options,
128 builtin_commit_graph_usage,
129 PARSE_OPT_STOP_AT_NON_OPTION);
132 if (!strcmp(argv[0], "read"))
133 return graph_read(argc, argv);
134 if (!strcmp(argv[0], "write"))
135 return graph_write(argc, argv);
138 usage_with_options(builtin_commit_graph_usage,
139 builtin_commit_graph_options);