@@ -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
@@ -116,6 +117,11 @@ static int graph_read(int argc, const char **argv)
116117 * (unsigned char * )(graph -> data + 5 ),
117118 * (unsigned char * )(graph -> data + 6 ),
118119 * (unsigned char * )(graph -> data + 7 ));
120+
121+ if (* (unsigned char * )(graph -> data + 4 ) == 2 )
122+ printf ("hash algorithm: %X\n" ,
123+ get_be32 (graph -> data + 8 ));
124+
119125 printf ("num_commits: %u\n" , graph -> num_commits );
120126 printf ("chunks:" );
121127
@@ -141,6 +147,8 @@ static int graph_write(int argc, const char **argv)
141147 struct string_list * pack_indexes = NULL ;
142148 struct string_list * commit_hex = NULL ;
143149 struct string_list lines ;
150+ int result ;
151+ int flags = COMMIT_GRAPH_PROGRESS ;
144152
145153 static struct option builtin_commit_graph_write_options [] = {
146154 OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
@@ -154,6 +162,8 @@ static int graph_write(int argc, const char **argv)
154162 N_ ("start walk at commits listed by stdin" )),
155163 OPT_BOOL (0 , "append" , & opts .append ,
156164 N_ ("include all commits already in the commit-graph file" )),
165+ OPT_INTEGER (0 , "version" , & opts .version ,
166+ N_ ("specify the file format version" )),
157167 OPT_END (),
158168 };
159169
@@ -165,14 +175,24 @@ static int graph_write(int argc, const char **argv)
165175 die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
166176 if (!opts .obj_dir )
167177 opts .obj_dir = get_object_directory ();
178+ if (opts .append )
179+ flags |= COMMIT_GRAPH_APPEND ;
168180
169- read_replace_refs = 0 ;
181+ switch (opts .version ) {
182+ case 1 :
183+ flags |= COMMIT_GRAPH_VERSION_1 ;
184+ break ;
170185
171- if ( opts . reachable ) {
172- write_commit_graph_reachable ( opts . obj_dir , opts . append , 1 ) ;
173- return 0 ;
186+ case 2 :
187+ flags |= COMMIT_GRAPH_VERSION_2 ;
188+ break ;
174189 }
175190
191+ read_replace_refs = 0 ;
192+
193+ if (opts .reachable )
194+ return write_commit_graph_reachable (opts .obj_dir , flags );
195+
176196 string_list_init (& lines , 0 );
177197 if (opts .stdin_packs || opts .stdin_commits ) {
178198 struct strbuf buf = STRBUF_INIT ;
@@ -188,14 +208,13 @@ static int graph_write(int argc, const char **argv)
188208 UNLEAK (buf );
189209 }
190210
191- write_commit_graph (opts .obj_dir ,
192- pack_indexes ,
193- commit_hex ,
194- opts .append ,
195- 1 );
211+ result = write_commit_graph (opts .obj_dir ,
212+ pack_indexes ,
213+ commit_hex ,
214+ flags );
196215
197216 UNLEAK (lines );
198- return 0 ;
217+ return result ;
199218}
200219
201220int cmd_commit_graph (int argc , const char * * argv , const char * prefix )
0 commit comments