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|graphed>] "
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|graphed>] "
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_GRAPHED = (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 ;
@@ -56,6 +67,30 @@ static struct object_directory *find_odb(struct repository *r,
56
67
return odb ;
57
68
}
58
69
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
+
59
94
static int graph_verify (int argc , const char * * argv )
60
95
{
61
96
struct commit_graph * graph = NULL ;
@@ -114,6 +149,27 @@ static int graph_verify(int argc, const char **argv)
114
149
extern int read_replace_refs ;
115
150
static struct split_commit_graph_opts split_opts ;
116
151
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
+
117
173
static int graph_write (int argc , const char * * argv )
118
174
{
119
175
struct string_list * pack_indexes = NULL ;
@@ -127,17 +183,26 @@ static int graph_write(int argc, const char **argv)
127
183
OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
128
184
N_ ("dir" ),
129
185
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 ),
138
201
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 ),
141
206
OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
142
207
N_ ("maximum number of commits in a non-base split commit-graph" )),
143
208
OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -158,12 +223,16 @@ static int graph_write(int argc, const char **argv)
158
223
builtin_commit_graph_write_options ,
159
224
builtin_commit_graph_write_usage , 0 );
160
225
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" ));
163
230
if (!opts .obj_dir )
164
231
opts .obj_dir = get_object_directory ();
165
- if (opts .append )
232
+ if (opts .input & COMMIT_GRAPH_INPUT_APPEND )
166
233
flags |= COMMIT_GRAPH_WRITE_APPEND ;
234
+ if (opts .input & COMMIT_GRAPH_INPUT_GRAPHED )
235
+ flags |= COMMIT_GRAPH_WRITE_NO_INPUT ;
167
236
if (opts .split )
168
237
flags |= COMMIT_GRAPH_WRITE_SPLIT ;
169
238
if (opts .progress )
@@ -172,22 +241,22 @@ static int graph_write(int argc, const char **argv)
172
241
read_replace_refs = 0 ;
173
242
odb = find_odb (the_repository , opts .obj_dir );
174
243
175
- if (opts .reachable ) {
244
+ if (opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) {
176
245
if (write_commit_graph_reachable (odb , flags , & split_opts ))
177
246
return 1 ;
178
247
return 0 ;
179
248
}
180
249
181
250
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 ) ) {
183
252
struct strbuf buf = STRBUF_INIT ;
184
253
185
254
while (strbuf_getline (& buf , stdin ) != EOF )
186
255
string_list_append (& lines , strbuf_detach (& buf , NULL ));
187
256
188
- if (opts .stdin_packs )
257
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS )
189
258
pack_indexes = & lines ;
190
- if (opts .stdin_commits ) {
259
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS ) {
191
260
commit_hex = & lines ;
192
261
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
193
262
}
0 commit comments