]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/blame.c
environment.h: move declarations for environment.c functions from cache.h
[thirdparty/git.git] / builtin / blame.c
index 02e39420b62babb5124708f3305985ebe6e316a9..9ec82edcbde540ffd0ff2c615742b43ac4a5fab0 100644 (file)
@@ -5,10 +5,14 @@
  * See COPYING for licensing conditions
  */
 
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
 #include "config.h"
 #include "color.h"
 #include "builtin.h"
+#include "environment.h"
+#include "gettext.h"
+#include "hex.h"
 #include "repository.h"
 #include "commit.h"
 #include "diff.h"
@@ -30,6 +34,7 @@
 #include "tag.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
+static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
 
 static const char *blame_opt_usage[] = {
        blame_usage,
@@ -38,6 +43,13 @@ static const char *blame_opt_usage[] = {
        NULL
 };
 
+static const char *annotate_opt_usage[] = {
+       annotate_usage,
+       "",
+       N_("<rev-opts> are documented in git-rev-list(1)"),
+       NULL
+};
+
 static int longest_file;
 static int longest_author;
 static int max_orig_digits;
@@ -899,6 +911,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        long anchor;
        const int hexsz = the_hash_algo->hexsz;
        long num_lines = 0;
+       const char *str_usage = cmd_is_annotate ? annotate_usage : blame_usage;
+       const char **opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;
 
        setup_default_color_by_age();
        git_config(git_blame_config, &output_option);
@@ -914,12 +928,13 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        parse_options_start(&ctx, argc, argv, prefix, options,
                            PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
        for (;;) {
-               switch (parse_options_step(&ctx, options, blame_opt_usage)) {
+               switch (parse_options_step(&ctx, options, opt_usage)) {
                case PARSE_OPT_NON_OPTION:
                case PARSE_OPT_UNKNOWN:
                        break;
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
+               case PARSE_OPT_SUBCOMMAND:
                        exit(129);
                case PARSE_OPT_COMPLETE:
                        exit(0);
@@ -933,7 +948,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                        ctx.argv[0] = "--children";
                        reverse = 1;
                }
-               parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
+               parse_revision_opt(&revs, &ctx, options, opt_usage);
        }
 parse_done:
        revision_opts_finish(&revs);
@@ -1039,7 +1054,7 @@ parse_done:
                switch (argc - dashdash_pos - 1) {
                case 2: /* (1b) */
                        if (argc != 4)
-                               usage_with_options(blame_opt_usage, options);
+                               usage_with_options(opt_usage, options);
                        /* reorder for the new way: <rev> -- <path> */
                        argv[1] = argv[3];
                        argv[3] = argv[2];
@@ -1050,11 +1065,11 @@ parse_done:
                        argv[argc] = NULL;
                        break;
                default:
-                       usage_with_options(blame_opt_usage, options);
+                       usage_with_options(opt_usage, options);
                }
        } else {
                if (argc < 2)
-                       usage_with_options(blame_opt_usage, options);
+                       usage_with_options(opt_usage, options);
                if (argc == 3 && is_a_rev(argv[argc - 1])) { /* (2b) */
                        path = add_prefix(prefix, argv[1]);
                        argv[1] = argv[2];
@@ -1112,7 +1127,7 @@ parse_done:
                                    nth_line_cb, &sb, lno, anchor,
                                    &bottom, &top, sb.path,
                                    the_repository->index))
-                       usage(blame_usage);
+                       usage(str_usage);
                if ((!lno && (top || bottom)) || lno < bottom)
                        die(Q_("file %s has only %lu line",
                               "file %s has only %lu lines",