Skip to content

Commit 5ea61f7

Browse files
pks-tgitster
authored andcommitted
commit-graph: stop using the_hash_algo via macros
We have two macros `GRAPH_DATA_WIDTH` and `GRAPH_MIN_SIZE` that compute hash-dependent sizes. They do so by using the global `the_hash_algo` variable though, which we want to get rid of over time. Convert these macros into functions that accept the hash algorithm as input parameter. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c7ca23 commit 5ea61f7

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

commit-graph.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ void git_test_write_commit_graph_or_die(void)
5353
#define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
5454
#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
5555

56-
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
57-
5856
#define GRAPH_VERSION_1 0x1
5957
#define GRAPH_VERSION GRAPH_VERSION_1
6058

@@ -66,8 +64,6 @@ void git_test_write_commit_graph_or_die(void)
6664

6765
#define GRAPH_HEADER_SIZE 8
6866
#define GRAPH_FANOUT_SIZE (4 * 256)
69-
#define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * CHUNK_TOC_ENTRY_SIZE \
70-
+ GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
7167

7268
#define CORRECTED_COMMIT_DATE_OFFSET_OVERFLOW (1ULL << 31)
7369

@@ -80,6 +76,16 @@ define_commit_slab(topo_level_slab, uint32_t);
8076
define_commit_slab(commit_pos, int);
8177
static struct commit_pos commit_pos = COMMIT_SLAB_INIT(1, commit_pos);
8278

79+
static size_t graph_data_width(const struct git_hash_algo *algop)
80+
{
81+
return algop->rawsz + 16;
82+
}
83+
84+
static size_t graph_min_size(const struct git_hash_algo *algop)
85+
{
86+
return GRAPH_HEADER_SIZE + 4 * CHUNK_TOC_ENTRY_SIZE + GRAPH_FANOUT_SIZE + algop->rawsz;
87+
}
88+
8389
static void set_commit_pos(struct repository *r, const struct object_id *oid)
8490
{
8591
static int32_t max_pos;
@@ -258,7 +264,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
258264

259265
graph_size = xsize_t(st->st_size);
260266

261-
if (graph_size < GRAPH_MIN_SIZE) {
267+
if (graph_size < graph_min_size(the_hash_algo)) {
262268
close(fd);
263269
error(_("commit-graph file is too small"));
264270
return NULL;
@@ -314,7 +320,7 @@ static int graph_read_commit_data(const unsigned char *chunk_start,
314320
size_t chunk_size, void *data)
315321
{
316322
struct commit_graph *g = data;
317-
if (chunk_size / GRAPH_DATA_WIDTH != g->num_commits)
323+
if (chunk_size / graph_data_width(the_hash_algo) != g->num_commits)
318324
return error(_("commit-graph commit data chunk is wrong size"));
319325
g->chunk_commit_data = chunk_start;
320326
return 0;
@@ -379,7 +385,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
379385
if (!graph_map)
380386
return NULL;
381387

382-
if (graph_size < GRAPH_MIN_SIZE)
388+
if (graph_size < graph_min_size(the_hash_algo))
383389
return NULL;
384390

385391
data = (const unsigned char *)graph_map;
@@ -901,7 +907,7 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
901907
die(_("invalid commit position. commit-graph is likely corrupt"));
902908

903909
lex_index = pos - g->num_commits_in_base;
904-
commit_data = g->chunk_commit_data + st_mult(GRAPH_DATA_WIDTH, lex_index);
910+
commit_data = g->chunk_commit_data + st_mult(graph_data_width(the_hash_algo), lex_index);
905911

906912
graph_data = commit_graph_data_at(item);
907913
graph_data->graph_pos = pos;
@@ -1105,7 +1111,8 @@ static struct tree *load_tree_for_commit(struct repository *r,
11051111
g = g->base_graph;
11061112

11071113
commit_data = g->chunk_commit_data +
1108-
st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
1114+
st_mult(graph_data_width(the_hash_algo),
1115+
graph_pos - g->num_commits_in_base);
11091116

11101117
oidread(&oid, commit_data, the_repository->hash_algo);
11111118
set_commit_tree(c, lookup_tree(r, &oid));

0 commit comments

Comments
 (0)