interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / parse-options.h

646 lines · 19753 bytes Raw Blame History
1#ifndef PARSE_OPTIONS_H
2#define PARSE_OPTIONS_H
3
4#include "gettext.h"
5
6struct repository;
7
8/**
9 * Refer to Documentation/technical/api-parse-options.adoc for the API doc.
10 */
11
12enum 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
34enum 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
45enum 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
59enum 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
70struct option;
71typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
72
73struct parse_opt_ctx_t;
74typedef 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
78typedef 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 */
155struct 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#define OPT_BIT_F(s, l, v, h, b, f) { \
173 .type = OPTION_BIT, \
174 .short_name = (s), \
175 .long_name = (l), \
176 .value = (v), \
177 .precision = sizeof(*v), \
178 .help = (h), \
179 .flags = PARSE_OPT_NOARG|(f), \
180 .callback = NULL, \
181 .defval = (b), \
182}
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#define OPT_SET_INT_F(s, l, v, h, i, f) { \
193 .type = OPTION_SET_INT, \
194 .short_name = (s), \
195 .long_name = (l), \
196 .value = (v), \
197 .precision = sizeof(*v), \
198 .help = (h), \
199 .flags = PARSE_OPT_NOARG | (f), \
200 .defval = (i), \
201}
202#define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f)
203#define OPT_CALLBACK_F(s, l, v, a, h, f, cb) { \
204 .type = OPTION_CALLBACK, \
205 .short_name = (s), \
206 .long_name = (l), \
207 .value = (v), \
208 .argh = (a), \
209 .help = (h), \
210 .flags = (f), \
211 .callback = (cb), \
212}
213#define OPT_STRING_F(s, l, v, a, h, f) { \
214 .type = OPTION_STRING, \
215 .short_name = (s), \
216 .long_name = (l), \
217 .value = (v), \
218 .argh = (a), \
219 .help = (h), \
220 .flags = (f), \
221}
222#define OPT_INTEGER_F(s, l, v, h, f) { \
223 .type = OPTION_INTEGER, \
224 .short_name = (s), \
225 .long_name = (l), \
226 .value = (v) + BARF_UNLESS_SIGNED(*(v)), \
227 .precision = sizeof(*v), \
228 .argh = N_("n"), \
229 .help = (h), \
230 .flags = (f), \
231}
232
233#define OPT_END() { \
234 .type = OPTION_END, \
235}
236#define OPT_GROUP(h) { \
237 .type = OPTION_GROUP, \
238 .help = (h), \
239}
240#define OPT_HIDDEN_GROUP(h) { \
241 .type = OPTION_GROUP, \
242 .help = (h), \
243 .flags = PARSE_OPT_HIDDEN, \
244}
245#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
246#define OPT_BITOP(s, l, v, h, set, clear) { \
247 .type = OPTION_BITOP, \
248 .short_name = (s), \
249 .long_name = (l), \
250 .value = (v), \
251 .precision = sizeof(*v), \
252 .help = (h), \
253 .flags = PARSE_OPT_NOARG|PARSE_OPT_NONEG, \
254 .defval = (set), \
255 .extra = (clear), \
256}
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#define OPT_SET_INT(s, l, v, h, i) OPT_SET_INT_F(s, l, v, h, i, 0)
269#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#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
293#define OPT_UNSIGNED(s, l, v, h) { \
294 .type = OPTION_UNSIGNED, \
295 .short_name = (s), \
296 .long_name = (l), \
297 .value = (v) + BARF_UNLESS_UNSIGNED(*(v)), \
298 .precision = sizeof(*v), \
299 .argh = N_("n"), \
300 .help = (h), \
301 .flags = PARSE_OPT_NONEG, \
302}
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#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#define OPT_FILENAME(s, l, v, h) { \
349 .type = OPTION_FILENAME, \
350 .short_name = (s), \
351 .long_name = (l), \
352 .value = (v), \
353 .argh = N_("file"), \
354 .help = (h), \
355}
356#define OPT_COLOR_FLAG(s, l, v, h) { \
357 .type = OPTION_CALLBACK, \
358 .short_name = (s), \
359 .long_name = (l), \
360 .value = (v), \
361 .argh = N_("when"), \
362 .help = (h), \
363 .flags = PARSE_OPT_OPTARG, \
364 .callback = parse_opt_color_flag_cb, \
365 .defval = (intptr_t)"always", \
366}
367
368#define OPT_NOOP_NOARG(s, l) { \
369 .type = OPTION_CALLBACK, \
370 .short_name = (s), \
371 .long_name = (l), \
372 .help = N_("no-op (backward compatibility)"), \
373 .flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, \
374 .callback = parse_opt_noop_cb, \
375}
376
377static 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 */
422int 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
427NORETURN void usage_with_options(const char * const *usagestr,
428 const struct option *options);
429
430void show_usage_with_options_if_asked(int ac, const char **av,
431 const char * const *usage,
432 const struct option *options);
433
434NORETURN 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)))
444void NORETURN usage_msg_optf(const char *fmt,
445 const char * const *usagestr,
446 const struct option *options, ...);
447
448void 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
454static 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{
458 die_for_incompatible_opt4(opt1, opt1_name,
459 opt2, opt2_name,
460 opt3, opt3_name,
461 0, "");
462}
463
464static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
465 int opt2, const char *opt2_name)
466{
467 die_for_incompatible_opt4(opt1, opt1_name,
468 opt2, opt2_name,
469 0, "",
470 0, "");
471}
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#define BUG_ON_OPT_NEG(unset) do { \
479 if ((unset)) \
480 BUG("option callback does not expect negation"); \
481} while (0)
482#define BUG_ON_OPT_ARG(arg) do { \
483 if ((arg)) \
484 BUG("option callback does not expect an argument"); \
485} 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
500struct 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 */
507struct 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
519void 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
524enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
525 const struct option *options,
526 const char * const usagestr[]);
527
528int parse_options_end(struct parse_opt_ctx_t *ctx);
529
530struct option *parse_options_dup(const struct option *a);
531struct option *parse_options_concat(const struct option *a, const struct option *b);
532
533/*----- some often used options -----*/
534int parse_opt_abbrev_cb(const struct option *, const char *, int);
535int parse_opt_expiry_date_cb(const struct option *, const char *, int);
536int parse_opt_color_flag_cb(const struct option *, const char *, int);
537int parse_opt_verbosity_cb(const struct option *, const char *, int);
538/* value is struct oid_array* */
539int parse_opt_object_name(const struct option *, const char *, int);
540/* value is struct object_id* */
541int parse_opt_object_id(const struct option *, const char *, int);
542int parse_opt_commits(const struct option *, const char *, int);
543int parse_opt_commit(const struct option *, const char *, int);
544int parse_opt_tertiary(const struct option *, const char *, int);
545int parse_opt_string_list(const struct option *, const char *, int);
546int parse_opt_strvec(const struct option *, const char *, int);
547int parse_opt_noop_cb(const struct option *, const char *, int);
548int parse_opt_passthru(const struct option *, const char *, int);
549int parse_opt_passthru_argv(const struct option *, const char *, int);
550/* value is enum branch_track* */
551int 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#define OPT__VERBOSITY(var) { \
556 .type = OPTION_CALLBACK, \
557 .short_name = 'v', \
558 .long_name = "verbose", \
559 .value = (var), \
560 .help = N_("be more verbose"), \
561 .flags = PARSE_OPT_NOARG, \
562 .callback = &parse_opt_verbosity_cb, \
563}, { \
564 .type = OPTION_CALLBACK, \
565 .short_name = 'q', \
566 .long_name = "quiet", \
567 .value = (var), \
568 .help = N_("be more quiet"), \
569 .flags = PARSE_OPT_NOARG, \
570 .callback = &parse_opt_verbosity_cb, \
571}
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#define OPT__ABBREV(var) { \
575 .type = OPTION_CALLBACK, \
576 .long_name = "abbrev", \
577 .value = (var), \
578 .argh = N_("n"), \
579 .help = N_("use <n> digits to display object names"), \
580 .flags = PARSE_OPT_OPTARG, \
581 .callback = &parse_opt_abbrev_cb, \
582}
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