Coverage Report

Created: 2026-10-17 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/parse-options.h
Line
Count
Source
1
#ifndef PARSE_OPTIONS_H
2
#define PARSE_OPTIONS_H
3
4
#include "gettext.h"
5
6
struct repository;
7
8
/**
9
 * Refer to Documentation/technical/api-parse-options.adoc for the API doc.
10
 */
11
12
enum parse_opt_type {
13
  /* special types */
14
  OPTION_END,
15
  OPTION_GROUP,
16
  OPTION_NUMBER,
17
  OPTION_ALIAS,
18
  OPTION_SUBCOMMAND,
19
  /* options with no arguments */
20
  OPTION_BIT,
21
  OPTION_NEGBIT,
22
  OPTION_BITOP,
23
  OPTION_COUNTUP,
24
  OPTION_SET_INT,
25
  /* options with arguments (usually) */
26
  OPTION_STRING,
27
  OPTION_INTEGER,
28
  OPTION_UNSIGNED,
29
  OPTION_CALLBACK,
30
  OPTION_LOWLEVEL_CALLBACK,
31
  OPTION_FILENAME
32
};
33
34
enum parse_opt_flags {
35
  PARSE_OPT_KEEP_DASHDASH = 1 << 0,
36
  PARSE_OPT_STOP_AT_NON_OPTION = 1 << 1,
37
  PARSE_OPT_KEEP_ARGV0 = 1 << 2,
38
  PARSE_OPT_KEEP_UNKNOWN_OPT = 1 << 3,
39
  PARSE_OPT_NO_INTERNAL_HELP = 1 << 4,
40
  PARSE_OPT_ONE_SHOT = 1 << 5,
41
  PARSE_OPT_SHELL_EVAL = 1 << 6,
42
  PARSE_OPT_SUBCOMMAND_OPTIONAL = 1 << 7,
43
};
44
45
enum parse_opt_option_flags {
46
  PARSE_OPT_OPTARG  = 1 << 0,
47
  PARSE_OPT_NOARG   = 1 << 1,
48
  PARSE_OPT_NONEG   = 1 << 2,
49
  PARSE_OPT_HIDDEN  = 1 << 3,
50
  PARSE_OPT_LASTARG_DEFAULT = 1 << 4,
51
  PARSE_OPT_NODASH = 1 << 5,
52
  PARSE_OPT_LITERAL_ARGHELP = 1 << 6,
53
  PARSE_OPT_FROM_ALIAS = 1 << 7,
54
  PARSE_OPT_NOCOMPLETE = 1 << 9,
55
  PARSE_OPT_COMP_ARG = 1 << 10,
56
  PARSE_OPT_CMDMODE = 1 << 11,
57
};
58
59
enum parse_opt_result {
60
  PARSE_OPT_COMPLETE = -4,
61
  PARSE_OPT_HELP_ERROR = -3,
62
  PARSE_OPT_HELP = -2,
63
  PARSE_OPT_ERROR = -1, /* must be the same as error() */
64
  PARSE_OPT_DONE = 0, /* fixed so that "return 0" works */
65
  PARSE_OPT_NON_OPTION,
66
  PARSE_OPT_SUBCOMMAND,
67
  PARSE_OPT_UNKNOWN
68
};
69
70
struct option;
71
typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
72
73
struct parse_opt_ctx_t;
74
typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
75
                const struct option *opt,
76
                const char *arg, int unset);
77
78
typedef int parse_opt_subcommand_fn(int argc, const char **argv,
79
            const char *prefix, struct repository *repo);
