Merge branch 'mk/blame-error-message' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 3 Nov 2015 23:32:42 +0000 (15:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Nov 2015 23:32:43 +0000 (15:32 -0800)
The error message from "git blame --contents --reverse" incorrectly
talked about "--contents --children".

* mk/blame-error-message:
blame: fix option name in error message

1  2 
builtin/blame.c
diff --combined builtin/blame.c
index 295ce92da5df25a9082b868e848ee9634145e636,b5474690153bae66727de6f4d44d6e395eddb9e4..6cac59c973bfcf1dc48e2a1af26375f914bb02c4
@@@ -6,7 -6,6 +6,7 @@@
   */
  
  #include "cache.h"
 +#include "refs.h"
  #include "builtin.h"
  #include "blob.h"
  #include "commit.h"
  #include "userdiff.h"
  #include "line-range.h"
  #include "line-log.h"
 +#include "dir.h"
  
 -static char blame_usage[] = N_("git blame [options] [rev-opts] [rev] [--] file");
 +static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
  
  static const char *blame_opt_usage[] = {
        blame_usage,
        "",
 -      N_("[rev-opts] are documented in git-rev-list(1)"),
 +      N_("<rev-opts> are documented in git-rev-list(1)"),
        NULL
  };
  
@@@ -51,7 -49,7 +51,7 @@@ static int xdl_opts
  static int abbrev = -1;
  static int no_whole_file_rename;
  
 -static enum date_mode blame_date_mode = DATE_ISO8601;
 +static struct date_mode blame_date_mode = { DATE_ISO8601 };
  static size_t blame_date_width;
  
  static struct string_list mailmap;
@@@ -974,10 -972,7 +974,10 @@@ static void pass_blame_to_parent(struc
        fill_origin_blob(&sb->revs->diffopt, target, &file_o);
        num_get_patch++;
  
 -      diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d);
 +      if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))
 +              die("unable to generate diff (%s -> %s)",
 +                  sha1_to_hex(parent->commit->object.sha1),
 +                  sha1_to_hex(target->commit->object.sha1));
        /* The rest are the same as the parent */
        blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent);
        *d.dstq = NULL;
@@@ -1123,9 -1118,7 +1123,9 @@@ static void find_copy_in_blob(struct sc
         * file_p partially may match that image.
         */
        memset(split, 0, sizeof(struct blame_entry [3]));
 -      diff_hunks(file_p, &file_o, 1, handle_split_cb, &d);
 +      if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))
 +              die("unable to generate diff (%s)",
 +                  sha1_to_hex(parent->commit->object.sha1));
        /* remainder, if any, all match the preimage */
        handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
  }
@@@ -1371,15 -1364,8 +1371,15 @@@ static void pass_whole_blame(struct sco
   */
  static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit)
  {
 -      if (!reverse)
 +      if (!reverse) {
 +              if (revs->first_parent_only &&
 +                  commit->parents &&
 +                  commit->parents->next) {
 +                      free_commit_list(commit->parents->next);
 +                      commit->parents->next = NULL;
 +              }
                return commit->parents;
 +      }
        return lookup_decoration(&revs->children, &commit->object);
  }
  
