25
25
26
26
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
27
27
28
- #define GRAPH_VERSION_1 0x1
29
- #define GRAPH_VERSION GRAPH_VERSION_1
30
-
31
28
#define GRAPH_EXTRA_EDGES_NEEDED 0x80000000
32
29
#define GRAPH_EDGE_LAST_MASK 0x7fffffff
33
30
#define GRAPH_PARENT_NONE 0x70000000
@@ -173,30 +170,35 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
173
170
}
174
171
175
172
graph_version = * (unsigned char * )(data + 4 );
176
- if (graph_version != GRAPH_VERSION ) {
173
+ if (graph_version != 1 ) {
177
174
error (_ ("commit-graph version %X does not match version %X" ),
178
- graph_version , GRAPH_VERSION );
179
- return NULL ;
180
- }
181
-
182
- hash_version = * (unsigned char * )(data + 5 );
183
- if (hash_version != oid_version ()) {
184
- error (_ ("commit-graph hash version %X does not match version %X" ),
185
- hash_version , oid_version ());
175
+ graph_version , 1 );
186
176
return NULL ;
187
177
}
188
178
189
179
graph = alloc_commit_graph ();
190
180
181
+ switch (graph_version ) {
182
+ case 1 :
183
+ hash_version = * (unsigned char * )(data + 5 );
184
+ if (hash_version != oid_version ()) {
185
+ error (_ ("commit-graph hash version %X does not match version %X" ),
186
+ hash_version , oid_version ());
187
+ return NULL ;
188
+ }
189
+
190
+ graph -> num_chunks = * (unsigned char * )(data + 6 );
191
+ chunk_lookup = data + 8 ;
192
+ break ;
193
+ }
194
+
191
195
graph -> hash_len = the_hash_algo -> rawsz ;
192
- graph -> num_chunks = * (unsigned char * )(data + 6 );
193
196
graph -> graph_fd = fd ;
194
197
graph -> data = graph_map ;
195
198
graph -> data_len = graph_size ;
196
199
197
200
last_chunk_id = 0 ;
198
201
last_chunk_offset = 8 ;
199
- chunk_lookup = data + 8 ;
200
202
for (i = 0 ; i < graph -> num_chunks ; i ++ ) {
201
203
uint32_t chunk_id ;
202
204
uint64_t chunk_offset ;
@@ -851,14 +853,15 @@ static int add_ref_to_list(const char *refname,
851
853
return 0 ;
852
854
}
853
855
854
- int write_commit_graph_reachable (const char * obj_dir , unsigned int flags )
856
+ int write_commit_graph_reachable (const char * obj_dir , unsigned int flags ,
857
+ unsigned char version )
855
858
{
856
859
struct string_list list = STRING_LIST_INIT_DUP ;
857
860
int result ;
858
861
859
862
for_each_ref (add_ref_to_list , & list );
860
863
result = write_commit_graph (obj_dir , NULL , & list ,
861
- flags );
864
+ flags , version );
862
865
863
866
string_list_clear (& list , 0 );
864
867
return result ;
@@ -867,7 +870,8 @@ int write_commit_graph_reachable(const char *obj_dir, unsigned int flags)
867
870
int write_commit_graph (const char * obj_dir ,
868
871
struct string_list * pack_indexes ,
869
872
struct string_list * commit_hex ,
870
- unsigned int flags )
873
+ unsigned int flags ,
874
+ unsigned char version )
871
875
{
872
876
struct packed_oid_list oids ;
873
877
struct packed_commit_list commits ;
@@ -888,10 +892,19 @@ int write_commit_graph(const char *obj_dir,
888
892
int res = 0 ;
889
893
int append = flags & COMMIT_GRAPH_APPEND ;
890
894
int report_progress = flags & COMMIT_GRAPH_PROGRESS ;
895
+ int header_size = 0 ;
891
896
892
897
if (!commit_graph_compatible (the_repository ))
893
898
return 0 ;
894
899
900
+ if (!version )
901
+ version = 1 ;
902
+ if (version != 1 ) {
903
+ error (_ ("unsupported commit-graph version %d" ),
904
+ version );
905
+ return 1 ;
906
+ }
907
+
895
908
oids .nr = 0 ;
896
909
approx_nr_objects = approximate_object_count ();
897
910
oids .alloc = approx_nr_objects / 32 ;
@@ -1076,10 +1089,16 @@ int write_commit_graph(const char *obj_dir,
1076
1089
1077
1090
hashwrite_be32 (f , GRAPH_SIGNATURE );
1078
1091
1079
- hashwrite_u8 (f , GRAPH_VERSION );
1080
- hashwrite_u8 (f , oid_version ());
1081
- hashwrite_u8 (f , num_chunks );
1082
- hashwrite_u8 (f , 0 ); /* unused padding byte */
1092
+ hashwrite_u8 (f , version );
1093
+
1094
+ switch (version ) {
1095
+ case 1 :
1096
+ hashwrite_u8 (f , oid_version ());
1097
+ hashwrite_u8 (f , num_chunks );
1098
+ hashwrite_u8 (f , 0 ); /* unused padding byte */
1099
+ header_size = 8 ;
1100
+ break ;
1101
+ }
1083
1102
1084
1103
chunk_ids [0 ] = GRAPH_CHUNKID_OIDFANOUT ;
1085
1104
chunk_ids [1 ] = GRAPH_CHUNKID_OIDLOOKUP ;
@@ -1090,7 +1109,7 @@ int write_commit_graph(const char *obj_dir,
1090
1109
chunk_ids [3 ] = 0 ;
1091
1110
chunk_ids [4 ] = 0 ;
1092
1111
1093
- chunk_offsets [0 ] = 8 + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1112
+ chunk_offsets [0 ] = header_size + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1094
1113
chunk_offsets [1 ] = chunk_offsets [0 ] + GRAPH_FANOUT_SIZE ;
1095
1114
chunk_offsets [2 ] = chunk_offsets [1 ] + hashsz * commits .nr ;
1096
1115
chunk_offsets [3 ] = chunk_offsets [2 ] + (hashsz + 16 ) * commits .nr ;
0 commit comments