80
81
/*
82
 * `type`::
83
 *   holds the type of the option, you must have an OPTION_END last in your
84
 *   array.
85
 *
86
 * `short_name`::
87
 *   the character to use as a short option name, '\0' if none.
88
 *
89
 * `long_name`::
90
 *   the long option (without the leading dashes) or subcommand name,
91
 *   NULL if none.
92
 *
93
 * `value`::
94
 *   stores pointers to the values to be filled.
95
 *
96
 * `precision`::
97
 *   precision of the integer pointed to by `value` in number of bytes. Should
98
 *   typically be its `sizeof()`.
99
 *
100
 * `argh`::
101
 *   token to explain the kind of argument this option wants. Does not
102
 *   begin in capital letter, and does not end with a full stop.
103
 *   Should be wrapped by N_() for translation.
104
 *   Is automatically enclosed in brackets when printed, unless it
105
 *   contains any of the following characters: ()<>[]|
106
 *   E.g. "name" is shown as "<name>" to indicate that a name value
107
 *   needs to be supplied, not the literal string "name", but
108
 *   "<start>,<end>" and "(this|that)" are printed verbatim.
109
 *
110
 * `help`::
111
 *   the short help associated to what the option does.
112
 *   Must never be NULL (except for OPTION_END and OPTION_SUBCOMMAND).
113
 *   OPTION_GROUP uses this pointer to store the group header.
114
 *   Should be wrapped by N_() for translation.
115
 *
116
 * `flags`::
117
 *   mask of parse_opt_option_flags.
118
 *   PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)
119
 *   PARSE_OPT_NOARG: says that this option does not take an argument
120
 *   PARSE_OPT_NONEG: says that this option cannot be negated
121
 *                   (i.e. rejects "--no-<option>")
122
 *   PARSE_OPT_HIDDEN: this option is skipped in the default usage, and
123
 *                     shown only in the full usage.
124
 *   PARSE_OPT_LASTARG_DEFAULT: says that this option will take the default
125
 *        value if no argument is given when the option
126
 *        is last on the command line. If the option is
127
 *        not last it will require an argument.
128
 *        Should not be used with PARSE_OPT_OPTARG.
129
 *   PARSE_OPT_NODASH: this option doesn't start with a dash; can only be a
130
 *           short option and can't accept arguments.
131
 *   PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets
132
 *        (i.e. '<argh>') in the help message.
133
 *        Useful for options with multiple parameters.
134
 *   PARSE_OPT_NOCOMPLETE: by default all visible options are completable
135
 *         by git-completion.bash. This option suppresses that.
136
 *   PARSE_OPT_COMP_ARG: this option forces to git-completion.bash to
137
 *       complete an option as --name= not --name even if
138
 *       the option takes optional argument.
139
 *
140
 * `callback`::
141
 *   pointer to the callback to use for OPTION_CALLBACK
142
 *
143
 * `defval`::
144
 *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
145
 *   OPTION_{BIT,SET_INT} store the {mask,integer} to put in the value when met.
146
 *   CALLBACKS can use it like they want.
147
 *
148
 * `ll_callback`::
149
 *   pointer to the callback to use for OPTION_LOWLEVEL_CALLBACK
150
 *
151
 * `subcommand_fn`::
152
 *   pointer to a function to use for OPTION_SUBCOMMAND.
153
 *   It will be put in value when the subcommand is given on the command line.
154
 */
155
struct option {
156
  enum parse_opt_type type;
157
  int short_name;
158
  const char *long_name;
159
  void *value;
160
  size_t precision;
161
  const char *argh;
162
  const char *help;
163
164
  enum parse_opt_option_flags flags;
165
  parse_opt_cb *callback;
166
  intptr_t defval;
167
  parse_opt_ll_cb *ll_callback;
168
  intptr_t extra;
169
  parse_opt_subcommand_fn *subcommand_fn;
170
};
171
172
0
#define OPT_BIT_F(s, l, v, h, b, f) { \
173
0
  .type = OPTION_BIT, \
174
0
  .short_name = (s), \
175
0
  .long_name = (l), \
176
0
  .value = (v), \
177
0
  .precision = sizeof(*v), \
178
0
  .help = (h), \
179
0
  .flags = PARSE_OPT_NOARG|(f), \
180
0
  .callback = NULL, \
181
0
  .defval = (b), \
182
0
}
183
#define OPT_COUNTUP_F(s, l, v, h, f) { \
184
  .type = OPTION_COUNTUP, \
185
  .short_name = (s), \
186
  .long_name = (l), \
187
  .value = (v), \
188
  .precision = sizeof(*v), \
189
  .help = (h), \
190
  .flags = PARSE_OPT_NOARG|(f), \
191
}
192
0
#define OPT_SET_INT_F(s, l, v, h, i, f) { \
193
0
  .type = OPTION_SET_INT, \
194
0
  .short_name = (s), \
195
0
  .long_name = (l), \
196
0
  .value = (v), \
197
0
  .precision = sizeof(*v), \
198
0
  .help = (h), \
199
0
  .flags = PARSE_OPT_NOARG | (f), \
