Merge branch 'tb/grep-column'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Jul 2018 19:20:31 +0000 (12:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jul 2018 19:20:31 +0000 (12:20 -0700)
"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

1  2 
Documentation/config.txt
grep.c
grep.h
Simple merge
diff --cc grep.c
index 7e2f440955a01ae305664df37f77ed87a55c2b06,992673fe7e62de25afcb168ee6a40d1b8bd06d1d..cd7fc6f66cadfcb38ad73f171b97a419610aad37
--- 1/grep.c
--- 2/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);
        }
 -              output_color(opt, buf, strlen(buf), opt->color_columnno);
+       /*
+        * 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->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 ed25be271b5b6a002fdb582fd5c11a499a4f0c94,08a0b391c5bdf7a22055486d3b4fc76d41fd8e43..01d2cba6f80921538d0269aefcad6f11218392b0
--- 1/grep.h
--- 2/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;