Skip to content

Commit fb3dc10

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ea61f7 commit fb3dc10

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

commit-graph.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static int graph_read_oid_lookup(const unsigned char *chunk_start,
311311
{
312312
struct commit_graph *g = data;
313313
g->chunk_oid_lookup = chunk_start;
314-
if (chunk_size / g->hash_len != g->num_commits)
314+
if (chunk_size / g->hash_algo->rawsz != g->num_commits)
315315
return error(_("commit-graph OID lookup chunk is the wrong size"));
316316
return 0;
317317
}
@@ -413,7 +413,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
413413

414414
graph = alloc_commit_graph();
415415

416-
graph->hash_len = the_hash_algo->rawsz;
416+
graph->hash_algo = the_hash_algo;
417417
graph->num_chunks = *(unsigned char*)(data + 6);
418418
graph->data = graph_map;
419419
graph->data_len = graph_size;
@@ -478,7 +478,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
478478
FREE_AND_NULL(graph->bloom_filter_settings);
479479
}
480480

481-
oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len,
481+
oidread(&graph->oid, graph->data + graph->data_len - graph->hash_algo->rawsz,
482482
the_repository->hash_algo);
483483

484484
free_chunkfile(cf);
@@ -584,7 +584,7 @@ static int add_graph_to_chain(struct commit_graph *g,
584584
return 0;
585585
}
586586

587-
if (g->chunk_base_graphs_size / g->hash_len < n) {
587+
if (g->chunk_base_graphs_size / g->hash_algo->rawsz < n) {
588588
warning(_("commit-graph base graphs chunk is too small"));
589589
return 0;
590590
}
@@ -594,7 +594,7 @@ static int add_graph_to_chain(struct commit_graph *g,
594594

595595
if (!cur_g ||
596596
!oideq(&oids[n], &cur_g->oid) ||
597-
!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n),
597+
!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n),
598598
the_repository->hash_algo)) {
599599
warning(_("commit-graph chain does not match"));
600600
return 0;
@@ -806,7 +806,7 @@ int generation_numbers_enabled(struct repository *r)
806806
return 0;
807807

808808
first_generation = get_be32(g->chunk_commit_data +
809-
g->hash_len + 8) >> 2;
809+
g->hash_algo->rawsz + 8) >> 2;
810810

811811
return !!first_generation;
812812
}
@@ -850,7 +850,7 @@ void close_commit_graph(struct object_database *o)
850850
static int bsearch_graph(struct commit_graph *g, const struct object_id *oid, uint32_t *pos)
851851
{
852852
return bsearch_hash(oid->hash, g->chunk_oid_fanout,
853-
g->chunk_oid_lookup, g->hash_len, pos);
853+
g->chunk_oid_lookup, g->hash_algo->rawsz, pos);
854854
}
855855

856856
static void load_oid_from_graph(struct commit_graph *g,
@@ -870,7 +870,7 @@ static void load_oid_from_graph(struct commit_graph *g,
870870

871871
lex_index = pos - g->num_commits_in_base;
872872

873-
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index),
873+
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, lex_index),
874874
the_repository->hash_algo);
875875
}
876876

@@ -912,8 +912,8 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
912912
graph_data = commit_graph_data_at(item);
913913
graph_data->graph_pos = pos;
914914

915-
date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
916-
date_low = get_be32(commit_data + g->hash_len + 12);
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);
917917
item->date = (timestamp_t)((date_high << 32) | date_low);
918918

919919
if (g->read_generation_data) {
@@ -931,10 +931,10 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
931931
} else
932932
graph_data->generation = item->date + offset;
933933
} else
934-
graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
934+
graph_data->generation = get_be32(commit_data + g->hash_algo->rawsz + 8) >> 2;
935935

936936
if (g->topo_levels)
937-
*topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_len + 8) >> 2;
937+
*topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_algo->rawsz + 8) >> 2;
938938
}
939939

940940
static inline void set_commit_tree(struct commit *c, struct tree *t)
@@ -958,20 +958,20 @@ static int fill_commit_in_graph(struct repository *r,
958958
fill_commit_graph_info(item, g, pos);
959959

960960
lex_index = pos - g->num_commits_in_base;
961-
commit_data = g->chunk_commit_data + st_mult(g->hash_len + 16, lex_index);
961+
commit_data = g->chunk_commit_data + st_mult(g->hash_algo->rawsz + 16, lex_index);
962962

963963
item->object.parsed = 1;
964964

965965
set_commit_tree(item, NULL);
966966

967967
pptr = &item->parents;
968968

969-
edge_value = get_be32(commit_data + g->hash_len);
969+
edge_value = get_be32(commit_data + g->hash_algo->rawsz);
970970
if (edge_value == GRAPH_PARENT_NONE)
971971
return 1;
972972
pptr = insert_parent_or_die(r, g, edge_value, pptr);
973973

974-
edge_value = get_be32(commit_data + g->hash_len + 4);
974+
edge_value = get_be32(commit_data + g->hash_algo->rawsz + 4);
975975
if (edge_value == GRAPH_PARENT_NONE)
976976
return 1;
977977
if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) {
@@ -2623,7 +2623,7 @@ int write_commit_graph(struct odb_source *source,
26232623
struct commit_graph *g = ctx.r->objects->commit_graph;
26242624
for (i = 0; i < g->num_commits; i++) {
26252625
struct object_id oid;
2626-
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2626+
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
26272627
the_repository->hash_algo);
26282628
oid_array_append(&ctx.oids, &oid);
26292629
}
@@ -2754,7 +2754,7 @@ static int verify_one_commit_graph(struct repository *r,
27542754
for (i = 0; i < g->num_commits; i++) {
27552755
struct commit *graph_commit;
27562756

2757-
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2757+
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
27582758
the_repository->hash_algo);
27592759

27602760
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
@@ -2799,7 +2799,7 @@ static int verify_one_commit_graph(struct repository *r,
27992799
timestamp_t generation;
28002800

28012801
display_progress(progress, ++(*seen));
2802-
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
2802+
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
28032803
the_repository->hash_algo);
28042804

28052805
graph_commit = lookup_commit(r, &cur_oid);

commit-graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct commit_graph {
8484
const unsigned char *data;
8585
size_t data_len;
8686

87-
unsigned char hash_len;
87+
const struct git_hash_algo *hash_algo;
8888
unsigned char num_chunks;
8989
uint32_t num_commits;
9090
struct object_id oid;

0 commit comments

Comments
 (0)