@@ -54,8 +54,6 @@ void git_test_write_commit_graph_or_die(void)
5454#define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
5555#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
5656
57- #define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
58-
5957#define GRAPH_VERSION_1 0x1
6058#define GRAPH_VERSION GRAPH_VERSION_1
6159
@@ -67,8 +65,6 @@ void git_test_write_commit_graph_or_die(void)
6765
6866#define GRAPH_HEADER_SIZE 8
6967#define GRAPH_FANOUT_SIZE (4 * 256)
70- #define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * CHUNK_TOC_ENTRY_SIZE \
71- + GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
7268
7369#define CORRECTED_COMMIT_DATE_OFFSET_OVERFLOW (1ULL << 31)
7470
@@ -81,6 +77,16 @@ define_commit_slab(topo_level_slab, uint32_t);
8177define_commit_slab (commit_pos , int );
8278static struct commit_pos commit_pos = COMMIT_SLAB_INIT (1 , commit_pos );
8379
80+ static size_t graph_data_width (const struct git_hash_algo * algop )
81+ {
82+ return algop -> rawsz + 16 ;
83+ }
84+
85+ static size_t graph_min_size (const struct git_hash_algo * algop )
86+ {
87+ return GRAPH_HEADER_SIZE + 4 * CHUNK_TOC_ENTRY_SIZE + GRAPH_FANOUT_SIZE + algop -> rawsz ;
88+ }
89+
8490static void set_commit_pos (struct repository * r , const struct object_id * oid )
8591{
8692 static int32_t max_pos ;
@@ -259,7 +265,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
259265
260266 graph_size = xsize_t (st -> st_size );
261267
262- if (graph_size < GRAPH_MIN_SIZE ) {
268+ if (graph_size < graph_min_size ( the_hash_algo ) ) {
263269 close (fd );
264270 error (_ ("commit-graph file is too small" ));
265271 return NULL ;
@@ -315,7 +321,7 @@ static int graph_read_commit_data(const unsigned char *chunk_start,
315321 size_t chunk_size , void * data )
316322{
317323 struct commit_graph * g = data ;
318- if (chunk_size / GRAPH_DATA_WIDTH != g -> num_commits )
324+ if (chunk_size / graph_data_width ( the_hash_algo ) != g -> num_commits )
319325 return error (_ ("commit-graph commit data chunk is wrong size" ));
320326 g -> chunk_commit_data = chunk_start ;
321327 return 0 ;
@@ -380,7 +386,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
380386 if (!graph_map )
381387 return NULL ;
382388
383- if (graph_size < GRAPH_MIN_SIZE )
389+ if (graph_size < graph_min_size ( the_hash_algo ) )
384390 return NULL ;
385391
386392 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