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>] [--append] "
13
+ "[--split[=<strategy>]] "
14
+ "[--input=<reachable|stdin-packs|stdin-commits|none>] "
15
+ "[--[no-]progress] <split options>" ),
13
16
NULL
14
17
};
15
18
@@ -19,21 +22,53 @@ 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>] [--append] "
26
+ "[--split[=<strategy>]] "
27
+ "[--input=<reachable|stdin-packs|stdin-commits|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 ;
35
46
} opts ;
36
47
48
+ static int option_parse_input (const struct option * opt , const char * arg ,
49
+ int unset )
50
+ {
51
+ enum commit_graph_input * to = opt -> value ;
52
+ if (unset || !strcmp (arg , "packs" )) {
53
+ * to = 0 ;
54
+ return 0 ;
55
+ }
56
+
57
+ if (!strcmp (arg , "reachable" ))
58
+ * to |= COMMIT_GRAPH_INPUT_REACHABLE ;
59
+ else if (!strcmp (arg , "stdin-packs" ))
60
+ * to |= COMMIT_GRAPH_INPUT_STDIN_PACKS ;
61
+ else if (!strcmp (arg , "stdin-commits" ))
62
+ * to |= COMMIT_GRAPH_INPUT_STDIN_COMMITS ;
63
+ else if (!strcmp (arg , "append" ))
64
+ * to |= COMMIT_GRAPH_INPUT_APPEND ;
65
+ else if (!strcmp (arg , "none" ))
66
+ * to |= (COMMIT_GRAPH_INPUT_APPEND | COMMIT_GRAPH_INPUT_NONE );
67
+ else
68
+ die (_ ("unrecognized --input source, %s" ), arg );
69
+ return 0 ;
70
+ }
71
+
37
72
static struct object_directory * find_odb_or_die (struct repository * r ,
38
73
const char * obj_dir )
39
74
{
@@ -101,6 +136,25 @@ static int graph_verify(int argc, const char **argv)
101
136
extern int read_replace_refs ;
102
137
static struct split_commit_graph_opts split_opts ;
103
138
139
+ static int write_option_parse_split (const struct option * opt , const char * arg ,
140
+ int unset )
141
+ {
142
+ enum commit_graph_split_flags * flags = opt -> value ;
143
+
144
+ opts .split = 1 ;
145
+ if (!arg )
146
+ return 0 ;
147
+
148
+ if (!strcmp (arg , "merge-all" ))
149
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_REQUIRED ;
150
+ else if (!strcmp (arg , "no-merge" ))
151
+ * flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED ;
152
+ else
153
+ die (_ ("unrecognized --split argument, %s" ), arg );
154
+
155
+ return 0 ;
156
+ }
157
+
104
158
static int graph_write (int argc , const char * * argv )
105
159
{
106
160
struct string_list * pack_indexes = NULL ;
@@ -114,17 +168,26 @@ static int graph_write(int argc, const char **argv)
114
168
OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
115
169
N_ ("dir" ),
116
170
N_ ("The object directory to store the graph" )),
117
- OPT_BOOL (0 , "reachable" , & opts .reachable ,
118
- N_ ("start walk at all refs" )),
119
- OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
120
- N_ ("scan pack-indexes listed by stdin for commits" )),
121
- OPT_BOOL (0 , "stdin-commits" , & opts .stdin_commits ,
122
- N_ ("start walk at commits listed by stdin" )),
123
- OPT_BOOL (0 , "append" , & opts .append ,
124
- N_ ("include all commits already in the commit-graph file" )),
171
+ OPT_CALLBACK (0 , "input" , & opts .input , NULL ,
172
+ N_ ("include commits from this source in the graph" ),
173
+ option_parse_input ),
174
+ OPT_BIT (0 , "reachable" , & opts .input ,
175
+ N_ ("start walk at all refs" ),
176
+ COMMIT_GRAPH_INPUT_REACHABLE ),
177
+ OPT_BIT (0 , "stdin-packs" , & opts .input ,
178
+ N_ ("scan pack-indexes listed by stdin for commits" ),
179
+ COMMIT_GRAPH_INPUT_STDIN_PACKS ),
180
+ OPT_BIT (0 , "stdin-commits" , & opts .input ,
181
+ N_ ("start walk at commits listed by stdin" ),
182
+ COMMIT_GRAPH_INPUT_STDIN_COMMITS ),
183
+ OPT_BIT (0 , "append" , & opts .input ,
184
+ N_ ("include all commits already in the commit-graph file" ),
185
+ COMMIT_GRAPH_INPUT_APPEND ),
125
186
OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
126
- OPT_BOOL (0 , "split" , & opts .split ,
127
- N_ ("allow writing an incremental commit-graph file" )),
187
+ OPT_CALLBACK_F (0 , "split" , & split_opts .flags , NULL ,
188
+ N_ ("allow writing an incremental commit-graph file" ),
189
+ PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
190
+ write_option_parse_split ),
128
191
OPT_INTEGER (0 , "max-commits" , & split_opts .max_commits ,
129
192
N_ ("maximum number of commits in a non-base split commit-graph" )),
130
193
OPT_INTEGER (0 , "size-multiple" , & split_opts .size_multiple ,
@@ -145,12 +208,16 @@ static int graph_write(int argc, const char **argv)
145
208
builtin_commit_graph_write_options ,
146
209
builtin_commit_graph_write_usage , 0 );
147
210
148
- if (opts .reachable + opts .stdin_packs + opts .stdin_commits > 1 )
149
- die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
211
+ if ((!!(opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) +
212
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS ) +
213
+ !!(opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS )) > 1 )
214
+ die (_ ("use at most one of --input=reachable, --input=stdin-commits, or --input=stdin-packs" ));
150
215
if (!opts .obj_dir )
151
216
opts .obj_dir = get_object_directory ();
152
- if (opts .append )
217
+ if (opts .input & COMMIT_GRAPH_INPUT_APPEND )
153
218
flags |= COMMIT_GRAPH_WRITE_APPEND ;
219
+ if (opts .input & COMMIT_GRAPH_INPUT_NONE )
220
+ flags |= COMMIT_GRAPH_WRITE_NO_INPUT ;
154
221
if (opts .split )
155
222
flags |= COMMIT_GRAPH_WRITE_SPLIT ;
156
223
if (opts .progress )
@@ -159,22 +226,22 @@ static int graph_write(int argc, const char **argv)
159
226
read_replace_refs = 0 ;
160
227
odb = find_odb_or_die (the_repository , opts .obj_dir );
161
228
162
- if (opts .reachable ) {
229
+ if (opts .input & COMMIT_GRAPH_INPUT_REACHABLE ) {
163
230
if (write_commit_graph_reachable (odb , flags , & split_opts ))
164
231
return 1 ;
165
232
return 0 ;
166
233
}
167
234
168
235
string_list_init (& lines , 0 );
169
- if (opts .stdin_packs || opts . stdin_commits ) {
236
+ if (opts .input & ( COMMIT_GRAPH_INPUT_STDIN_PACKS | COMMIT_GRAPH_INPUT_STDIN_COMMITS ) ) {
170
237
struct strbuf buf = STRBUF_INIT ;
171
238
172
239
while (strbuf_getline (& buf , stdin ) != EOF )
173
240
string_list_append (& lines , strbuf_detach (& buf , NULL ));
174
241
175
- if (opts .stdin_packs )
242
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_PACKS )
176
243
pack_indexes = & lines ;
177
- if (opts .stdin_commits ) {
244
+ if (opts .input & COMMIT_GRAPH_INPUT_STDIN_COMMITS ) {
178
245
commit_hex = & lines ;
179
246
flags |= COMMIT_GRAPH_WRITE_CHECK_OIDS ;
180
247
}
0 commit comments