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 ;
@@ -888,10 +890,22 @@ int write_commit_graph(const char *obj_dir,
888
890
int res = 0 ;
889
891
int append = flags & COMMIT_GRAPH_APPEND ;
890
892
int report_progress = flags & COMMIT_GRAPH_PROGRESS ;
893
+ int version = 0 ;
894
+ int header_size = 0 ;
891
895
892
896
if (!commit_graph_compatible (the_repository ))
893
897
return 0 ;
894
898
899
+ if (flags & COMMIT_GRAPH_VERSION_1 )
900
+ version = 1 ;
901
+ if (!version )
902
+ version = 1 ;
903
+ if (version != 1 ) {
904
+ error (_ ("unsupported commit-graph version %d" ),
905
+ version );
906
+ return 1 ;
907
+ }
908
+
895
909
oids .nr = 0 ;
896
910
approx_nr_objects = approximate_object_count ();
897
911
oids .alloc = approx_nr_objects / 32 ;
@@ -1076,10 +1090,16 @@ int write_commit_graph(const char *obj_dir,
1076
1090
1077
1091
hashwrite_be32 (f , GRAPH_SIGNATURE );
1078
1092
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 */
1093
+ hashwrite_u8 (f , version );
1094
+
1095
+ switch (version ) {
1096
+ case 1 :
1097
+ hashwrite_u8 (f , oid_version ());
1098
+ hashwrite_u8 (f , num_chunks );
1099
+ hashwrite_u8 (f , 0 ); /* unused padding byte */
1100
+ header_size = 8 ;
1101
+ break ;
1102
+ }
1083
1103
1084
1104
chunk_ids [0 ] = GRAPH_CHUNKID_OIDFANOUT ;
1085
1105
chunk_ids [1 ] = GRAPH_CHUNKID_OIDLOOKUP ;
@@ -1090,7 +1110,7 @@ int write_commit_graph(const char *obj_dir,
1090
1110
chunk_ids [3 ] = 0 ;
1091
1111
chunk_ids [4 ] = 0 ;
1092
1112
1093
- chunk_offsets [0 ] = 8 + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1113
+ chunk_offsets [0 ] = header_size + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1094
1114
chunk_offsets [1 ] = chunk_offsets [0 ] + GRAPH_FANOUT_SIZE ;
1095
1115
chunk_offsets [2 ] = chunk_offsets [1 ] + hashsz * commits .nr ;
1096
1116
chunk_offsets [3 ] = chunk_offsets [2 ] + (hashsz + 16 ) * commits .nr ;
0 commit comments