200
0
  .defval = (i), \
201
0
}
202
0
#define OPT_BOOL_F(s, l, v, h, f)   OPT_SET_INT_F(s, l, v, h, 1, f)
203
0
#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) { \
204
0
  .type = OPTION_CALLBACK, \
205
0
  .short_name = (s), \
206
0
  .long_name = (l), \
207
0
  .value = (v), \
208
0
  .argh = (a), \
209
0
  .help = (h), \
210
0
  .flags = (f), \
211
0
  .callback = (cb), \
212
0
}
213
0
#define OPT_STRING_F(s, l, v, a, h, f) { \
214
0
  .type = OPTION_STRING, \
215
0
  .short_name = (s), \
216
0
  .long_name = (l), \
217
0
  .value = (v), \
218
0
  .argh = (a), \
219
0
  .help = (h), \
220
0
  .flags = (f), \
221
0
}
222
0
#define OPT_INTEGER_F(s, l, v, h, f) { \
223
0
  .type = OPTION_INTEGER, \
224
0
  .short_name = (s), \
225
0
  .long_name = (l), \
226
0
  .value = (v) + BARF_UNLESS_SIGNED(*(v)), \
227
0
  .precision = sizeof(*v), \
228
0
  .argh = N_("n"), \
229
0
  .help = (h), \
230
0
  .flags = (f), \
231
0
}
232
233
0
#define OPT_END() { \
234
0
  .type = OPTION_END, \
235
0
}
236
0
#define OPT_GROUP(h) { \
237
0
  .type = OPTION_GROUP, \
238
0
  .help = (h), \
239
0
}
240
#define OPT_HIDDEN_GROUP(h) { \
241
  .type = OPTION_GROUP, \
242
  .help = (h), \
243
  .flags = PARSE_OPT_HIDDEN, \
244
}
245
0
#define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)
246
0
#define OPT_BITOP(s, l, v, h, set, clear) { \
247
0
  .type = OPTION_BITOP, \
248
0
  .short_name = (s), \
249
0
  .long_name = (l), \
250
0
  .value = (v), \
251
0
  .precision = sizeof(*v), \
252
0
  .help = (h), \
253
0
  .flags = PARSE_OPT_NOARG|PARSE_OPT_NONEG, \
254
0
  .defval = (set), \
255
0
  .extra = (clear), \
256
0
}
257
#define OPT_NEGBIT(s, l, v, h, b) { \
258
  .type = OPTION_NEGBIT, \
259
  .short_name = (s), \
260
  .long_name = (l), \
261
  .value = (v), \
262
  .precision = sizeof(*v), \
263
  .help = (h), \
264
  .flags = PARSE_OPT_NOARG, \
265
  .defval = (b), \
266
}
267
#define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)
268
0
#define OPT_SET_INT(s, l, v, h, i)  OPT_SET_INT_F(s, l, v, h, i, 0)
269
0
#define OPT_BOOL(s, l, v, h)        OPT_BOOL_F(s, l, v, h, 0)
270
#define OPT_HIDDEN_BOOL(s, l, v, h) { \
271
  .type = OPTION_SET_INT, \
272
  .short_name = (s), \
273
  .long_name = (l), \
274
  .value = (v), \
275
  .precision = sizeof(*v), \
276
  .help = (h), \
277
  .flags = PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, \
278
  .defval = 1, \
279
}
280
#define OPT_CMDMODE_F(s, l, v, h, i, f) { \
281
  .type = OPTION_SET_INT, \
282
  .short_name = (s), \
283
  .long_name = (l), \
284
  .value = (v), \
285
  .precision = sizeof(*v), \
286
  .help = (h), \
287
  .flags = PARSE_OPT_CMDMODE|PARSE_OPT_NOARG|PARSE_OPT_NONEG | (f), \
288
  .defval = (i), \
289
}
290
#define OPT_CMDMODE(s, l, v, h, i)  OPT_CMDMODE_F(s, l, v, h, i, 0)
291
292
0
#define OPT_INTEGER(s, l, v, h)     OPT_INTEGER_F(s, l, v, h, 0)
293
0
#define OPT_UNSIGNED(s, l, v, h) { \
294
0
  .type = OPTION_UNSIGNED, \
295
0
  .short_name = (s), \
296
0
  .long_name = (l), \
