Git fork

commit-graph: store the hash algorithm instead of its length

The commit-graph stores the length of the hash algorithm it uses. In
subsequent commits we'll need to pass the whole hash algorithm around
though, which we currently don't have access to.

Refactor the code so that we store the hash algorithm instead of only
its size.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
e45402bb 3481cb7d

+19 -19
+18 -18
commit-graph.c
··· 312 { 313 struct commit_graph *g = data; 314 g->chunk_oid_lookup = chunk_start; 315 - if (chunk_size / g->hash_len != g->num_commits) 316 return error(_("commit-graph OID lookup chunk is the wrong size")); 317 return 0; 318 } ··· 414 415 graph = alloc_commit_graph(); 416 417 - graph->hash_len = the_hash_algo->rawsz; 418 graph->num_chunks = *(unsigned char*)(data + 6); 419 graph->data = graph_map; 420 graph->data_len = graph_size; ··· 479 FREE_AND_NULL(graph->bloom_filter_settings); 480 } 481 482 - oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len, 483 the_repository->hash_algo); 484 485 free_chunkfile(cf); ··· 585 return 0; 586 } 587 588 - if (g->chunk_base_graphs_size / g->hash_len < n) { 589 warning(_("commit-graph base graphs chunk is too small")); 590 return 0; 591 } ··· 595 596 if (!cur_g || 597 !oideq(&oids[n], &cur_g->oid) || 598 - !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n), 599 the_repository->hash_algo)) { 600 warning(_("commit-graph chain does not match")); 601 return 0; ··· 806 return 0; 807 808 first_generation = get_be32(g->chunk_commit_data + 809 - g->hash_len + 8) >> 2; 810 811 return !!first_generation; 812 } ··· 850 static int bsearch_graph(struct commit_graph *g, const struct object_id *oid, uint32_t *pos) 851 { 852 return bsearch_hash(oid->hash, g->chunk_oid_fanout, 853 - g->chunk_oid_lookup, g->hash_len, pos); 854 } 855 856 static void load_oid_from_graph(struct commit_graph *g, ··· 870 871 lex_index = pos - g->num_commits_in_base; 872 873 - oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index), 874 the_repository->hash_algo); 875 } 876 ··· 912 graph_data = commit_graph_data_at(item); 913 graph_data->graph_pos = pos; 914 915 - date_high = get_be32(commit_data + g->hash_len + 8) & 0x3; 916 - date_low = get_be32(commit_data + g->hash_len + 12); 917 item->date = (timestamp_t)((date_high << 32) | date_low); 918 919 if (g->read_generation_data) { ··· 931 } else 932 graph_data->generation = item->date + offset; 933 } else 934 - graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2; 935 936 if (g->topo_levels) 937 - *topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_len + 8) >> 2; 938 } 939 940 static inline void set_commit_tree(struct commit *c, struct tree *t) ··· 958 fill_commit_graph_info(item, g, pos); 959 960 lex_index = pos - g->num_commits_in_base; 961 - commit_data = g->chunk_commit_data + st_mult(g->hash_len + 16, lex_index); 962 963 item->object.parsed = 1; 964 ··· 966 967 pptr = &item->parents; 968 969 - edge_value = get_be32(commit_data + g->hash_len); 970 if (edge_value == GRAPH_PARENT_NONE) 971 return 1; 972 pptr = insert_parent_or_die(r, g, edge_value, pptr); 973 974 - edge_value = get_be32(commit_data + g->hash_len + 4); 975 if (edge_value == GRAPH_PARENT_NONE) 976 return 1; 977 if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) { ··· 2624 struct commit_graph *g = ctx.r->objects->commit_graph; 2625 for (i = 0; i < g->num_commits; i++) { 2626 struct object_id oid; 2627 - oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i), 2628 the_repository->hash_algo); 2629 oid_array_append(&ctx.oids, &oid); 2630 } ··· 2755 for (i = 0; i < g->num_commits; i++) { 2756 struct commit *graph_commit; 2757 2758 - oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i), 2759 the_repository->hash_algo); 2760 2761 if (i && oidcmp(&prev_oid, &cur_oid) >= 0) ··· 2800 timestamp_t generation; 2801 2802 display_progress(progress, ++(*seen)); 2803 - oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i), 2804 the_repository->hash_algo); 2805 2806 graph_commit = lookup_commit(r, &cur_oid);
··· 312 { 313 struct commit_graph *g = data; 314 g->chunk_oid_lookup = chunk_start; 315 + if (chunk_size / g->hash_algo->rawsz != g->num_commits) 316 return error(_("commit-graph OID lookup chunk is the wrong size")); 317 return 0; 318 } ··· 414 415 graph = alloc_commit_graph(); 416 417 + graph->hash_algo = the_hash_algo; 418 graph->num_chunks = *(unsigned char*)(data + 6); 419 graph->data = graph_map; 420 graph->data_len = graph_size; ··· 479 FREE_AND_NULL(graph->bloom_filter_settings); 480 } 481 482 + oidread(&graph->oid, graph->data + graph->data_len - graph->hash_algo->rawsz, 483 the_repository->hash_algo); 484 485 free_chunkfile(cf); ··· 585 return 0; 586 } 587 588 + if (g->chunk_base_graphs_size / g->hash_algo->rawsz < n) { 589 warning(_("commit-graph base graphs chunk is too small")); 590 return 0; 591 } ··· 595 596 if (!cur_g || 597 !oideq(&oids[n], &cur_g->oid) || 598 + !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n), 599 the_repository->hash_algo)) { 600 warning(_("commit-graph chain does not match")); 601 return 0; ··· 806 return 0; 807 808 first_generation = get_be32(g->chunk_commit_data + 809 + g->hash_algo->rawsz + 8) >> 2; 810 811 return !!first_generation; 812 } ··· 850 static int bsearch_graph(struct commit_graph *g, const struct object_id *oid, uint32_t *pos) 851 { 852 return bsearch_hash(oid->hash, g->chunk_oid_fanout, 853 + g->chunk_oid_lookup, g->hash_algo->rawsz, pos); 854 } 855 856 static void load_oid_from_graph(struct commit_graph *g, ··· 870 871 lex_index = pos - g->num_commits_in_base; 872 873 + oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, lex_index), 874 the_repository->hash_algo); 875 } 876 ··· 912 graph_data = commit_graph_data_at(item); 913 graph_data->graph_pos = pos; 914 915 + date_high = get_be32(commit_data + g->hash_algo->rawsz + 8) & 0x3; 916 + date_low = get_be32(commit_data + g->hash_algo->rawsz + 12); 917 item->date = (timestamp_t)((date_high << 32) | date_low); 918 919 if (g->read_generation_data) { ··· 931 } else 932 graph_data->generation = item->date + offset; 933 } else 934 + graph_data->generation = get_be32(commit_data + g->hash_algo->rawsz + 8) >> 2; 935 936 if (g->topo_levels) 937 + *topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_algo->rawsz + 8) >> 2; 938 } 939 940 static inline void set_commit_tree(struct commit *c, struct tree *t) ··· 958 fill_commit_graph_info(item, g, pos); 959 960 lex_index = pos - g->num_commits_in_base; 961 + commit_data = g->chunk_commit_data + st_mult(g->hash_algo->rawsz + 16, lex_index); 962 963 item->object.parsed = 1; 964 ··· 966 967 pptr = &item->parents; 968 969 + edge_value = get_be32(commit_data + g->hash_algo->rawsz); 970 if (edge_value == GRAPH_PARENT_NONE) 971 return 1; 972 pptr = insert_parent_or_die(r, g, edge_value, pptr); 973 974 + edge_value = get_be32(commit_data + g->hash_algo->rawsz + 4); 975 if (edge_value == GRAPH_PARENT_NONE) 976 return 1; 977 if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) { ··· 2624 struct commit_graph *g = ctx.r->objects->commit_graph; 2625 for (i = 0; i < g->num_commits; i++) { 2626 struct object_id oid; 2627 + oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i), 2628 the_repository->hash_algo); 2629 oid_array_append(&ctx.oids, &oid); 2630 } ··· 2755 for (i = 0; i < g->num_commits; i++) { 2756 struct commit *graph_commit; 2757 2758 + oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i), 2759 the_repository->hash_algo); 2760 2761 if (i && oidcmp(&prev_oid, &cur_oid) >= 0) ··· 2800 timestamp_t generation; 2801 2802 display_progress(progress, ++(*seen)); 2803 + oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i), 2804 the_repository->hash_algo); 2805 2806 graph_commit = lookup_commit(r, &cur_oid);
+1 -1
commit-graph.h
··· 84 const unsigned char *data; 85 size_t data_len; 86 87 - unsigned char hash_len; 88 unsigned char num_chunks; 89 uint32_t num_commits; 90 struct object_id oid;
··· 84 const unsigned char *data; 85 size_t data_len; 86 87 + const struct git_hash_algo *hash_algo; 88 unsigned char num_chunks; 89 uint32_t num_commits; 90 struct object_id oid;