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_PARENT_MISSING 0x7fffffff
3330#define GRAPH_EDGE_LAST_MASK 0x7fffffff
@@ -118,30 +115,35 @@ struct commit_graph *load_commit_graph_one(const char *graph_file)
118115 }
119116
120117 graph_version = * (unsigned char * )(data + 4 );
121- if (graph_version != GRAPH_VERSION ) {
118+ if (graph_version != 1 ) {
122119 error (_ ("graph version %X does not match version %X" ),
123- graph_version , GRAPH_VERSION );
124- goto cleanup_fail ;
125- }
126-
127- hash_version = * (unsigned char * )(data + 5 );
128- if (hash_version != oid_version ()) {
129- error (_ ("hash version %X does not match version %X" ),
130- hash_version , oid_version ());
120+ graph_version , 1 );
131121 goto cleanup_fail ;
132122 }
133123
134124 graph = alloc_commit_graph ();
135125
126+ switch (graph_version ) {
127+ case 1 :
128+ hash_version = * (unsigned char * )(data + 5 );
129+ if (hash_version != oid_version ()) {
130+ error (_ ("hash version %X does not match version %X" ),
131+ hash_version , oid_version ());
132+ goto cleanup_fail ;
133+ }
134+
135+ graph -> num_chunks = * (unsigned char * )(data + 6 );
136+ chunk_lookup = data + 8 ;
137+ break ;
138+ }
139+
136140 graph -> hash_len = the_hash_algo -> rawsz ;
137- graph -> num_chunks = * (unsigned char * )(data + 6 );
138141 graph -> graph_fd = fd ;
139142 graph -> data = graph_map ;
140143 graph -> data_len = graph_size ;
141144
142145 last_chunk_id = 0 ;
143146 last_chunk_offset = 8 ;
144- chunk_lookup = data + 8 ;
145147 for (i = 0 ; i < graph -> num_chunks ; i ++ ) {
146148 uint32_t chunk_id = get_be32 (chunk_lookup + 0 );
147149 uint64_t chunk_offset = get_be64 (chunk_lookup + 4 );
@@ -792,10 +794,22 @@ int write_commit_graph(const char *obj_dir,
792794 int res = 0 ;
793795 int append = flags & COMMIT_GRAPH_APPEND ;
794796 int report_progress = flags & COMMIT_GRAPH_PROGRESS ;
797+ int version = 0 ;
798+ int header_size = 0 ;
795799
796800 if (!commit_graph_compatible (the_repository ))
797801 return 0 ;
798802
803+ if (flags & COMMIT_GRAPH_VERSION_1 )
804+ version = 1 ;
805+ if (!version )
806+ version = 1 ;
807+ if (version != 1 ) {
808+ error (_ ("unsupported commit-graph version %d" ),
809+ version );
810+ return 1 ;
811+ }
812+
799813 oids .nr = 0 ;
800814 approx_nr_objects = approximate_object_count ();
801815 oids .alloc = approx_nr_objects / 32 ;
@@ -980,10 +994,16 @@ int write_commit_graph(const char *obj_dir,
980994
981995 hashwrite_be32 (f , GRAPH_SIGNATURE );
982996
983- hashwrite_u8 (f , GRAPH_VERSION );
984- hashwrite_u8 (f , oid_version ());
985- hashwrite_u8 (f , num_chunks );
986- hashwrite_u8 (f , 0 ); /* unused padding byte */
997+ hashwrite_u8 (f , version );
998+
999+ switch (version ) {
1000+ case 1 :
1001+ hashwrite_u8 (f , oid_version ());
1002+ hashwrite_u8 (f , num_chunks );
1003+ hashwrite_u8 (f , 0 ); /* unused padding byte */
1004+ header_size = 8 ;
1005+ break ;
1006+ }
9871007
9881008 chunk_ids [0 ] = GRAPH_CHUNKID_OIDFANOUT ;
9891009 chunk_ids [1 ] = GRAPH_CHUNKID_OIDLOOKUP ;
@@ -994,7 +1014,7 @@ int write_commit_graph(const char *obj_dir,
9941014 chunk_ids [3 ] = 0 ;
9951015 chunk_ids [4 ] = 0 ;
9961016
997- chunk_offsets [0 ] = 8 + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
1017+ chunk_offsets [0 ] = header_size + (num_chunks + 1 ) * GRAPH_CHUNKLOOKUP_WIDTH ;
9981018 chunk_offsets [1 ] = chunk_offsets [0 ] + GRAPH_FANOUT_SIZE ;
9991019 chunk_offsets [2 ] = chunk_offsets [1 ] + hashsz * commits .nr ;
10001020 chunk_offsets [3 ] = chunk_offsets [2 ] + (hashsz + 16 ) * commits .nr ;
0 commit comments