doc txt & -h consistency: make "annotate" consistent

The cmd_blame() already detected whether it was processing "blame" or "annotate", but it didn't adjust its usage output accordingly. Let's do that. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 13, 2022 at 17:39 UTC df8738116f7a00f74c8ac75d10ced87164287819
2 files changed +17 -7
Documentation/git-annotate.txt
+1 -1
@@ -8,7 +8,7 @@ git-annotate - Annotate file lines with commit information
8 SYNOPSIS
9 --------
10 [verse]
11 -'git annotate' [<options>] <file> [<revision>]
11 +'git annotate' [<options>] [<rev-opts>] [<rev>] [--] <file>
12
13 DESCRIPTION
14 -----------
builtin/blame.c
+16 -6
@@ -30,6 +30,7 @@
30 #include "tag.h"
31
32 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
33 +static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
34
35 static const char *blame_opt_usage[] = {
36 blame_usage,
@@ -38,6 +39,13 @@ static const char *blame_opt_usage[] = {
39 NULL
40 };
41
42 +static const char *annotate_opt_usage[] = {
43 + annotate_usage,
44 + "",
45 + N_("<rev-opts> are documented in git-rev-list(1)"),
46 + NULL
47 +};
48 +
49 static int longest_file;
50 static int longest_author;
51 static int max_orig_digits;
@@ -899,6 +907,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
907 long anchor;
908 const int hexsz = the_hash_algo->hexsz;
909 long num_lines = 0;
910 + const char *str_usage = cmd_is_annotate ? annotate_usage : blame_usage;
911 + const char **opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;
912
913 setup_default_color_by_age();
914 git_config(git_blame_config, &output_option);
@@ -914,7 +924,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
924 parse_options_start(&ctx, argc, argv, prefix, options,
925 PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
926 for (;;) {
917 - switch (parse_options_step(&ctx, options, blame_opt_usage)) {
927 + switch (parse_options_step(&ctx, options, opt_usage)) {
928 case PARSE_OPT_NON_OPTION:
929 case PARSE_OPT_UNKNOWN:
930 break;
@@ -934,7 +944,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
944 ctx.argv[0] = "--children";
945 reverse = 1;
946 }
937 - parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
947 + parse_revision_opt(&revs, &ctx, options, opt_usage);
948 }
949 parse_done:
950 revision_opts_finish(&revs);
@@ -1040,7 +1050,7 @@ parse_done:
1050 switch (argc - dashdash_pos - 1) {
1051 case 2: /* (1b) */
1052 if (argc != 4)
1043 - usage_with_options(blame_opt_usage, options);
1053 + usage_with_options(opt_usage, options);
1054 /* reorder for the new way: <rev> -- <path> */
1055 argv[1] = argv[3];
1056 argv[3] = argv[2];
@@ -1051,11 +1061,11 @@ parse_done:
1061 argv[argc] = NULL;
1062 break;
1063 default:
1054 - usage_with_options(blame_opt_usage, options);
1064 + usage_with_options(opt_usage, options);
1065 }
1066 } else {
1067 if (argc < 2)
1058 - usage_with_options(blame_opt_usage, options);
1068 + usage_with_options(opt_usage, options);
1069 if (argc == 3 && is_a_rev(argv[argc - 1])) { /* (2b) */
1070 path = add_prefix(prefix, argv[1]);
1071 argv[1] = argv[2];
@@ -1113,7 +1123,7 @@ parse_done:
1123 nth_line_cb, &sb, lno, anchor,
1124 &bottom, &top, sb.path,
1125 the_repository->index))
1116 - usage(blame_usage);
1126 + usage(str_usage);
1127 if ((!lno && (top || bottom)) || lno < bottom)
1128 die(Q_("file %s has only %lu line",
1129 "file %s has only %lu lines",