fetch-pack: put shallow info in output parameter
[gitweb.git] / builtin / blame.c
index 35104e41603942c8ee8b19d528d76dfc16675eab..3295718841aab1051ee8bdde0b1fc0aa26ae5f00 100644 (file)
@@ -49,6 +49,7 @@ static int abbrev = -1;
 static int no_whole_file_rename;
 static int show_progress;
 static char repeated_meta_color[COLOR_MAXLEN];
+static int coloring_mode;
 
 static struct date_mode blame_date_mode = { DATE_ISO8601 };
 static size_t blame_date_width;
@@ -410,6 +411,7 @@ static void parse_color_fields(const char *s)
                die (_("must end with a color"));
 
        colorfield[colorfield_nr].hop = TIME_MAX;
+       string_list_clear(&l, 0);
 }
 
 static void setup_default_color_by_age(void)
@@ -583,7 +585,7 @@ static int read_ancestry(const char *graft_file)
 
 static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect)
 {
-       const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
+       const char *uniq = find_unique_abbrev(&suspect->commit->object.oid,
                                              auto_abbrev);
        int len = strlen(uniq);
        if (auto_abbrev < len)
@@ -702,6 +704,20 @@ static int git_blame_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "blame.coloring")) {
+               if (!strcmp(value, "repeatedLines")) {
+                       coloring_mode |= OUTPUT_COLOR_LINE;
+               } else if (!strcmp(value, "highlightRecent")) {
+                       coloring_mode |= OUTPUT_SHOW_AGE_WITH_COLOR;
+               } else if (!strcmp(value, "none")) {
+                       coloring_mode &= ~(OUTPUT_COLOR_LINE |
+                                           OUTPUT_SHOW_AGE_WITH_COLOR);
+               } else {
+                       warning(_("invalid value for blame.coloring"));
+                       return 0;
+               }
+       }
+
        if (git_diff_heuristic_config(var, value, cb) < 0)
                return -1;
        if (userdiff_config(var, value) < 0)
@@ -743,6 +759,15 @@ static int blame_move_callback(const struct option *option, const char *arg, int
        return 0;
 }
 
+static int is_a_rev(const char *name)
+{
+       struct object_id oid;
+
+       if (get_oid(name, &oid))
+               return 0;
+       return OBJ_NONE < oid_object_info(the_repository, &oid, NULL);
+}
+
 int cmd_blame(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
@@ -817,6 +842,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        for (;;) {
                switch (parse_options_step(&ctx, options, blame_opt_usage)) {
                case PARSE_OPT_HELP:
+               case PARSE_OPT_ERROR:
                        exit(129);
                case PARSE_OPT_DONE:
                        if (ctx.argv[0])
@@ -942,16 +968,15 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
        } else {
                if (argc < 2)
                        usage_with_options(blame_opt_usage, options);
-               path = add_prefix(prefix, argv[argc - 1]);
-               if (argc == 3 && !file_exists(path)) { /* (2b) */
+               if (argc == 3 && is_a_rev(argv[argc - 1])) { /* (2b) */
                        path = add_prefix(prefix, argv[1]);
                        argv[1] = argv[2];
+               } else {        /* (2a) */
+                       if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree())
+                               die("missing <path> to blame");
+                       path = add_prefix(prefix, argv[argc - 1]);
                }
                argv[argc - 1] = "--";
-
-               setup_work_tree();
-               if (!file_exists(path))
-                       die_errno("cannot stat path '%s'", path);
        }
 
        revs.disable_stdin = 1;
@@ -1037,6 +1062,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
        blame_coalesce(&sb);
 
+       if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
+               output_option |= coloring_mode;
+
        if (!(output_option & OUTPUT_PORCELAIN)) {
                find_alignment(&sb, &output_option);
                if (!*repeated_meta_color &&