Merge branch 'nd/switch-and-restore' into maint
[git] / t / helper / test-read-graph.c
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 }