9
9
#include "progress.h"
10
10
#include "tag.h"
11
11
12
- static char const * const builtin_commit_graph_usage [] = {
13
- N_ ("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]" ),
14
- N_ ("git commit-graph write [--object-dir <objdir>] [--append] "
15
- "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
16
- "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] "
17
- "<split options>" ),
12
+ #define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \
13
+ N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]")
14
+
15
+ #define BUILTIN_COMMIT_GRAPH_WRITE_USAGE \
16
+ N_("git commit-graph write [--object-dir <objdir>] [--append] " \
17
+ "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] " \
18
+ "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] " \
19
+ "<split options>")
20
+
21
+ static const char * builtin_commit_graph_verify_usage [] = {
22
+ BUILTIN_COMMIT_GRAPH_VERIFY_USAGE ,
18
23
NULL
19
24
};
20
25
21
- static const char * const builtin_commit_graph_verify_usage [] = {
22
- N_ ( "git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]" ) ,
26
+ static const char * builtin_commit_graph_write_usage [] = {
27
+ BUILTIN_COMMIT_GRAPH_WRITE_USAGE ,
23
28
NULL
24
29
};
25
30
26
- static const char * const builtin_commit_graph_write_usage [] = {
27
- N_ ("git commit-graph write [--object-dir <objdir>] [--append] "
28
- "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
29
- "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] "
30
- "<split options>" ),
31
- NULL
31
+ static char const * const builtin_commit_graph_usage [] = {
32
+ BUILTIN_COMMIT_GRAPH_VERIFY_USAGE ,
33
+ BUILTIN_COMMIT_GRAPH_WRITE_USAGE ,
34
+ NULL ,
32
35
};
33
36
34
37
static struct opts_commit_graph {
@@ -43,6 +46,20 @@ static struct opts_commit_graph {
43
46
int enable_changed_paths ;
44
47
} opts ;
45
48
49
+ static struct option common_opts [] = {
50
+ OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
51
+ N_ ("dir" ),
52
+ N_ ("the object directory to store the graph" )),
53
+ OPT_BOOL (0 , "progress" , & opts .progress ,
54
+ N_ ("force progress reporting" )),
55
+ OPT_END ()
56
+ };
57
+
58
+ static struct option * add_common_options (struct option * to )
59
+ {
60
+ return parse_options_concat (common_opts , to );
61
+ }
62
+
46
63
static struct object_directory * find_odb (struct repository * r ,
47
64
const char * obj_dir )
48
65
{
@@ -76,21 +93,20 @@ static int graph_verify(int argc, const char **argv)
76
93
int flags = 0 ;
77
94
78
95
static struct option builtin_commit_graph_verify_options [] = {
79
- OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
80
- N_ ("dir" ),
81
- N_ ("the object directory to store the graph" )),
82
96
OPT_BOOL (0 , "shallow" , & opts .shallow ,
83
97
N_ ("if the commit-graph is split, only verify the tip file" )),
84
- OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
85
98
OPT_END (),
86
99
};
100
+ struct option * options = add_common_options (builtin_commit_graph_verify_options );
87
101
88
102
trace2_cmd_mode ("verify" );
89
103
90
104
opts .progress = isatty (2 );
91
105
argc = parse_options (argc , argv , NULL ,
92
- builtin_commit_graph_verify_options ,
106
+ options ,
93
107
builtin_commit_graph_verify_usage , 0 );
108
+ if (argc )
109
+ usage_with_options (builtin_commit_graph_verify_usage , options );
94
110
95
111
if (!opts .obj_dir )
96
112
opts .obj_dir = get_object_directory ();
@@ -106,6 +122,7 @@ static int graph_verify(int argc, const char **argv)
106
122
die_errno (_ ("Could not open commit-graph '%s'" ), graph_name );
107
123
108
124
FREE_AND_NULL (graph_name );
125
+ FREE_AND_NULL (options );
109
126
110
127
if (open_ok )
111
128
graph = load_commit_graph_one_fd_st (the_repository , fd , & st , odb );
@@ -206,9 +223,6 @@ static int graph_write(int argc, const char **argv)
206
223
struct progress * progress = NULL ;
207
224
208
225
static struct option builtin_commit_graph_write_options [] = {
209
- OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
210
- N_ ("dir" ),
211
- N_ ("the object directory to store the graph" )),
212
226
OPT_BOOL (0 , "reachable" , & opts .reachable ,
213
227
N_ ("start walk at all refs" )),
214
228
OPT_BOOL (0 , "stdin-packs" , & opts .stdin_packs ,
@@ -219,7 +233,6 @@ static int graph_write(int argc, const char **argv)
219
233
N_ ("include all commits already in the commit-graph file" )),
220
234
OPT_BOOL (0 , "changed-paths" , & opts .enable_changed_paths ,
221
235
N_ ("enable computation for changed paths" )),
222
- OPT_BOOL (0 , "progress" , & opts .progress , N_ ("force progress reporting" )),
223
236
OPT_CALLBACK_F (0 , "split" , & write_opts .split_flags , NULL ,
224
237
N_ ("allow writing an incremental commit-graph file" ),
225
238
PARSE_OPT_OPTARG | PARSE_OPT_NONEG ,
@@ -235,6 +248,7 @@ static int graph_write(int argc, const char **argv)
235
248
0 , write_option_max_new_filters ),
236
249
OPT_END (),
237
250
};
251
+ struct option * options = add_common_options (builtin_commit_graph_write_options );
238
252
239
253
opts .progress = isatty (2 );
240
254
opts .enable_changed_paths = -1 ;
@@ -248,8 +262,10 @@ static int graph_write(int argc, const char **argv)
248
262
git_config (git_commit_graph_write_config , & opts );
249
263
250
264
argc = parse_options (argc , argv , NULL ,
251
- builtin_commit_graph_write_options ,
265
+ options ,
252
266
builtin_commit_graph_write_usage , 0 );
267
+ if (argc )
268
+ usage_with_options (builtin_commit_graph_write_usage , options );
253
269
254
270
if (opts .reachable + opts .stdin_packs + opts .stdin_commits > 1 )
255
271
die (_ ("use at most one of --reachable, --stdin-commits, or --stdin-packs" ));
@@ -304,39 +320,33 @@ static int graph_write(int argc, const char **argv)
304
320
result = 1 ;
305
321
306
322
cleanup :
323
+ FREE_AND_NULL (options );
307
324
string_list_clear (& pack_indexes , 0 );
308
325
strbuf_release (& buf );
309
326
return result ;
310
327
}
311
328
312
329
int cmd_commit_graph (int argc , const char * * argv , const char * prefix )
313
330
{
314
- static struct option builtin_commit_graph_options [] = {
315
- OPT_STRING (0 , "object-dir" , & opts .obj_dir ,
316
- N_ ("dir" ),
317
- N_ ("the object directory to store the graph" )),
318
- OPT_END (),
319
- };
320
-
321
- if (argc == 2 && !strcmp (argv [1 ], "-h" ))
322
- usage_with_options (builtin_commit_graph_usage ,
323
- builtin_commit_graph_options );
331
+ struct option * builtin_commit_graph_options = common_opts ;
324
332
325
333
git_config (git_default_config , NULL );
326
334
argc = parse_options (argc , argv , prefix ,
327
335
builtin_commit_graph_options ,
328
336
builtin_commit_graph_usage ,
329
337
PARSE_OPT_STOP_AT_NON_OPTION );
338
+ if (!argc )
339
+ goto usage ;
330
340
331
341
save_commit_buffer = 0 ;
332
342
333
- if (argc > 0 ) {
334
- if (!strcmp (argv [0 ], "verify" ))
335
- return graph_verify (argc , argv );
336
- if (!strcmp (argv [0 ], "write" ))
337
- return graph_write (argc , argv );
338
- }
343
+ if (!strcmp (argv [0 ], "verify" ))
344
+ return graph_verify (argc , argv );
345
+ else if (argc && !strcmp (argv [0 ], "write" ))
346
+ return graph_write (argc , argv );
339
347
348
+ error (_ ("unrecognized subcommand: %s" ), argv [0 ]);
349
+ usage :
340
350
usage_with_options (builtin_commit_graph_usage ,
341
351
builtin_commit_graph_options );
342
352
}
0 commit comments