@@@ -1840,7 -1826,7 +1840,7 @@@ static const char *format_time(unsigne
                size_t time_width;
                int tz;
                tz = atoi(tz_str);
 -              time_str = show_date(time, tz, blame_date_mode);
 +              time_str = show_date(time, tz, &blame_date_mode);
                strbuf_addstr(&time_buf, time_str);
                /*
                 * Add space paddings to time_buf to display a fixed width
@@@ -2099,6 -2085,7 +2099,6 @@@ static void find_alignment(struct score
  
        for (e = sb->ent; e; e = e->next) {
                struct origin *suspect = e->suspect;
 -              struct commit_info ci;
                int num;
  
                if (compute_auto_abbrev)
                if (longest_file < num)
                        longest_file = num;
                if (!(suspect->commit->object.flags & METAINFO_SHOWN)) {
 +                      struct commit_info ci;
                        suspect->commit->object.flags |= METAINFO_SHOWN;
                        get_commit_info(suspect->commit, &ci, 1);
                        if (*option & OUTPUT_SHOW_EMAIL)
                                num = utf8_strwidth(ci.author.buf);
                        if (longest_author < num)
                                longest_author = num;
 +                      commit_info_destroy(&ci);
                }
                num = e->s_lno + e->num_lines;
                if (longest_src_lines < num)
                        longest_dst_lines = num;
                if (largest_score < ent_score(sb, e))
                        largest_score = ent_score(sb, e);
 -
 -              commit_info_destroy(&ci);
        }
        max_orig_digits = decimal_width(longest_src_lines);
        max_digits = decimal_width(longest_dst_lines);
@@@ -2165,6 -2152,16 +2165,6 @@@ static void sanity_check_refcnt(struct 
        }
  }
  
 -/*
 - * Used for the command line parsing; check if the path exists
 - * in the working tree.
 - */
 -static int has_string_in_work_tree(const char *path)
 -{
 -      struct stat st;
 -      return !lstat(path, &st);
 -}
 -
  static unsigned parse_score(const char *arg)
  {
        char *end;
@@@ -2189,18 -2186,10 +2189,18 @@@ static int git_blame_config(const char 
                blank_boundary = git_config_bool(var, value);
                return 0;
        }
 +      if (!strcmp(var, "blame.showemail")) {
 +              int *output_option = cb;
 +              if (git_config_bool(var, value))
 +                      *output_option |= OUTPUT_SHOW_EMAIL;
 +              else
 +                      *output_option &= ~OUTPUT_SHOW_EMAIL;
 +              return 0;
 +      }
        if (!strcmp(var, "blame.date")) {
                if (!value)
                        return config_error_nonbool(var);
 -              blame_date_mode = parse_date_format(value);
 +              parse_date_format(value, &blame_date_mode);
                return 0;
        }
  
@@@ -2239,19 -2228,20 +2239,19 @@@ static struct commit_list **append_pare
  static void append_merge_parents(struct commit_list **tail)
  {
        int merge_head;
 -      const char *merge_head_file = git_path("MERGE_HEAD");
        struct strbuf line = STRBUF_INIT;
  
 -      merge_head = open(merge_head_file, O_RDONLY);
 +      merge_head = open(git_path_merge_head(), O_RDONLY);
        if (merge_head < 0) {
                if (errno == ENOENT)
                        return;
 -              die("cannot open '%s' for reading", merge_head_file);
 +              die("cannot open '%s' for reading", git_path_merge_head());
        }
  
        while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
                unsigned char sha1[20];
                if (line.len < 40 || get_sha1_hex(line.buf, sha1))
 -                      die("unknown line in '%s': %s", merge_head_file, line.buf);
 +                      die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
                tail = append_parent(tail, sha1);
        }
        close(merge_head);
@@@ -2359,7 -2349,6 +2359,7 @@@ static struct commit *fake_working_tree
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
 +      convert_to_git(path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
        return commit;
  }
  
 -static const char *prepare_final(struct scoreboard *sb)
 +static char *prepare_final(struct scoreboard *sb)
  {
        int i;
        const char *final_commit_name = NULL;
                sb->final = (struct commit *) obj;
                final_commit_name = revs->pending.objects[i].name;
        }
 -      return final_commit_name;
 +      return xstrdup_or_null(final_commit_name);
  }
  
 -static const char *prepare_initial(struct scoreboard *sb)
 +static char *prepare_initial(struct scoreboard *sb)
  {
        int i;
        const char *final_commit_name = NULL;
        }
        if (!final_commit_name)
                die("No commit to dig down to?");
 -      return final_commit_name;
 +      return xstrdup(final_commit_name);
  }
  
  static int blame_copy_callback(const struct option *option, const char *arg, int unset)
@@@ -2500,7 -2489,7 +2500,7 @@@ int cmd_blame(int argc, const char **ar
        struct origin *o;
        struct blame_entry *ent = NULL;
        long dashdash_pos, lno;
 -      const char *final_commit_name = NULL;
 +      char *final_commit_name = NULL;
        enum object_type type;
  
        static struct string_list range_list;
        unsigned int range_i;
        long anchor;
  
 -      git_config(git_blame_config, NULL);
 +      git_config(git_blame_config, &output_option);
        init_revisions(&revs, NULL);
        revs.date_mode = blame_date_mode;
        DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
@@@ -2581,13 -2570,13 +2581,13 @@@ parse_done
  
        if (cmd_is_annotate) {
                output_option |= OUTPUT_ANNOTATE_COMPAT;
 -              blame_date_mode = DATE_ISO8601;
 +              blame_date_mode.type = DATE_ISO8601;
        } else {
                blame_date_mode = revs.date_mode;
        }
  
        /* The maximum width used to show the dates */
 -      switch (blame_date_mode) {
 +      switch (blame_date_mode.type) {
        case DATE_RFC2822:
                blame_date_width = sizeof("Thu, 19 Oct 2006 16:00:04 -0700");
                break;
        case DATE_NORMAL:
                blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
                break;
 +      case DATE_STRFTIME:
 +              blame_date_width = strlen(show_date(0, 0, &blame_date_mode)) + 1; /* add the null */
 +              break;
        }
        blame_date_width -= 1; /* strip the null */
  
                if (argc < 2)
                        usage_with_options(blame_opt_usage, options);
                path = add_prefix(prefix, argv[argc - 1]);
 -              if (argc == 3 && !has_string_in_work_tree(path)) { /* (2b) */
 +              if (argc == 3 && !file_exists(path)) { /* (2b) */
                        path = add_prefix(prefix, argv[1]);
                        argv[1] = argv[2];
                }
                argv[argc - 1] = "--";
  
                setup_work_tree();
 -              if (!has_string_in_work_tree(path))
 +              if (!file_exists(path))
                        die_errno("cannot stat path '%s'", path);
        }
  
                sb.commits.compare = compare_commits_by_commit_date;
        }
        else if (contents_from)
-               die("--contents and --children do not blend well.");
+               die("--contents and --reverse do not blend well.");
 +      else if (revs.first_parent_only)
 +              die("combining --first-parent and --reverse is not supported");
        else {
                final_commit_name = prepare_initial(&sb);
                sb.commits.compare = compare_commits_by_reverse_commit_date;
  
        assign_blame(&sb, opt);
  
 +      free(final_commit_name);
 +
        if (incremental)
                return 0;