From: Junio C Hamano Date: Wed, 18 Jul 2018 19:20:31 +0000 (-0700) Subject: Merge branch 'tb/grep-column' X-Git-Tag: v2.19.0-rc0~156 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d036d667b7f297f8305ffaaec212a95da7022ebe;p=thirdparty%2Fgit.git Merge branch 'tb/grep-column' "git grep" learned the "--column" option that gives not just the line number but the column number of the hit. * tb/grep-column: contrib/git-jump/git-jump: jump to exact location grep.c: add configuration variables to show matched option builtin/grep.c: add '--column' option to 'git-grep(1)' grep.c: display column number of first match grep.[ch]: extend grep_opt to allow showing matched column grep.c: expose {,inverted} match column in match_line() Documentation/config.txt: camel-case lineNumber for consistency --- d036d667b7f297f8305ffaaec212a95da7022ebe diff --cc grep.c index 7e2f440955,992673fe7e..cd7fc6f66c --- a/grep.c +++ b/grep.c @@@ -15,17 -13,6 +15,18 @@@ static int grep_source_is_binary(struc static struct grep_opt grep_defaults; +static const char *color_grep_slots[] = { + [GREP_COLOR_CONTEXT] = "context", + [GREP_COLOR_FILENAME] = "filename", + [GREP_COLOR_FUNCTION] = "function", + [GREP_COLOR_LINENO] = "lineNumber", ++ [GREP_COLOR_COLUMNNO] = "column", + [GREP_COLOR_MATCH_CONTEXT] = "matchContext", + [GREP_COLOR_MATCH_SELECTED] = "matchSelected", + [GREP_COLOR_SELECTED] = "selected", + [GREP_COLOR_SEP] = "separator", +}; + static void std_output(struct grep_opt *opt, const void *buf, size_t size) { fwrite(buf, size, 1, stdout); @@@ -55,14 -42,15 +56,15 @@@ void init_grep_defaults(void opt->pathname = 1; opt->max_depth = -1; opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED; - color_set(opt->color_context, ""); - color_set(opt->color_filename, ""); - color_set(opt->color_function, ""); - color_set(opt->color_lineno, ""); - color_set(opt->color_columnno, ""); - color_set(opt->color_match_context, GIT_COLOR_BOLD_RED); - color_set(opt->color_match_selected, GIT_COLOR_BOLD_RED); - color_set(opt->color_selected, ""); - color_set(opt->color_sep, GIT_COLOR_CYAN); + color_set(opt->colors[GREP_COLOR_CONTEXT], ""); + color_set(opt->colors[GREP_COLOR_FILENAME], ""); + color_set(opt->colors[GREP_COLOR_FUNCTION], ""); + color_set(opt->colors[GREP_COLOR_LINENO], ""); ++ color_set(opt->colors[GREP_COLOR_COLUMNNO], ""); + color_set(opt->colors[GREP_COLOR_MATCH_CONTEXT], GIT_COLOR_BOLD_RED); + color_set(opt->colors[GREP_COLOR_MATCH_SELECTED], GIT_COLOR_BOLD_RED); + color_set(opt->colors[GREP_COLOR_SELECTED], ""); + color_set(opt->colors[GREP_COLOR_SEP], GIT_COLOR_CYAN); opt->color = -1; opt->output = std_output; } @@@ -1387,9 -1443,20 +1437,20 @@@ static void show_line(struct grep_opt * if (opt->linenum) { char buf[32]; xsnprintf(buf, sizeof(buf), "%d", lno); - output_color(opt, buf, strlen(buf), opt->color_lineno); + output_color(opt, buf, strlen(buf), opt->colors[GREP_COLOR_LINENO]); output_sep(opt, sign); } + /* + * Treat 'cno' as the 1-indexed offset from the start of a non-context + * line to its first match. Otherwise, 'cno' is 0 indicating that we are + * being called with a context line. + */ + if (opt->columnnum && cno) { + char buf[32]; + xsnprintf(buf, sizeof(buf), "%"PRIuMAX, (uintmax_t)cno); - output_color(opt, buf, strlen(buf), opt->color_columnno); ++ output_color(opt, buf, strlen(buf), opt->colors[GREP_COLOR_COLUMNNO]); + output_sep(opt, sign); + } if (opt->color) { regmatch_t match; enum grep_context ctx = GREP_CONTEXT_BODY; diff --cc grep.h index ed25be271b,08a0b391c5..01d2cba6f8 --- a/grep.h +++ b/grep.h @@@ -62,18 -62,6 +62,19 @@@ enum grep_header_field GREP_HEADER_FIELD_MAX }; +enum grep_color { + GREP_COLOR_CONTEXT, + GREP_COLOR_FILENAME, + GREP_COLOR_FUNCTION, + GREP_COLOR_LINENO, ++ GREP_COLOR_COLUMNNO, + GREP_COLOR_MATCH_CONTEXT, + GREP_COLOR_MATCH_SELECTED, + GREP_COLOR_SELECTED, + GREP_COLOR_SEP, + NR_GREP_COLORS +}; + struct grep_pat { struct grep_pat *next; const char *origin;