Skip to content

Commit b48158a

Browse files
KarthikNayakgitster
authored andcommitted
cat-file: make the options mutually exclusive
We only parse the options if 2 or 3 arguments are specified. Update 'struct option options[]' to use OPT_CMDMODE rather than OPT_SET_INT to allow only one mutually exclusive option and avoid the need for checking number of arguments. This was written by Junio C Hamano, tested by me. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46f0344 commit b48158a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

builtin/cat-file.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
362362

363363
const struct option options[] = {
364364
OPT_GROUP(N_("<type> can be one of: blob, tree, commit, tag")),
365-
OPT_SET_INT('t', NULL, &opt, N_("show object type"), 't'),
366-
OPT_SET_INT('s', NULL, &opt, N_("show object size"), 's'),
367-
OPT_SET_INT('e', NULL, &opt,
365+
OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'),
366+
OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'),
367+
OPT_CMDMODE('e', NULL, &opt,
368368
N_("exit with zero when there's no error"), 'e'),
369-
OPT_SET_INT('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
370-
OPT_SET_INT(0, "textconv", &opt,
369+
OPT_CMDMODE('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
370+
OPT_CMDMODE(0, "textconv", &opt,
371371
N_("for blob objects, run textconv on object's content"), 'c'),
372372
{ OPTION_CALLBACK, 0, "batch", &batch, "format",
373373
N_("show info and content of objects fed from the standard input"),
@@ -380,9 +380,6 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
380380

381381
git_config(git_cat_file_config, NULL);
382382

383-
if (argc != 3 && argc != 2)
384-
usage_with_options(cat_file_usage, options);
385-
386383
argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
387384

388385
if (opt) {

0 commit comments

Comments
 (0)