9
9
10
10
static char const * const builtin_commit_graph_usage [] = {
11
11
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|none>] "
15
+ "[--[no-]progress] <split options>" ),
13
16
NULL
14
17
};
15
18
@@ -19,16 +22,24 @@ static const char * const builtin_commit_graph_verify_usage[] = {
19
22
};
20
23
21
24
static 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|none>] "
28
+ "[--[no-]progress] <split options>" ),
23
29
NULL
24
30
};
25
31
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_NONE = (1 << 5 )
38
+ };
39
+
26
40
static struct opts_commit_graph {
27
41
const char * obj_dir ;
28
- int reachable ;
29
- int stdin_packs ;
30
- int stdin_commits ;
31
- int append ;
42
+ enum commit_graph_input input ;
32
43
int split ;
33
44
int shallow ;
34
45
int progress ;
@@ -53,6 +64,30 @@ static struct object_directory *find_odb(struct repository *r,
53
64
return odb ;
54
65
}
55
66
67
+ static int option_parse_input (const struct option * opt , const char * arg ,
68
+ int unset )
69
+ {
70
+ enum commit_graph_input * to = opt -> value ;
71
+ if (unset || !strcmp (arg , "packs" )) {
72
+ * to = 0 ;
73
+ return 0 ;
74
+ }
75
+
76
+ if (!strcmp (arg , "reachable" ))
77
+ * to |= COMMIT_GRAPH_INPUT_REACHABLE ;
78
+ else if (!strcmp (arg , "stdin-packs" ))
79
+ * to |= COMMIT_GRAPH_INPUT_STDIN_PACKS ;
80
+ else if (!strcmp (arg , "stdin-commits" ))
81
+ * to |= COMMIT_GRAPH_INPUT_STDIN_COMMITS ;
82
+ else if (!strcmp (arg , "append" ))
83
+ * to |= COMMIT_GRAPH_INPUT_APPEND ;
84
+ else if (!strcmp (arg , "none" ))
85
+ * to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_NONE );
86
+ else
87
+ die (_ ("unrecognized --input source, %s" ), arg );
88
+ return 0 ;
89
+ }
90
+
56
91
static int graph_verify (int argc , const char * * argv )
57
92
{
58
93
struct commit_graph * graph = NULL ;
@@ -111,6 +146,27 @@ static int graph_verify(int argc, const char **argv)
111
146
extern int read_replace_refs ;
112
147
static struct split_commit_graph_opts split_opts ;
113
148
149
+ static int write_option_parse_split (const struct option * opt , const char * arg ,
150
+ int unset )
151
+ {
152
+ enum commit_graph_split_flags * flags = opt -> value ;
153
+
154
+ opts .split = 1 ;
155
+ if (!arg ) {
156
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_AUTO ;
157
+ return 0 ;
158
+ }
159
+
160
+ if (!strcmp (arg , "merge-all" ))
161
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_REQUIRED ;
162
+ else if (!strcmp (arg , "no-merge" ))
163
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED ;
164
+ else
165
+ die (_ ("unrecognized --split argument, %s" ), arg );
166
+
167
+ return 0 ;
168
+ }
169
+
114
170
static int graph_write (int argc , const char * * argv )
115
171
{
116
172
struct string_list * pack_indexes = NULL ;
@@ -124,17 +180,26 @@ static int graph_write(int argc, const char **argv)
124
180
OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
125
181
N_ ("dir" ),
126
182
N_ ("The object directory to store the graph" )),
127
- OPT_BOOL (0 , "reachable" , & opts .reachable ,
128
- N_ ("start walk at all refs" )),
129
- OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
130
- N_ ("scan pack-indexes listed by stdin for commits" )),
131
- OPT_BOOL (0 , "stdin-commits" , & opts .stdin_commits ,
132
- N_ ("start walk at commits listed by stdin" )),
133
- OPT_BOOL (0 , "append" , & opts .append ,
134
- N_ ("include all commits already in the commit-graph file" )),
183
+ OPT_CALLBACK (0 , "input" , & opts .input , NULL ,
184
+ N_ ("include commits from this source in the graph" ),
185
+ option_parse_input ),
186
+ OPT_BIT (0 , "reachable" , & opts .input ,
187
+ N_ ("start walk at all refs" ),
188
+ COMMIT_GRAPH_INPUT_REACHABLE ),
189
+ OPT_BIT (0 , "stdin-packs" , & opts .input ,
190
+ N_ ("scan pack-indexes listed by stdin for commits" ),
191
+ COMMIT_GRAPH_INPUT_STDIN_PACKS ),
192
+ OPT_BIT (0 , "stdin-commits" , & opts .input ,
193
+ N_ ("start walk at commits listed by stdin" ),
194
+ COMMIT_GRAPH_INPUT_STDIN_COMMITS ),
195
+ OPT_BIT (0 , "append" , & opts .input ,
196
+ N_ ("include all commits already in the commit-graph file" ),
197
+ COMMIT_GRAPH_INPUT_APPEND ),
135
198
OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
136
- OPT_BOOL (0 , "split" , & opts .split ,
137
- N_ ("allow writing an incremental commit-graph file" )),
199
+ OPT_CALLBACK_F (0 , "split" , & split_opts .flags , NULL ,
200
+ N_ ("allow writing an incremental commit-graph file" ),
201
+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
202
+ write_option_parse_split ),
138
203
OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
139
204
N_ ("maximum number of commits in a non-base split commit-graph" )),
140
205
OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -155,12 +220,16 @@ static int graph_write(int argc, const char **argv)
155
220
builtin_commit_graph_write_options ,
156
221
builtin_commit_graph_write_usage , 0 );
157
222
158
- if (opts .reachable + opts .stdin_packs + opts .stdin_commits > 1 )
159
- die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
223
+ if ((!!(opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) +
224
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS ) +
225
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS )) > 1 )
226
+ die (_ ("use at most one of --input=reachable, --input=stdin-commits, or --input=stdin-packs" ));
160
227
if (!opts .obj_dir )
161
228
opts .obj_dir = get_object_directory ();
162
- if (opts .append )
229
+ if (opts .input & COMMIT_GRAPH_INPUT_APPEND )
163
230
flags |= COMMIT_GRAPH_WRITE_APPEND ;
231
+ if (opts .input & COMMIT_GRAPH_INPUT_NONE )
232
+ flags |= COMMIT_GRAPH_WRITE_NO_INPUT ;
164
233
if (opts .split )
165
234
flags |= COMMIT_GRAPH_WRITE_SPLIT ;
166
235
if (opts .progress )
@@ -169,22 +238,22 @@ static int graph_write(int argc, const char **argv)
169
238
read_replace_refs = 0 ;
170
239
odb = find_odb (the_repository , opts .obj_dir );
171
240
172
- if (opts .reachable ) {
241
+ if (opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) {
173
242
if (write_commit_graph_reachable (odb , flags , & split_opts ))
174
243
return 1 ;
175
244
return 0 ;
176
245
}
177
246
178
247
string_list_init (& lines , 0 );
179
- if (opts .stdin_packs || opts . stdin_commits ) {
248
+ if (opts .input & ( COMMIT_GRAPH_INPUT_STDIN_PACKS | COMMIT_GRAPH_INPUT_STDIN_COMMITS ) ) {
180
249
struct strbuf buf = STRBUF_INIT ;
181
250
182
251
while (strbuf_getline (& buf , stdin ) != EOF )
183
252
string_list_append (& lines , strbuf_detach (& buf , NULL ));
184
253
185
- if (opts .stdin_packs )
254
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS )
186
255
pack_indexes = & lines ;
187
- if (opts .stdin_commits ) {
256
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS ) {
188
257
commit_hex = & lines ;
189
258
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
190
259
}
0 commit comments