297
0
  .value = (v) + BARF_UNLESS_UNSIGNED(*(v)), \
298
0
  .precision = sizeof(*v), \
299
0
  .argh = N_("n"), \
300
0
  .help = (h), \
301
0
  .flags = PARSE_OPT_NONEG, \
302
0
}
303
#define OPT_STRING(s, l, v, a, h)   OPT_STRING_F(s, l, v, a, h, 0)
304
#define OPT_STRING_LIST(s, l, v, a, h) { \
305
  .type = OPTION_CALLBACK, \
306
  .short_name = (s), \
307
  .long_name = (l), \
308
  .value = (v), \
309
  .argh = (a), \
310
  .help = (h), \
311
  .callback = &parse_opt_string_list, \
312
}
313
#define OPT_STRVEC(s, l, v, a, h) { \
314
  .type = OPTION_CALLBACK, \
315
  .short_name = (s), \
316
  .long_name = (l), \
317
  .value = (v), \
318
  .argh = (a), \
319
  .help = (h), \
320
  .callback = &parse_opt_strvec, \
321
}
322
#define OPT_UYN(s, l, v, h) { \
323
  .type = OPTION_CALLBACK, \
324
  .short_name = (s), \
325
  .long_name = (l), \
326
  .value = (v), \
327
  .help = (h), \
328
  .flags = PARSE_OPT_NOARG, \
329
  .callback = &parse_opt_tertiary, \
330
}
331
#define OPT_EXPIRY_DATE(s, l, v, h) { \
332
  .type = OPTION_CALLBACK, \
333
  .short_name = (s), \
334
  .long_name = (l), \
335
  .value = (v), \
336
  .argh = N_("expiry-date"), \
337
  .help = (h), \
338
  .callback = parse_opt_expiry_date_cb, \
339
}
340
0
#define OPT_CALLBACK(s, l, v, a, h, cb) OPT_CALLBACK_F(s, l, v, a, h, 0, cb)
341
#define OPT_NUMBER_CALLBACK(v, h, cb) { \
342
  .type = OPTION_NUMBER, \
343
  .value = (v), \
344
  .help = (h), \
345
  .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG, \
346
  .callback = (cb), \
347
}
348
0
#define OPT_FILENAME(s, l, v, h) { \
349
0
  .type = OPTION_FILENAME, \
350
0
  .short_name = (s), \
351
0
  .long_name = (l), \
352
0
  .value = (v), \
353
0
  .argh = N_("file"), \
354
0
  .help = (h), \
355
0
}
356
0
#define OPT_COLOR_FLAG(s, l, v, h) { \
357
0
  .type = OPTION_CALLBACK, \
358
0
  .short_name = (s), \
359
0
  .long_name = (l), \
360
0
  .value = (v), \
361
0
  .argh = N_("when"), \
362
0
  .help = (h), \
363
0
  .flags = PARSE_OPT_OPTARG, \
364
0
  .callback = parse_opt_color_flag_cb, \
365
0
  .defval = (intptr_t)"always", \
366
0
}
367
368
0
#define OPT_NOOP_NOARG(s, l) { \
369
0
  .type = OPTION_CALLBACK, \
370
0
  .short_name = (s), \
371
0
  .long_name = (l), \
372
0
  .help = N_("no-op (backward compatibility)"), \
373
0
  .flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, \
374
0
  .callback = parse_opt_noop_cb, \
375
0
}
376
377
static char *parse_options_noop_ignored_value MAYBE_UNUSED;
378
#define OPT_NOOP_ARG(s, l) { \
379
  .type = OPTION_CALLBACK, \
380
  .short_name = (s), \
381
  .long_name = (l), \
382
  .value = &parse_options_noop_ignored_value, \
383
  .argh = "ignored", \
384
  .help = N_("no-op (backward compatibility)"), \
385
  .flags = PARSE_OPT_HIDDEN, \
386
  .callback = parse_opt_noop_cb, \
387
}
388
389
#define OPT_ALIAS_F(s, l, source_long_name, f) { \
390
  .type = OPTION_ALIAS, \
391
  .short_name = (s), \
392
  .long_name = (l), \
393
  .value = (char *)(source_long_name), \
394
  .flags = (f), \
