99
1010static char const * const builtin_commit_graph_usage [] = {
1111 N_ ("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]" ),
12- N_ ("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>" ),
12+ N_ ("git commit-graph write [--object-dir <objdir>] "
13+ "[--split[=<strategy>]] "
14+ "[--input=<reachable|stdin-packs|stdin-commits|append|graphed>] "
15+ "[--[no-]progress] <split options>" ),
1316 NULL
1417};
1518
@@ -19,16 +22,24 @@ static const char * const builtin_commit_graph_verify_usage[] = {
1922};
2023
2124static const char * const builtin_commit_graph_write_usage [] = {
22- N_ ("git commit-graph write [--object-dir <objdir>] [--append|--split] [--reachable|--stdin-packs|--stdin-commits] [--[no-]progress] <split options>" ),
25+ N_ ("git commit-graph write [--object-dir <objdir>] "
26+ "[--split[=<strategy>]] "
27+ "[--input=<reachable|stdin-packs|stdin-commits|append|graphed>] "
28+ "[--[no-]progress] <split options>" ),
2329 NULL
2430};
2531
32+ enum commit_graph_input {
33+ COMMIT_GRAPH_INPUT_REACHABLE = (1 << 1 ),
34+ COMMIT_GRAPH_INPUT_STDIN_PACKS = (1 << 2 ),
35+ COMMIT_GRAPH_INPUT_STDIN_COMMITS = (1 << 3 ),
36+ COMMIT_GRAPH_INPUT_APPEND = (1 << 4 ),
37+ COMMIT_GRAPH_INPUT_GRAPHED = (1 << 5 )
38+ };
39+
2640static struct opts_commit_graph {
2741 const char * obj_dir ;
28- int reachable ;
29- int stdin_packs ;
30- int stdin_commits ;
31- int append ;
42+ enum commit_graph_input input ;
3243 int split ;
3344 int shallow ;
3445 int progress ;
@@ -56,6 +67,30 @@ static struct object_directory *find_odb(struct repository *r,
5667 return odb ;
5768}
5869
70+ static int option_parse_input (const struct option * opt , const char * arg ,
71+ int unset )
72+ {
73+ enum commit_graph_input * to = opt -> value ;
74+ if (unset || !strcmp (arg , "packs" )) {
75+ * to = 0 ;
76+ return 0 ;
77+ }
78+
79+ if (!strcmp (arg , "reachable" ))
80+ * to |= COMMIT_GRAPH_INPUT_REACHABLE ;
81+ else if (!strcmp (arg , "stdin-packs" ))
82+ * to |= COMMIT_GRAPH_INPUT_STDIN_PACKS ;
83+ else if (!strcmp (arg , "stdin-commits" ))
84+ * to |= COMMIT_GRAPH_INPUT_STDIN_COMMITS ;
85+ else if (!strcmp (arg , "append" ))
86+ * to |= COMMIT_GRAPH_INPUT_APPEND ;
87+ else if (!strcmp (arg , "graphed" ))
88+ * to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_GRAPHED );
89+ else
90+ die (_ ("unrecognized --input source, %s" ), arg );
91+ return 0 ;
92+ }
93+
5994static int graph_verify (int argc , const char * * argv )
6095{
6196 struct commit_graph * graph = NULL ;
@@ -114,6 +149,27 @@ static int graph_verify(int argc, const char **argv)
114149extern int read_replace_refs ;
115150static struct split_commit_graph_opts split_opts ;
116151
152+ static int write_option_parse_split (const struct option * opt , const char * arg ,
153+ int unset )
154+ {
155+ enum commit_graph_split_flags * flags = opt -> value ;
156+
157+ opts .split = 1 ;
158+ if (!arg ) {
159+ * flags = COMMIT_GRAPH_SPLIT_MERGE_AUTO ;
160+ return 0 ;
161+ }
162+
163+ if (!strcmp (arg , "merge-all" ))
164+ * flags = COMMIT_GRAPH_SPLIT_MERGE_REQUIRED ;
165+ else if (!strcmp (arg , "no-merge" ))
166+ * flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED ;
167+ else
168+ die (_ ("unrecognized --split argument, %s" ), arg );
169+
170+ return 0 ;
171+ }
172+
117173static int graph_write (int argc , const char * * argv )
118174{
119175 struct string_list * pack_indexes = NULL ;
@@ -127,17 +183,26 @@ static int graph_write(int argc, const char **argv)
127183 OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
128184 N_ ("dir" ),
129185 N_ ("The object directory to store the graph" )),
130- OPT_BOOL (0 , "reachable" , & opts .reachable ,
131- N_ ("start walk at all refs" )),
132- OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
133- N_ ("scan pack-indexes listed by stdin for commits" )),
134- OPT_BOOL (0 , "stdin-commits" , & opts .stdin_commits ,
135- N_ ("start walk at commits listed by stdin" )),
136- OPT_BOOL (0 , "append" , & opts .append ,
137- N_ ("include all commits already in the commit-graph file" )),
186+ OPT_CALLBACK (0 , "input" , & opts .input , NULL ,
187+ N_ ("include commits from this source in the graph" ),
188+ option_parse_input ),
189+ OPT_BIT (0 , "reachable" , & opts .input ,
190+ N_ ("start walk at all refs" ),
191+ COMMIT_GRAPH_INPUT_REACHABLE ),
192+ OPT_BIT (0 , "stdin-packs" , & opts .input ,
193+ N_ ("scan pack-indexes listed by stdin for commits" ),
194+ COMMIT_GRAPH_INPUT_STDIN_PACKS ),
195+ OPT_BIT (0 , "stdin-commits" , & opts .input ,
196+ N_ ("start walk at commits listed by stdin" ),
197+ COMMIT_GRAPH_INPUT_STDIN_COMMITS ),
198+ OPT_BIT (0 , "append" , & opts .input ,
199+ N_ ("include all commits already in the commit-graph file" ),
200+ COMMIT_GRAPH_INPUT_APPEND ),
138201 OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
139- OPT_BOOL (0 , "split" , & opts .split ,
140- N_ ("allow writing an incremental commit-graph file" )),
202+ OPT_CALLBACK_F (0 , "split" , & split_opts .flags , NULL ,
203+ N_ ("allow writing an incremental commit-graph file" ),
204+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
205+ write_option_parse_split ),
141206 OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
142207 N_ ("maximum number of commits in a non-base split commit-graph" )),
143208 OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -158,12 +223,16 @@ static int graph_write(int argc, const char **argv)
158223 builtin_commit_graph_write_options ,
159224 builtin_commit_graph_write_usage , 0 );
160225
161- if (opts .reachable + opts .stdin_packs + opts .stdin_commits > 1 )
162- die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
226+ if ((!!(opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) +
227+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS ) +
228+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS )) > 1 )
229+ die (_ ("use at most one of --input=reachable, --input=stdin-commits, or --input=stdin-packs" ));
163230 if (!opts .obj_dir )
164231 opts .obj_dir = get_object_directory ();
165- if (opts .append )
232+ if (opts .input & COMMIT_GRAPH_INPUT_APPEND )
166233 flags |= COMMIT_GRAPH_WRITE_APPEND ;
234+ if (opts .input & COMMIT_GRAPH_INPUT_GRAPHED )
235+ flags |= COMMIT_GRAPH_WRITE_NO_INPUT ;
167236 if (opts .split )
168237 flags |= COMMIT_GRAPH_WRITE_SPLIT ;
169238 if (opts .progress )
@@ -172,22 +241,22 @@ static int graph_write(int argc, const char **argv)
172241 read_replace_refs = 0 ;
173242 odb = find_odb (the_repository , opts .obj_dir );
174243
175- if (opts .reachable ) {
244+ if (opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) {
176245 if (write_commit_graph_reachable (odb , flags , & split_opts ))
177246 return 1 ;
178247 return 0 ;
179248 }
180249
181250 string_list_init (& lines , 0 );
182- if (opts .stdin_packs || opts . stdin_commits ) {
251+ if (opts .input & ( COMMIT_GRAPH_INPUT_STDIN_PACKS | COMMIT_GRAPH_INPUT_STDIN_COMMITS ) ) {
183252 struct strbuf buf = STRBUF_INIT ;
184253
185254 while (strbuf_getline (& buf , stdin ) != EOF )
186255 string_list_append (& lines , strbuf_detach (& buf , NULL ));
187256
188- if (opts .stdin_packs )
257+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS )
189258 pack_indexes = & lines ;
190- if (opts .stdin_commits ) {
259+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS ) {
191260 commit_hex = & lines ;
192261 flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
193262 }
0 commit comments