@@ -53,8 +53,6 @@ void git_test_write_commit_graph_or_die(void)
53
53
#define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
54
54
#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
55
55
56
- #define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
57
-
58
56
#define GRAPH_VERSION_1 0x1
59
57
#define GRAPH_VERSION GRAPH_VERSION_1
60
58
@@ -66,8 +64,6 @@ void git_test_write_commit_graph_or_die(void)
66
64
67
65
#define GRAPH_HEADER_SIZE 8
68
66
#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)
71
67
72
68
#define CORRECTED_COMMIT_DATE_OFFSET_OVERFLOW (1ULL << 31)
73
69
@@ -80,6 +76,16 @@ define_commit_slab(topo_level_slab, uint32_t);
80
76
define_commit_slab (commit_pos , int );
81
77
static struct commit_pos commit_pos = COMMIT_SLAB_INIT (1 , commit_pos );
82
78
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
+
83
89
static void set_commit_pos (struct repository * r , const struct object_id * oid )
84
90
{
85
91
static int32_t max_pos ;
@@ -258,7 +264,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
258
264
259
265
graph_size = xsize_t (st -> st_size );
260
266
261
- if (graph_size < GRAPH_MIN_SIZE ) {
267
+ if (graph_size < graph_min_size ( the_hash_algo ) ) {
262
268
close (fd );
263
269
error (_ ("commit-graph file is too small" ));
264
270
return NULL ;
@@ -314,7 +320,7 @@ static int graph_read_commit_data(const unsigned char *chunk_start,
314
320
size_t chunk_size , void * data )
315
321
{
316
322
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 )
318
324
return error (_ ("commit-graph commit data chunk is wrong size" ));
319
325
g -> chunk_commit_data = chunk_start ;
320
326
return 0 ;
@@ -379,7 +385,7 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
379
385
if (!graph_map )
380
386
return NULL ;
381
387
382
- if (graph_size < GRAPH_MIN_SIZE )
388
+ if (graph_size < graph_min_size ( the_hash_algo ) )
383
389
return NULL ;
384
390
385
391
data = (const unsigned char * )graph_map ;
@@ -901,7 +907,7 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
901
907
die (_ ("invalid commit position. commit-graph is likely corrupt" ));
902
908
903
909
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 );
905
911
906
912
graph_data = commit_graph_data_at (item );
907
913
graph_data -> graph_pos = pos ;
@@ -1105,7 +1111,8 @@ static struct tree *load_tree_for_commit(struct repository *r,
1105
1111
g = g -> base_graph ;
1106
1112
1107
1113
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 );
1109
1116
1110
1117
oidread (& oid , commit_data , the_repository -> hash_algo );
1111
1118
set_commit_tree (c , lookup_tree (r , & oid ));
0 commit comments