395
}
396
397
#define OPT_ALIAS(s, l, source_long_name) OPT_ALIAS_F(s, l, source_long_name, 0)
398
399
#define OPT_SUBCOMMAND_F(l, v, fn, h, f) { \
400
  .type = OPTION_SUBCOMMAND, \
401
  .long_name = (l), \
402
  .value = (v), \
403
  .help = (h), \
404
  .flags = (f), \
405
  .subcommand_fn = (fn), \
406
}
407
#define OPT_SUBCOMMAND(l, v, fn)    OPT_SUBCOMMAND_F((l), (v), (fn), NULL, 0)
408
409
/*
410
 * parse_options() will filter out the processed options and leave the
411
 * non-option arguments in argv[]. argv0 is assumed program name and
412
 * skipped.
413
 *
414
 * usagestr strings should be marked for translation with N_().
415
 *
416
 * Returns the number of arguments left in argv[].
417
 *
418
 * In one-shot mode, argv0 is not a program name, argv[] is left
419
 * untouched and parse_options() returns the number of options
420
 * processed.
421
 */
422
int parse_options(int argc, const char **argv, const char *prefix,
423
      const struct option *options,
424
      const char * const usagestr[],
425
      enum parse_opt_flags flags);
426
427
NORETURN void usage_with_options(const char * const *usagestr,
428
         const struct option *options);
429
430
void show_usage_with_options_if_asked(int ac, const char **av,
431
              const char * const *usage,
432
              const struct option *options);
433
434
NORETURN void usage_msg_opt(const char *msg,
435
          const char * const *usagestr,
436
          const struct option *options);
437
438
/**
439
 * usage_msg_optf() is like usage_msg_opt() except that the first
440
 * argument is a format string, and optional format arguments follow
441
 * after the 3rd option.
442
 */
443
__attribute__((format (printf,1,4)))
444
void NORETURN usage_msg_optf(const char *fmt,
445
           const char * const *usagestr,
446
           const struct option *options, ...);
447
448
void die_for_incompatible_opt4(int opt1, const char *opt1_name,
449
             int opt2, const char *opt2_name,
450
             int opt3, const char *opt3_name,
451
             int opt4, const char *opt4_name);
452
453
454
static inline void die_for_incompatible_opt3(int opt1, const char *opt1_name,
455
               int opt2, const char *opt2_name,
456
               int opt3, const char *opt3_name)
457
0
{
458
0
  die_for_incompatible_opt4(opt1, opt1_name,
459
0
          opt2, opt2_name,
460
0
          opt3, opt3_name,
461
0
          0, "");
462
0
}
Unexecuted instantiation: submodule-config.c:die_for_incompatible_opt3
Unexecuted instantiation: submodule.c:die_for_incompatible_opt3
Unexecuted instantiation: column.c:die_for_incompatible_opt3
Unexecuted instantiation: diff.c:die_for_incompatible_opt3
Unexecuted instantiation: parse-options-cb.c:die_for_incompatible_opt3
Unexecuted instantiation: parse-options.c:die_for_incompatible_opt3
Unexecuted instantiation: remote.c:die_for_incompatible_opt3
Unexecuted instantiation: revision.c:die_for_incompatible_opt3
Unexecuted instantiation: apply.c:die_for_incompatible_opt3
Unexecuted instantiation: list-objects-filter-options.c:die_for_incompatible_opt3
Unexecuted instantiation: send-pack.c:die_for_incompatible_opt3
463
464
static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
465
               int opt2, const char *opt2_name)
466
0
{
467
0
  die_for_incompatible_opt4(opt1, opt1_name,
468
0
          opt2, opt2_name,
469
0
          0, "",
470
0
          0, "");
471
0
}
Unexecuted instantiation: submodule-config.c:die_for_incompatible_opt2
Unexecuted instantiation: submodule.c:die_for_incompatible_opt2
Unexecuted instantiation: column.c:die_for_incompatible_opt2
Unexecuted instantiation: diff.c:die_for_incompatible_opt2
Unexecuted instantiation: parse-options-cb.c:die_for_incompatible_opt2
Unexecuted instantiation: parse-options.c:die_for_incompatible_opt2
Unexecuted instantiation: remote.c:die_for_incompatible_opt2
Unexecuted instantiation: revision.c:die_for_incompatible_opt2
Unexecuted instantiation: apply.c:die_for_incompatible_opt2
Unexecuted instantiation: list-objects-filter-options.c:die_for_incompatible_opt2
Unexecuted instantiation: send-pack.c:die_for_incompatible_opt2
472
473
/*
474
 * Use these assertions for callbacks that expect to be called with NONEG and
475
 * NOARG respectively, and do not otherwise handle the "unset" and "arg"
476
 * parameters.
477
 */
