@@ -10,7 +10,7 @@ static char const * const builtin_commit_graph_usage[] = {
1010 N_ ("git commit-graph [--object-dir <objdir>]" ),
1111 N_ ("git commit-graph read [--object-dir <objdir>]" ),
1212 N_ ("git commit-graph verify [--object-dir <objdir>]" ),
13- N_ ("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]" ),
13+ N_ ("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits] [--version=<n>] " ),
1414 NULL
1515};
1616
@@ -25,7 +25,7 @@ static const char * const builtin_commit_graph_read_usage[] = {
2525};
2626
2727static const char * const builtin_commit_graph_write_usage [] = {
28- N_ ("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits]" ),
28+ N_ ("git commit-graph write [--object-dir <objdir>] [--append] [--reachable|--stdin-packs|--stdin-commits] [--version=<n>] " ),
2929 NULL
3030};
3131
@@ -35,6 +35,7 @@ static struct opts_commit_graph {
3535 int stdin_packs ;
3636 int stdin_commits ;
3737 int append ;
38+ int version ;
3839} opts ;
3940
4041
@@ -101,6 +102,11 @@ static int graph_read(int argc, const char **argv)
101102 * (unsigned char * )(graph -> data + 5 ),
102103 * (unsigned char * )(graph -> data + 6 ),
103104 * (unsigned char * )(graph -> data + 7 ));
105+
106+ if (* (unsigned char * )(graph -> data + 4 ) == 2 )
107+ printf ("hash algorithm: %X\n" ,
108+ get_be32 (graph -> data + 8 ));
109+
104110 printf ("num_commits: %u\n" , graph -> num_commits );
105111 printf ("chunks:" );
106112
@@ -126,6 +132,8 @@ static int graph_write(int argc, const char **argv)
126132 struct string_list * pack_indexes = NULL ;
127133 struct string_list * commit_hex = NULL ;
128134 struct string_list lines ;
135+ int result ;
136+ int flags = COMMIT_GRAPH_PROGRESS ;
129137
130138 static struct option builtin_commit_graph_write_options [] = {
131139 OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
@@ -139,6 +147,8 @@ static int graph_write(int argc, const char **argv)
139147 N_ ("start walk at commits listed by stdin" )),
140148 OPT_BOOL (0 , "append" , & opts .append ,
141149 N_ ("include all commits already in the commit-graph file" )),
150+ OPT_INTEGER (0 , "version" , & opts .version ,
151+ N_ ("specify the file format version" )),
142152 OPT_END (),
143153 };
144154
@@ -150,14 +160,24 @@ static int graph_write(int argc, const char **argv)
150160 die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
151161 if (!opts .obj_dir )
152162 opts .obj_dir = get_object_directory ();
163+ if (opts .append )
164+ flags |= COMMIT_GRAPH_APPEND ;
153165
154- read_replace_refs = 0 ;
166+ switch (opts .version ) {
167+ case 1 :
168+ flags |= COMMIT_GRAPH_VERSION_1 ;
169+ break ;
155170
156- if ( opts . reachable ) {
157- write_commit_graph_reachable ( opts . obj_dir , opts . append , 1 ) ;
158- return 0 ;
171+ case 2 :
172+ flags |= COMMIT_GRAPH_VERSION_2 ;
173+ break ;
159174 }
160175
176+ read_replace_refs = 0 ;
177+
178+ if (opts .reachable )
179+ return write_commit_graph_reachable (opts .obj_dir , flags );
180+
161181 string_list_init (& lines , 0 );
162182 if (opts .stdin_packs || opts .stdin_commits ) {
163183 struct strbuf buf = STRBUF_INIT ;
@@ -173,14 +193,13 @@ static int graph_write(int argc, const char **argv)
173193 UNLEAK (buf );
174194 }
175195
176- write_commit_graph (opts .obj_dir ,
177- pack_indexes ,
178- commit_hex ,
179- opts .append ,
180- 1 );
196+ result = write_commit_graph (opts .obj_dir ,
197+ pack_indexes ,
198+ commit_hex ,
199+ flags );
181200
182201 UNLEAK (lines );
183- return 0 ;
202+ return result ;
184203}
185204
186205int cmd_commit_graph (int argc , const char * * argv , const char * prefix )
0 commit comments