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] [--changed-paths] [--[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
+ "[--changed-paths] "
16
+ "[--[no-]progress] <split options>" ),
13
17
NULL
14
18
};
15
19
@@ -19,16 +23,25 @@ static const char * const builtin_commit_graph_verify_usage[] = {
19
23
};
20
24
21
25
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] [--changed-paths] [--[no-]progress] <split options>" ),
26
+ N_ ("git commit-graph write [--object-dir <objdir>] "
27
+ "[--split[=<strategy>]] "
28
+ "[--input=<reachable|stdin-packs|stdin-commits|append|none>] "
29
+ "[--changed-paths] "
30
+ "[--[no-]progress] <split options>" ),
23
31
NULL
24
32
};
25
33
34
+ enum commit_graph_input {
35
+ COMMIT_GRAPH_INPUT_REACHABLE = (1 << 1 ),
36
+ COMMIT_GRAPH_INPUT_STDIN_PACKS = (1 << 2 ),
37
+ COMMIT_GRAPH_INPUT_STDIN_COMMITS = (1 << 3 ),
38
+ COMMIT_GRAPH_INPUT_APPEND = (1 << 4 ),
39
+ COMMIT_GRAPH_INPUT_NONE = (1 << 5 )
40
+ };
41
+
26
42
static struct opts_commit_graph {
27
43
const char * obj_dir ;
28
- int reachable ;
29
- int stdin_packs ;
30
- int stdin_commits ;
31
- int append ;
44
+ enum commit_graph_input input ;
32
45
int split ;
33
46
int shallow ;
34
47
int progress ;
@@ -54,6 +67,30 @@ static struct object_directory *find_odb(struct repository *r,
54
67
return odb ;
55
68
}
56
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 , "none" ))
88
+ * to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_NONE );
89
+ else
90
+ die (_ ("unrecognized --input source, %s" ), arg );
91
+ return 0 ;
92
+ }
93
+
57
94
static int graph_verify (int argc , const char * * argv )
58
95
{
59
96
struct commit_graph * graph = NULL ;
@@ -112,6 +149,27 @@ static int graph_verify(int argc, const char **argv)
112
149
extern int read_replace_refs ;
113
150
static struct split_commit_graph_opts split_opts ;
114
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
+
115
173
static int graph_write (int argc , const char * * argv )
116
174
{
117
175
struct string_list * pack_indexes = NULL ;
@@ -125,19 +183,28 @@ static int graph_write(int argc, const char **argv)
125
183
OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
126
184
N_ ("dir" ),
127
185
N_ ("The object directory to store the graph" )),
128
- OPT_BOOL (0 , "reachable" , & opts .reachable ,
129
- N_ ("start walk at all refs" )),
130
- OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
131
- N_ ("scan pack-indexes listed by stdin for commits" )),
132
- OPT_BOOL (0 , "stdin-commits" , & opts .stdin_commits ,
133
- N_ ("start walk at commits listed by stdin" )),
134
- OPT_BOOL (0 , "append" , & opts .append ,
135
- 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 ),
136
201
OPT_BOOL (0 , "changed-paths" , & opts .enable_changed_paths ,
137
202
N_ ("enable computation for changed paths" )),
138
203
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" )),
204
+ OPT_CALLBACK_F (0 , "split" , & split_opts .flags , NULL ,
205
+ N_ ("allow writing an incremental commit-graph file" ),
206
+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
207
+ write_option_parse_split ),
141
208
OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
142
209
N_ ("maximum number of commits in a non-base split commit-graph" )),
143
210
OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -158,12 +225,16 @@ static int graph_write(int argc, const char **argv)
158
225
builtin_commit_graph_write_options ,
159
226
builtin_commit_graph_write_usage , 0 );
160
227
161
- if (opts .reachable + opts .stdin_packs + opts .stdin_commits > 1 )
162
- die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
228
+ if ((!!(opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) +
229
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS ) +
230
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS )) > 1 )
231
+ die (_ ("use at most one of --input=reachable, --input=stdin-commits, or --input=stdin-packs" ));
163
232
if (!opts .obj_dir )
164
233
opts .obj_dir = get_object_directory ();
165
- if (opts .append )
234
+ if (opts .input & COMMIT_GRAPH_INPUT_APPEND )
166
235
flags |= COMMIT_GRAPH_WRITE_APPEND ;
236
+ if (opts .input & COMMIT_GRAPH_INPUT_NONE )
237
+ flags |= COMMIT_GRAPH_WRITE_NO_INPUT ;
167
238
if (opts .split )
168
239
flags |= COMMIT_GRAPH_WRITE_SPLIT ;
169
240
if (opts .progress )
@@ -175,22 +246,22 @@ static int graph_write(int argc, const char **argv)
175
246
read_replace_refs = 0 ;
176
247
odb = find_odb (the_repository , opts .obj_dir );
177
248
178
- if (opts .reachable ) {
249
+ if (opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) {
179
250
if (write_commit_graph_reachable (odb , flags , & split_opts ))
180
251
return 1 ;
181
252
return 0 ;
182
253
}
183
254
184
255
string_list_init (& lines , 0 );
185
- if (opts .stdin_packs || opts . stdin_commits ) {
256
+ if (opts .input & ( COMMIT_GRAPH_INPUT_STDIN_PACKS | COMMIT_GRAPH_INPUT_STDIN_COMMITS ) ) {
186
257
struct strbuf buf = STRBUF_INIT ;
187
258
188
259
while (strbuf_getline (& buf , stdin ) != EOF )
189
260
string_list_append (& lines , strbuf_detach (& buf , NULL ));
190
261
191
- if (opts .stdin_packs )
262
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS )
192
263
pack_indexes = & lines ;
193
- if (opts .stdin_commits ) {
264
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS ) {
194
265
commit_hex = & lines ;
195
266
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
196
267
}
0 commit comments