2525
2626#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
2727
28- #define GRAPH_VERSION_1 0x1
29- #define GRAPH_VERSION GRAPH_VERSION_1
30-
3128#define GRAPH_EXTRA_EDGES_NEEDED 0x80000000
3229#define GRAPH_EDGE_LAST_MASK 0x7fffffff
3330#define GRAPH_PARENT_NONE 0x70000000
@@ -173,30 +170,35 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
173170 }
174171
175172 graph_version = * (unsigned char * )(data + 4 );
176- if (graph_version != GRAPH_VERSION ) {
173+ if (graph_version != 1 ) {
177174 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 );
186176 return NULL ;
187177 }
188178
189179 graph = alloc_commit_graph ();
190180
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+
191195 graph -> hash_len = the_hash_algo -> rawsz ;
192- graph -> num_chunks = * (unsigned char * )(data + 6 );
193196 graph -> graph_fd = fd ;
194197 graph -> data = graph_map ;
195198 graph -> data_len = graph_size ;
196199
197200 last_chunk_id = 0 ;
198201 last_chunk_offset = 8 ;
199- chunk_lookup = data + 8 ;
200202 for (i = 0 ; i < graph -> num_chunks ; i ++ ) {
201203 uint32_t chunk_id ;
202204 uint64_t chunk_offset ;
@@ -888,10 +890,22 @@ int write_commit_graph(const char *obj_dir,
888890 int res = 0 ;
889891 int append = flags & COMMIT_GRAPH_APPEND ;
890892 int report_progress = flags & COMMIT_GRAPH_PROGRESS ;
893+ int version = 0 ;
894+ int header_size = 0 ;
891895
892896 if (!commit_graph_compatible (the_repository ))
893897 return 0 ;
894898
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+
895909 oids .nr = 0 ;
896910 approx_nr_objects = approximate_object_count ();
897911 oids .alloc = approx_nr_objects / 32 ;
@@ -1076,10 +1090,16 @@ int write_commit_graph(const char *obj_dir,
10761090
10771091 hashwrite_be32 (f , GRAPH_SIGNATURE );
10781092
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+ }
10831103
10841104 chunk_ids [0 ] = GRAPH_CHUNKID_OIDFANOUT ;
10851105 chunk_ids [1 ] = GRAPH_CHUNKID_OIDLOOKUP ;
@@ -1090,7 +1110,7 @@ int write_commit_graph(const char *obj_dir,
10901110 chunk_ids [3 ] = 0 ;
10911111 chunk_ids [4 ] = 0 ;
10921112
1093- chunk_offsets [0 ] = 8 + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1113+ chunk_offsets [0 ] = header_size + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
10941114 chunk_offsets [1 ] = chunk_offsets [0 ] + GRAPH_FANOUT_SIZE ;
10951115 chunk_offsets [2 ] = chunk_offsets [1 ] + hashsz * commits .nr ;
10961116 chunk_offsets [3 ] = chunk_offsets [2 ] + (hashsz + 16 ) * commits .nr ;
0 commit comments