Skip to content

Commit 5a40417

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97fe725 commit 5a40417

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

builtin/cat-file.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,6 @@ static int batch_objects(struct batch_options *opt)
618618
return retval;
619619
}
620620

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-
633621
static int git_cat_file_config(const char *var, const char *value, void *cb)
634622
{
635623
if (userdiff_config(var, value) < 0)
@@ -664,6 +652,17 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
664652
struct batch_options batch = {0};
665653
int unknown_type = 0;
666654

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+
};
667666
const struct option options[] = {
668667
OPT_GROUP(N_("<type> can be one of: blob, tree, commit, tag")),
669668
OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'),
@@ -700,43 +699,43 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
700699
git_config(git_cat_file_config, NULL);
701700

702701
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);
704703

705704
if (opt) {
706705
if (batch.enabled && (opt == 'c' || opt == 'w'))
707706
batch.cmdmode = opt;
708707
else if (argc == 1)
709708
obj_name = argv[0];
710709
else
711-
usage_with_options(cat_file_usage, options);
710+
usage_with_options(usage, options);
712711
}
713712
if (!opt && !batch.enabled) {
714713
if (argc == 2) {
715714
exp_type = argv[0];
716715
obj_name = argv[1];
717716
} else
718-
usage_with_options(cat_file_usage, options);
717+
usage_with_options(usage, options);
719718
}
720719
if (batch.enabled) {
721720
if (batch.cmdmode != opt || argc)
722-
usage_with_options(cat_file_usage, options);
721+
usage_with_options(usage, options);
723722
if (batch.cmdmode && batch.all_objects)
724723
die("--batch-all-objects cannot be combined with "
725724
"--textconv nor with --filters");
726725
}
727726

728727
if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) {
729-
usage_with_options(cat_file_usage, options);
728+
usage_with_options(usage, options);
730729
}
731730

732731
if (force_path && opt != 'c' && opt != 'w') {
733732
error("--path=<path> needs --textconv or --filters");
734-
usage_with_options(cat_file_usage, options);
733+
usage_with_options(usage, options);
735734
}
736735

737736
if (force_path && batch.enabled) {
738737
error("--path=<path> incompatible with --batch");
739-
usage_with_options(cat_file_usage, options);
738+
usage_with_options(usage, options);
740739
}
741740

742741
if (batch.buffer_output < 0)

0 commit comments

Comments
 (0)