cat-file: move "usage" variable to cmd_cat_file()
There's no benefit to defining this at a distance, and it makes the code harder to read as you've got to scroll up to see the usage that corresponds to the options. In subsequent commits I'll make use of usage_msg_opt(), which will be quite noisy if I have to use the long "cat_file_usage" variable, there's no other command being defined in this file, so let's rename it to just "usage". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Dec 28, 2021 at 14:28 UTC
5a40417876c8ec97e1f367a1638a558ec010e3d8
1 file changed
+18
-19
builtin/cat-file.c
+18
-19
@@ -618,18 +618,6 @@ static int batch_objects(struct batch_options *opt)
618
return retval;
619
}
620
621
-static const char * const cat_file_usage[] = {
622
- N_("git cat-file <type> <object>"),
623
- N_("git cat-file (-e | -p) <object>"),
624
- N_("git cat-file ( -t | -s ) [--allow-unknown-type] <object>"),
625
- N_("git cat-file (--batch | --batch-check) [--batch-all-objects]\n"
626
- " [--buffer] [--follow-symlinks] [--unordered]\n"
627
- " [--textconv | --filters]"),
628
- N_("git cat-file (--textconv | --filters )\n"
629
- " [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
630
- NULL
631
-};
632
-
621
static int git_cat_file_config(const char *var, const char *value, void *cb)
622
{
623
if (userdiff_config(var, value) < 0)
@@ -664,6 +652,17 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
652
struct batch_options batch = {0};
653
int unknown_type = 0;
654
655
+ const char * const usage[] = {
656
+ N_("git cat-file <type> <object>"),
657
+ N_("git cat-file (-e | -p) <object>"),
658
+ N_("git cat-file ( -t | -s ) [--allow-unknown-type] <object>"),
659
+ N_("git cat-file (--batch | --batch-check) [--batch-all-objects]\n"
660
+ " [--buffer] [--follow-symlinks] [--unordered]\n"
661
+ " [--textconv | --filters]"),
662
+ N_("git cat-file (--textconv | --filters )\n"
663
+ " [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
664
+ NULL
665
+ };
666
const struct option options[] = {
667
OPT_GROUP(N_("<type> can be one of: blob, tree, commit, tag")),
668
OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'),
@@ -700,7 +699,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
699
git_config(git_cat_file_config, NULL);
700
701
batch.buffer_output = -1;
703
- argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
702
+ argc = parse_options(argc, argv, prefix, options, usage, 0);
703
704
if (opt) {
705
if (batch.enabled && (opt == 'c' || opt == 'w'))
@@ -708,35 +707,35 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
707
else if (argc == 1)
708
obj_name = argv[0];
709
else
711
- usage_with_options(cat_file_usage, options);
710
+ usage_with_options(usage, options);
711
}
712
if (!opt && !batch.enabled) {
713
if (argc == 2) {
714
exp_type = argv[0];
715
obj_name = argv[1];
716
} else
718
- usage_with_options(cat_file_usage, options);
717
+ usage_with_options(usage, options);
718
}
719
if (batch.enabled) {
720
if (batch.cmdmode != opt || argc)
722
- usage_with_options(cat_file_usage, options);
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
}
726
727
if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) {
729
- usage_with_options(cat_file_usage, options);
728
+ usage_with_options(usage, options);
729
}
730
731
if (force_path && opt != 'c' && opt != 'w') {
732
error("--path=<path> needs --textconv or --filters");
734
- usage_with_options(cat_file_usage, options);
733
+ usage_with_options(usage, options);
734
}
735
736
if (force_path && batch.enabled) {
737
error("--path=<path> incompatible with --batch");
739
- usage_with_options(cat_file_usage, options);
738
+ usage_with_options(usage, options);
739
}
740
741
if (batch.buffer_output < 0)