478
0
#define BUG_ON_OPT_NEG(unset) do { \
479
0
  if ((unset)) \
480
0
    BUG("option callback does not expect negation"); \
481
0
} while (0)
482
0
#define BUG_ON_OPT_ARG(arg) do { \
483
0
  if ((arg)) \
484
0
    BUG("option callback does not expect an argument"); \
485
0
} while (0)
486
487
/*
488
 * Similar to the assertions above, but checks that "arg" is always non-NULL.
489
 * This assertion also implies BUG_ON_OPT_NEG(), letting you declare both
490
 * assertions in a single line.
491
 */
492
#define BUG_ON_OPT_NEG_NOARG(unset, arg) do { \
493
  BUG_ON_OPT_NEG(unset); \
494
  if(!(arg)) \
495
    BUG("option callback expects an argument"); \
496
} while(0)
497
498
/*----- incremental advanced APIs -----*/
499
500
struct parse_opt_cmdmode_list;
501
502
/*
503
 * It's okay for the caller to consume argv/argc in the usual way.
504
 * Other fields of that structure are private to parse-options and should not
505
 * be modified in any way.
506
 */
507
struct parse_opt_ctx_t {
508
  const char **argv;
509
  const char **out;
510
  int argc, cpidx, total;
511
  const char *opt;
512
  enum parse_opt_flags flags;
513
  unsigned has_subcommands;
514
  const char *prefix;
515
  const char **alias_groups; /* must be in groups of 3 elements! */
516
  struct parse_opt_cmdmode_list *cmdmode_list;
517
};
518
519
void parse_options_start(struct parse_opt_ctx_t *ctx,
520
       int argc, const char **argv, const char *prefix,
521
       const struct option *options,
522
       enum parse_opt_flags flags);
523
524
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
525
           const struct option *options,
526
           const char * const usagestr[]);
527
528
int parse_options_end(struct parse_opt_ctx_t *ctx);
529
530
struct option *parse_options_dup(const struct option *a);
531
struct option *parse_options_concat(const struct option *a, const struct option *b);
532
533
/*----- some often used options -----*/
534
int parse_opt_abbrev_cb(const struct option *, const char *, int);
535
int parse_opt_expiry_date_cb(const struct option *, const char *, int);
536
int parse_opt_color_flag_cb(const struct option *, const char *, int);
537
int parse_opt_verbosity_cb(const struct option *, const char *, int);
538
/* value is struct oid_array* */
539
int parse_opt_object_name(const struct option *, const char *, int);
540
/* value is struct object_id* */
541
int parse_opt_object_id(const struct option *, const char *, int);
542
int parse_opt_commits(const struct option *, const char *, int);
543
int parse_opt_commit(const struct option *, const char *, int);
544
int parse_opt_tertiary(const struct option *, const char *, int);
545
int parse_opt_string_list(const struct option *, const char *, int);
546
int parse_opt_strvec(const struct option *, const char *, int);
547
int parse_opt_noop_cb(const struct option *, const char *, int);
548
int parse_opt_passthru(const struct option *, const char *, int);
549
int parse_opt_passthru_argv(const struct option *, const char *, int);
550
/* value is enum branch_track* */
551
int parse_opt_tracking_mode(const struct option *, const char *, int);
552
553
#define OPT__VERBOSE(var, h)  OPT_COUNTUP('v', "verbose", (var), (h))
554
#define OPT__QUIET(var, h)    OPT_COUNTUP('q', "quiet",   (var), (h))
555
0
#define OPT__VERBOSITY(var) { \
556
0
  .type = OPTION_CALLBACK, \
557
0
  .short_name = 'v', \
558
0
  .long_name = "verbose", \
559
0
  .value = (var), \
560
0
  .help = N_("be more verbose"), \
561
0
  .flags = PARSE_OPT_NOARG, \
562
0
  .callback = &parse_opt_verbosity_cb, \
