git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / helper / test-read-graph.c
| 1 | #define USE_THE_REPOSITORY_VARIABLE |
| 2 | |
| 3 | #include "test-tool.h" |
| 4 | #include "commit-graph.h" |
| 5 | #include "commit.h" |
| 6 | #include "hex.h" |
| 7 | #include "object-name.h" |
| 8 | #include "repository.h" |
| 9 | #include "odb.h" |
| 10 | #include "odb/source.h" |
| 11 | #include "bloom.h" |
| 12 | #include "setup.h" |
| 13 | |
| 14 | static void dump_graph_info(struct commit_graph *graph) |
| 15 | { |
| 16 | printf("header: %08x %d %d %d %d\n", |
| 17 | ntohl(*(uint32_t*)graph->data), |
| 18 | *(unsigned char*)(graph->data + 4), |
| 19 | *(unsigned char*)(graph->data + 5), |
| 20 | *(unsigned char*)(graph->data + 6), |
| 21 | *(unsigned char*)(graph->data + 7)); |
| 22 | printf("num_commits: %u\n", graph->num_commits); |
| 23 | printf("chunks:"); |
| 24 | |
| 25 | if (graph->chunk_oid_fanout) |
| 26 | printf(" oid_fanout"); |
| 27 | if (graph->chunk_oid_lookup) |
| 28 | printf(" oid_lookup"); |
| 29 | if (graph->chunk_commit_data) |
| 30 | printf(" commit_metadata"); |
| 31 | if (graph->chunk_generation_data) |
| 32 | printf(" generation_data"); |
| 33 | if (graph->chunk_generation_data_overflow) |
| 34 | printf(" generation_data_overflow"); |
| 35 | if (graph->chunk_extra_edges) |
| 36 | printf(" extra_edges"); |
| 37 | if (graph->chunk_bloom_indexes) |
| 38 | printf(" bloom_indexes"); |
| 39 | if (graph->chunk_bloom_data) |
| 40 | printf(" bloom_data"); |
| 41 | printf("\n"); |
| 42 | |
| 43 | printf("options:"); |
| 44 | if (graph->bloom_filter_settings) |
| 45 | printf(" bloom(%"PRIu32",%"PRIu32",%"PRIu32")", |
| 46 | graph->bloom_filter_settings->hash_version, |
| 47 | graph->bloom_filter_settings->bits_per_entry, |
| 48 | graph->bloom_filter_settings->num_hashes); |
| 49 | if (graph->read_generation_data) |
| 50 | printf(" read_generation_data"); |
| 51 | if (graph->topo_levels) |
| 52 | printf(" topo_levels"); |
| 53 | printf("\n"); |
| 54 | } |
| 55 | |
| 56 | static void dump_graph_bloom_filters(struct commit_graph *graph) |
| 57 | { |
| 58 | uint32_t i; |
| 59 | |
| 60 | for (i = 0; i < graph->num_commits + graph->num_commits_in_base; i++) { |
| 61 | struct bloom_filter filter = { 0 }; |
| 62 | size_t j; |
| 63 | |
| 64 | if (load_bloom_filter_from_graph(graph, &filter, i) < 0) { |
| 65 | fprintf(stderr, "missing Bloom filter for graph " |
| 66 | "position %"PRIu32"\n", i); |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | for (j = 0; j < filter.len; j++) |
| 71 | printf("%02x", filter.data[j]); |
| 72 | if (filter.len) |
| 73 | printf("\n"); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | int cmd__read_graph(int argc, const char **argv) |
| 78 | { |
| 79 | struct commit_graph *graph = NULL; |
| 80 | struct odb_source *source; |
| 81 | int ret = 0; |
| 82 | |
| 83 | setup_git_directory(the_repository); |
| 84 | source = the_repository->objects->source; |
| 85 | |
| 86 | prepare_repo_settings(the_repository); |
| 87 | |
| 88 | graph = read_commit_graph_one(the_repository, source->path); |
| 89 | if (!graph) { |
| 90 | ret = 1; |
| 91 | goto done; |
| 92 | } |
| 93 | |
| 94 | if (argc <= 1) |
| 95 | dump_graph_info(graph); |
| 96 | else if (!strcmp(argv[1], "bloom-filters")) |
| 97 | dump_graph_bloom_filters(graph); |
| 98 | else if (!strcmp(argv[1], "commit-info")) { |
| 99 | int i; |
| 100 | for (i = 2; i < argc; i++) { |
| 101 | struct object_id oid; |
| 102 | struct commit *c; |
| 103 | |
| 104 | if (repo_get_oid(the_repository, argv[i], &oid)) |
| 105 | die("not a valid object name: '%s'", argv[i]); |
| 106 | c = lookup_commit_in_graph(the_repository, &oid); |
| 107 | if (!c) { |
| 108 | fprintf(stderr, "%s: not in graph\n", argv[i]); |
| 109 | ret = 1; |
| 110 | continue; |
| 111 | } |
| 112 | printf("%s generation %"PRIuMAX"\n", |
| 113 | oid_to_hex(&oid), |
| 114 | (uintmax_t)commit_graph_generation(c)); |
| 115 | } |
| 116 | } else { |
| 117 | fprintf(stderr, "unknown sub-command: '%s'\n", argv[1]); |
| 118 | ret = 1; |
| 119 | } |
| 120 | |
| 121 | done: |
| 122 | free_commit_graph(graph); |
| 123 | return ret; |
| 124 | } |