| 1 | #define USE_THE_REPOSITORY_VARIABLE |
| 2 | |
| 3 | #include "test-tool.h" |
| 4 | #include "commit-graph.h" |
| 5 | #include "repository.h" |
| 6 | #include "odb.h" |
| 7 | #include "bloom.h" |
| 8 | #include "setup.h" |
| 9 | |
| 10 | static void dump_graph_info(struct commit_graph *graph) |
| 11 | { |
| 12 | printf("header: %08x %d %d %d %d\n", |
| 13 | ntohl(*(uint32_t*)graph->data), |
| 14 | *(unsigned char*)(graph->data + 4), |
| 15 | *(unsigned char*)(graph->data + 5), |
| 16 | *(unsigned char*)(graph->data + 6), |
| 17 | *(unsigned char*)(graph->data + 7)); |
| 18 | printf("num_commits: %u\n", graph->num_commits); |
| 19 | printf("chunks:"); |
| 20 | |
| 21 | if (graph->chunk_oid_fanout) |
| 22 | printf(" oid_fanout"); |
| 23 | if (graph->chunk_oid_lookup) |
| 24 | printf(" oid_lookup"); |
| 25 | if (graph->chunk_commit_data) |
| 26 | printf(" commit_metadata"); |
| 27 | if (graph->chunk_generation_data) |
| 28 | printf(" generation_data"); |
| 29 | if (graph->chunk_generation_data_overflow) |
| 30 | printf(" generation_data_overflow"); |
| 31 | if (graph->chunk_extra_edges) |
| 32 | printf(" extra_edges"); |
| 33 | if (graph->chunk_bloom_indexes) |
| 34 | printf(" bloom_indexes"); |
| 35 | if (graph->chunk_bloom_data) |
| 36 | printf(" bloom_data"); |
| 37 | printf("\n"); |
| 38 | |
| 39 | printf("options:"); |
| 40 | if (graph->bloom_filter_settings) |
| 41 | printf(" bloom(%"PRIu32",%"PRIu32",%"PRIu32")", |
| 42 | graph->bloom_filter_settings->hash_version, |
| 43 | graph->bloom_filter_settings->bits_per_entry, |
| 44 | graph->bloom_filter_settings->num_hashes); |
| 45 | if (graph->read_generation_data) |
| 46 | printf(" read_generation_data"); |
| 47 | if (graph->topo_levels) |
| 48 | printf(" topo_levels"); |
| 49 | printf("\n"); |
| 50 | } |
| 51 | |
| 52 | static void dump_graph_bloom_filters(struct commit_graph *graph) |
| 53 | { |
| 54 | uint32_t i; |
| 55 | |
| 56 | for (i = 0; i < graph->num_commits + graph->num_commits_in_base; i++) { |
| 57 | struct bloom_filter filter = { 0 }; |
| 58 | size_t j; |
| 59 | |
| 60 | if (load_bloom_filter_from_graph(graph, &filter, i) < 0) { |
| 61 | fprintf(stderr, "missing Bloom filter for graph " |
| 62 | "position %"PRIu32"\n", i); |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | for (j = 0; j < filter.len; j++) |
| 67 | printf("%02x", filter.data[j]); |
| 68 | if (filter.len) |
| 69 | printf("\n"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | int cmd__read_graph(int argc, const char **argv) |
| 74 | { |
| 75 | struct commit_graph *graph = NULL; |
| 76 | struct odb_source *source; |
| 77 | int ret = 0; |
| 78 | |
| 79 | setup_git_directory(the_repository); |
| 80 | source = the_repository->objects->sources; |
| 81 | |
| 82 | prepare_repo_settings(the_repository); |
| 83 | |
| 84 | graph = read_commit_graph_one(source); |
| 85 | if (!graph) { |
| 86 | ret = 1; |
| 87 | goto done; |
| 88 | } |
| 89 | |
| 90 | if (argc <= 1) |
| 91 | dump_graph_info(graph); |
| 92 | else if (!strcmp(argv[1], "bloom-filters")) |
| 93 | dump_graph_bloom_filters(graph); |
| 94 | else { |
| 95 | fprintf(stderr, "unknown sub-command: '%s'\n", argv[1]); |
| 96 | ret = 1; |
| 97 | } |
| 98 | |
| 99 | done: |
| 100 | free_commit_graph(graph); |
| 101 | return ret; |
| 102 | } |