563
0
}, { \
564
0
  .type = OPTION_CALLBACK, \
565
0
  .short_name = 'q', \
566
0
  .long_name = "quiet", \
567
0
  .value = (var), \
568
0
  .help = N_("be more quiet"), \
569
0
  .flags = PARSE_OPT_NOARG, \
570
0
  .callback = &parse_opt_verbosity_cb, \
571
0
}
572
#define OPT__DRY_RUN(var, h)  OPT_BOOL('n', "dry-run", (var), (h))
573
#define OPT__FORCE(var, h, f) OPT_COUNTUP_F('f', "force",   (var), (h), (f))
574
0
#define OPT__ABBREV(var) { \
575
0
  .type = OPTION_CALLBACK, \
576
0
  .long_name = "abbrev", \
577
0
  .value = (var), \
578
0
  .argh = N_("n"), \
579
0
  .help = N_("use <n> digits to display object names"), \
580
0
  .flags = PARSE_OPT_OPTARG, \
581
0
  .callback = &parse_opt_abbrev_cb, \
582
0
}
583
#define OPT__SUPER_PREFIX(var) \
584
  OPT_STRING_F(0, "super-prefix", (var), N_("prefix"), \
585
    N_("prefixed path to initial superproject"), PARSE_OPT_HIDDEN)
586
587
#define OPT__COLOR(var, h) \
588
  OPT_COLOR_FLAG(0, "color", (var), (h))
589
#define OPT_COLUMN(s, l, v, h) { \
590
  .type = OPTION_CALLBACK, \
591
  .short_name = (s), \
592
  .long_name = (l), \
593
  .value = (v), \
594
  .argh = N_("style"), \
595
  .help = (h), \
596
  .flags = PARSE_OPT_OPTARG, \
597
  .callback = parseopt_column_callback, \
598
}
599
#define OPT_PASSTHRU(s, l, v, a, h, f) { \
600
  .type = OPTION_CALLBACK, \
601
  .short_name = (s), \
602
  .long_name = (l), \
603
  .value = (v), \
604
  .argh = (a), \
605
  .help = (h), \
606
  .flags = (f), \
607
  .callback = parse_opt_passthru, \
608
}
609
#define OPT_PASSTHRU_ARGV(s, l, v, a, h, f) { \
610
  .type = OPTION_CALLBACK, \
611
  .short_name = (s), \
612
  .long_name = (l), \
613
  .value = (v), \
614
  .argh = (a), \
615
  .help = (h), \
616
  .flags = (f), \
617
  .callback = parse_opt_passthru_argv, \
618
}
619
#define _OPT_CONTAINS_OR_WITH(l, v, h, f) { \
620
  .type = OPTION_CALLBACK, \
621
  .long_name = (l), \
622
  .value = (v), \
623
  .argh = N_("commit"), \
624
  .help = (h), \
625
  .flags = PARSE_OPT_LASTARG_DEFAULT | (f), \
626
  .callback = parse_opt_commits, \
627
  .defval = (intptr_t) "HEAD", \
628
}
629
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, PARSE_OPT_NONEG)
630
#define OPT_NO_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("no-contains", v, h, PARSE_OPT_NONEG)
631
#define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)
632
#define OPT_WITHOUT(v, h) _OPT_CONTAINS_OR_WITH("without", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)
633
#define OPT_CLEANUP(v) OPT_STRING(0, "cleanup", v, N_("mode"), N_("how to strip spaces and #comments from message"))
634
#define OPT_PATHSPEC_FROM_FILE(v) OPT_FILENAME(0, "pathspec-from-file", v, N_("read pathspec from file"))
635
#define OPT_PATHSPEC_FILE_NUL(v)  OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character"))
636
#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
637
#define OPT_DIFF_UNIFIED(v) OPT_INTEGER_F('U', "unified", v, N_("generate diffs with <n> lines context"), PARSE_OPT_NONEG)
638
#define OPT_DIFF_INTERHUNK_CONTEXT(v) OPT_INTEGER_F(0, "inter-hunk-context", v, N_("show context between diff hunks up to the specified number of lines"), PARSE_OPT_NONEG)
639
640
#define OPT_IPVERSION(v) \
641
  OPT_SET_INT_F('4', "ipv4", (v), N_("use IPv4 addresses only"), \
642
    TRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \
643
  OPT_SET_INT_F('6', "ipv6", (v), N_("use IPv6 addresses only"), \
644
    TRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)
645
646
#endif