From: Jonas Fonseca Date: Wed, 9 Mar 2011 23:15:49 +0000 (-0500) Subject: [GH-6] Make blame configurable via options from ~/.tigrc and the command line X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ff39685956079dcdf1b8a2a7ca59c540cfbe91c8;p=tig.git [GH-6] Make blame configurable via options from ~/.tigrc and the command line --- diff --git a/NEWS b/NEWS index bdbd0a4..6091738 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,13 @@ Release notes master ------ +Improvements: + + - (GH-6) Make blame configurable via extra options passed from the command + line and blame-options setting from ~/.tigrc. For example: + + set blame-options = -C -C -C + Bug fixes: - Expand %(directory) to . for the root directory. (GH-3) diff --git a/tig.1.txt b/tig.1.txt index 3e2ffdf..490a0a2 100644 --- a/tig.1.txt +++ b/tig.1.txt @@ -10,7 +10,7 @@ SYNOPSIS [verse] tig [options] [revisions] [--] [paths] tig show [options] [revisions] [--] [paths] -tig blame [rev] path +tig blame [options] [rev] path tig status tig < [git command output] @@ -37,10 +37,11 @@ parsing. All following options will be passed untouched to the underlying git command. show:: - Open diff view using the given git show options. + Open diff view using the given git-show(1) options. blame:: - Show given file annotated or blamed by commits. + Show given file annotated by commits. + Takes zero or more git-blame(1) options. Optionally limited from given revision. status:: diff --git a/tig.c b/tig.c index 9250cd7..f022f17 100644 --- a/tig.c +++ b/tig.c @@ -365,6 +365,7 @@ static FILE *opt_tty = NULL; static const char **opt_diff_argv = NULL; static const char **opt_rev_argv = NULL; static const char **opt_file_argv = NULL; +static const char **opt_blame_argv = NULL; #define is_initial_commit() (!get_ref_head()) #define is_head_commit(rev) (!strcmp((rev), "HEAD") || (get_ref_head() && !strcmp(rev, get_ref_head()->id))) @@ -933,6 +934,7 @@ add_builtin_run_requests(void) OPT_ERR_(NO_OPTION_VALUE, "No option value"), \ OPT_ERR_(NO_VALUE_ASSIGNED, "No value assigned"), \ OPT_ERR_(OBSOLETE_REQUEST_NAME, "Obsolete request name"), \ + OPT_ERR_(OUT_OF_MEMORY, "Out of memory"), \ OPT_ERR_(TOO_MANY_OPTION_ARGUMENTS, "Too many option arguments"), \ OPT_ERR_(UNKNOWN_ATTRIBUTE, "Unknown attribute"), \ OPT_ERR_(UNKNOWN_COLOR, "Unknown color"), \ @@ -1110,10 +1112,24 @@ parse_string(char *opt, const char *arg, size_t optsize) } } +static enum option_code +parse_args(const char ***args, const char *argv[]) +{ + if (!argv_copy(args, argv)) + return OPT_ERR_OUT_OF_MEMORY; + return OPT_OK; +} + /* Wants: name = value */ static enum option_code option_set_command(int argc, const char *argv[]) { + if (argc < 3) + return OPT_ERR_WRONG_NUMBER_OF_ARGUMENTS; + + if (!opt_blame_argv && !strcmp(argv[0], "blame-options")) + return parse_args(&opt_blame_argv, argv + 2); + if (argc != 3) return OPT_ERR_WRONG_NUMBER_OF_ARGUMENTS; @@ -2383,6 +2399,11 @@ format_argv(const char ***dst_argv, const char *src_argv[], bool replace, bool f break; continue; + } else if (!strcmp(arg, "%(blameargs)")) { + if (!argv_append_array(dst_argv, opt_blame_argv)) + break; + continue; + } else if (!strcmp(arg, "%(revargs)") || (first && !strcmp(arg, "%(commit)"))) { if (!argv_append_array(dst_argv, opt_rev_argv)) @@ -4181,7 +4202,7 @@ blame_read_file(struct view *view, const char *line, bool *read_file) { if (!line) { const char *blame_argv[] = { - "git", "blame", "--incremental", + "git", "blame", "%(blameargs)", "--incremental", *opt_ref ? opt_ref : "--incremental", "--", opt_file, NULL }; @@ -6695,7 +6716,7 @@ static const char usage[] = "\n" "Usage: tig [options] [revs] [--] [paths]\n" " or: tig show [options] [revs] [--] [paths]\n" -" or: tig blame [rev] path\n" +" or: tig blame [options] [rev] [--] path\n" " or: tig status\n" " or: tig < [git command output]\n" "\n" @@ -6792,16 +6813,18 @@ parse_options(int argc, const char *argv[]) return REQ_VIEW_STATUS; } else if (!strcmp(subcommand, "blame")) { - if (argc <= 2 || argc > 4) + filter_rev_parse(&opt_file_argv, "--no-revs", "--no-flags", argv + 2); + filter_rev_parse(&opt_blame_argv, "--no-revs", "--flags", argv + 2); + filter_rev_parse(&opt_rev_argv, "--symbolic", "--revs-only", argv + 2); + + if (!opt_file_argv || opt_file_argv[1] || (opt_rev_argv && opt_rev_argv[1])) die("invalid number of options to blame\n\n%s", usage); - i = 2; - if (argc == 4) { - string_ncopy(opt_ref, argv[i], strlen(argv[i])); - i++; + if (opt_rev_argv) { + string_ncopy(opt_ref, opt_rev_argv[0], strlen(opt_rev_argv[0])); } - string_ncopy(opt_file, argv[i], strlen(argv[i])); + string_ncopy(opt_file, opt_file_argv[0], strlen(opt_file_argv[0])); return REQ_VIEW_BLAME; } else if (!strcmp(subcommand, "show")) { diff --git a/tigrc.5.txt b/tigrc.5.txt index 649a47a..1464492 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -49,6 +49,7 @@ set show-line-numbers = no # Show line numbers? set line-number-interval = 5 # Interval between line numbers set commit-encoding = "UTF-8" # Commit encoding set horizontal-scroll = 33% # Scroll 33% of the view width +set blame-options = -C -C -C # Blame lines from other files -------------------------------------------------------------------------- Or in the git configuration files: @@ -91,6 +92,13 @@ The following variables can be set: Width of the author column. When set to 5 or below, the author name will be abbreviated to the author's initials. +'blame-options' (string):: + + A space separated string of extra blame options. Can be used for + telling git-blame(1) how to detect the origin of lines. The value + is ignored when tig is started in blame mode and given blame options + on the command line. + 'commit-encoding' (string):: The encoding used for commits. The default is UTF-8. Note this option