Skip to content

Commit 485fd2c

Browse files
avargitster
authored andcommitted
cat-file: make --batch-all-objects a CMDMODE
The usage of OPT_CMDMODE() in "cat-file"[1] was added in parallel with the development of[3] the --batch-all-objects option[4], so we've since grown[5] checks that it can't be combined with other command modes, when it should just be made a top-level command-mode instead. It doesn't combine with --filters, --textconv etc. By giving parse_options() information about what options are mutually exclusive with one another we can get the die() message being removed here for free, we didn't even use that removed message in some cases, e.g. for both of: --batch-all-objects --textconv --batch-all-objects --filters We'd take the "goto usage" in the "if (opt)" branch, and never reach the previous message. Now we'll emit e.g.: $ git cat-file --batch-all-objects --filters error: option `filters' is incompatible with --batch-all-objects 1. b48158a (cat-file: make the options mutually exclusive, 2015-05-03) 2. https://lore.kernel.org/git/[email protected]/ 3. https://lore.kernel.org/git/[email protected]/ 4. 6a95193 (cat-file: add --batch-all-objects option, 2015-06-22) 5. 3214594 (cat-file: support --textconv/--filters in batch mode, 2016-09-09) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a40417 commit 485fd2c

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

builtin/cat-file.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
674674
N_("for blob objects, run textconv on object's content"), 'c'),
675675
OPT_CMDMODE(0, "filters", &opt,
676676
N_("for blob objects, run filters on object's content"), 'w'),
677+
OPT_CMDMODE(0, "batch-all-objects", &opt,
678+
N_("show all objects with --batch or --batch-check"), 'b'),
677679
OPT_STRING(0, "path", &force_path, N_("blob"),
678680
N_("use a specific path for --textconv/--filters")),
679681
OPT_BOOL(0, "allow-unknown-type", &unknown_type,
@@ -689,8 +691,6 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
689691
batch_option_callback),
690692
OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks,
691693
N_("follow in-tree symlinks (used with --batch or --batch-check)")),
692-
OPT_BOOL(0, "batch-all-objects", &batch.all_objects,
693-
N_("show all objects with --batch or --batch-check")),
694694
OPT_BOOL(0, "unordered", &batch.unordered,
695695
N_("do not order --batch-all-objects output")),
696696
OPT_END()
@@ -699,30 +699,27 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
699699
git_config(git_cat_file_config, NULL);
700700

701701
batch.buffer_output = -1;
702-
argc = parse_options(argc, argv, prefix, options, usage, 0);
703702

704-
if (opt) {
703+
argc = parse_options(argc, argv, prefix, options, usage, 0);
704+
if (argc && batch.enabled)
705+
usage_with_options(usage, options);
706+
if (opt == 'b') {
707+
batch.all_objects = 1;
708+
} else if (opt) {
705709
if (batch.enabled && (opt == 'c' || opt == 'w'))
706710
batch.cmdmode = opt;
707711
else if (argc == 1)
708712
obj_name = argv[0];
709713
else
710714
usage_with_options(usage, options);
711-
}
712-
if (!opt && !batch.enabled) {
715+
} else if (!opt && !batch.enabled) {
713716
if (argc == 2) {
714717
exp_type = argv[0];
715718
obj_name = argv[1];
716719
} else
717720
usage_with_options(usage, options);
718-
}
719-
if (batch.enabled) {
720-
if (batch.cmdmode != opt || argc)
721-
usage_with_options(usage, options);
722-
if (batch.cmdmode && batch.all_objects)
723-
die("--batch-all-objects cannot be combined with "
724-
"--textconv nor with --filters");
725-
}
721+
} else if (batch.enabled && batch.cmdmode != opt)
722+
usage_with_options(usage, options);
726723

727724
if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) {
728725
usage_with_options(usage, options);

t/t1006-cat-file.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ for switches in \
1414
'-p -t' \
1515
'-t -s' \
1616
'-s --textconv' \
17-
'--textconv --filters'
17+
'--textconv --filters' \
18+
'--batch-all-objects -e'
1819
do
1920
test_expect_success "usage: cmdmode $switches" '
2021
test_cmdmode_usage git cat-file $switches
@@ -41,10 +42,6 @@ do
4142
test_expect_success "usage: $opt requires another option" '
4243
test_expect_code 129 git cat-file $opt
4344
'
44-
45-
test_expect_failure "usage: incompatible options: --batch-all-objects with $opt" '
46-
test_incompatible_usage git cat-file --batch-all-objects $opt
47-
'
4845
done
4946

5047
for opt in $short_modes

0 commit comments

Comments
 (0)