{"thread":{"id":"48339","subject":"[PATCH 1/6] grep.c: take regmatch_t as argument in match_line()","startedAt":"2018-04-21T03:45:36Z","lastAt":"2018-05-19T04:44:35Z","messageCount":108,"participants":["Taylor Blau","Junio C Hamano","René Scharfe","Martin Ågren","Ævar Arnfjörð Bjarmason","Eric Sunshine","Duy Nguyen","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"345298","messageId":"20180421034530.GB24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 1/6] grep.c: take regmatch_t as argument in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:30Z","receivedAt":"2018-04-21T03:45:36Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"In a subsequent patch, we teach show_line() to optionally include the\ncolumn number of the first match on each matched line.\n\nThe regmatch_t involved in match_line() and match_one_pattern() both\ncontain this information (via regmatch_t->rm_so), but their current\nimplementation throws this stack variable away at the end of the call.\n\nInstead, let's teach match_line() to take in a 'regmatch_t *' so that\ncallers can inspect the result of their calls. This will prove useful in\na subsequent commit when a caller will forward on information from the\nregmatch_t into show_line (as described above).\n\nThe return condition remains unchanged, therefore the only change\nrequired of callers is the addition of a single argument.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"345299","messageId":"20180421034532.GC24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:32Z","receivedAt":"2018-04-21T03:45:40Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"show_line() currently receives the line number within the\n'grep_opt->buf' in order to determine which line number to display. In\norder to display information about the matching column number--if\nrequested--we must additionally take in that information.\n\nTo do so, we extend the signature of show_line() to take in an\nadditional unsigned \"cno\". \"cno\" is either:\n\n  * A 1-indexed column number of the first match on the given line, or\n  * 0, if the column number is irrelevant (when displaying a function\n    name, context lines, etc).\n\nWe additionally modify all calls to show_line() in order to pass the new\nrequired argument.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..29bc799ecf 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1361,7 +1361,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1501,7 +1501,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1566,7 +1566,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1830,7 +1830,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1859,7 +1859,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"345300","messageId":"20180421034535.GD24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:35Z","receivedAt":"2018-04-21T03:45:42Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"In preparation of adding --column-number to 'git-grep(1)', we extend\ngrep_opt to take in the requisite new members.\n\nWe additionally teach the 'grep.columnnumber' and\n'color.grep.columnumber' configuration variables to configure showing\nand coloring the column number, respectively. (These options remain\nundocumented until 'git-grep(1)' learns the --column option in a\nforthcoming commit.)\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 8 ++++++++\n grep.h | 2 ++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 29bc799ecf..7872a5d868 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -95,6 +95,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.columnnumber\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -111,6 +115,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.columnumber\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n@@ -155,6 +161,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +171,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"345301","messageId":"20180421034537.GE24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 4/6] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:37Z","receivedAt":"2018-04-21T03:45:46Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Building upon our work in the previous commit to add members 'columnnum'\nand 'color_columno' to 'grep_opt', we teach show_line() how to respect\nthose options.\n\nWhen requested, show_line() will display the column number of the first\nmatch on a non-context line. show_line() differentiates between context\nand non-context lines through the '&& cno' check. 'cno' will be equal to\nzero if and only if show_line() is invoked on a context line. It will be\na non-zero value otherwise.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 7872a5d868..5aeb893263 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1404,6 +1404,12 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n-- \n2.17.0\n\n"},{"id":"345302","messageId":"20180421034540.GF24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:40Z","receivedAt":"2018-04-21T03:45:48Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"This commit teaches 'git-grep(1)' a new option, '--column-number'. This\noption builds upon previous commits to show the column number of the\nfirst match on a non-context line.\n\nFor example:\n\n  $ git grep -mn example | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nNow that configuration variables such as grep.columnNumber and\ncolor.grep.columnNumber have a visible effect, we document them in this\npatch as well.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   |  5 +++++\n Documentation/git-grep.txt |  9 ++++++++-\n builtin/grep.c             |  1 +\n t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n 4 files changed, 36 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..02fd4b662b 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,6 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `linenumber`;;\n \tline number prefix (when using `-n`)\n+`columnnumber`;;\n+\tcolumn number prefix (when using `-m`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable `-m` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..dd90f74ded 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [-m | --column-number]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable `-m` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\n@@ -169,6 +172,10 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+-m::\n+--column-number::\n+\tPrefix the 1-indexed column number of the first match on non-context lines.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..faa65abab5 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL('m', \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..0cf654824d 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,28 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit -c grep.linenumber=false grep -m -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit -c grep.linenumber=false grep -n -m -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n-- \n2.17.0\n\n"},{"id":"345303","messageId":"20180421034543.GG24606@syl.local","threadId":"48339","inReplyTo":"cover.1524281843.git.me@ttaylorr.com","subject":"[PATCH 6/6] contrib/git-jump/git-jump: use column number when grep-ing","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-21T03:45:43Z","receivedAt":"2018-04-21T03:45:50Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"This patch adds the '--column-number' synonym '-m' to the default\ngrep command so that callers are brought to the correct line _and_\ncolumn of each matched location.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/git-jump | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..2706963690 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n -m\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"345305","messageId":"xmqq8t9hb3sm.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180421034540.GF24606@syl.local","subject":"Re: [PATCH 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-21T04:07:37Z","receivedAt":"2018-04-21T04:07:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n> ...\n> +`columnnumber`;;\n> +\tcolumn number prefix (when using `-m`)\n\nIs there other people's tool (preferrably some variant of \"grep\")\nthat has an option to tell it to show the column number of the hit?\nWhat is the option called there?  Does that tool let the option\nsquat on short-and-sweet '-m'?\n\nThanks.\n"},{"id":"345306","messageId":"xmqq4lk5b3ht.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"xmqq8t9hb3sm.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-21T04:14:06Z","receivedAt":"2018-04-21T04:14:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n>> This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n>> ...\n>> +`columnnumber`;;\n>> +\tcolumn number prefix (when using `-m`)\n>\n> Is there other people's tool (preferrably some variant of \"grep\")\n> that has an option to tell it to show the column number of the hit?\n> What is the option called there?  Does that tool let the option\n> squat on short-and-sweet '-m'?\n>\n> Thanks.\n\nI still do not know if we have a good existing model system to take\nthe longer optoin name from, but at least, GNU grep seems to use -m\nto mean a completely different thing, so I'd think that we would not\nassign '-m' to this new feature.\n\n"},{"id":"345308","messageId":"cef29224-718f-21e9-0242-8bcd8e9c20a6@web.de","threadId":"48339","inReplyTo":"xmqq4lk5b3ht.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-04-21T05:36:35Z","receivedAt":"2018-04-21T05:37:29Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 21.04.2018 um 06:14 schrieb Junio C Hamano:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> Taylor Blau <me@ttaylorr.com> writes:\n>>\n>>> This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n>>> ...\n>>> +`columnnumber`;;\n>>> +\tcolumn number prefix (when using `-m`)\n>>\n>> Is there other people's tool (preferrably some variant of \"grep\")\n>> that has an option to tell it to show the column number of the hit?\n>> What is the option called there?  Does that tool let the option\n>> squat on short-and-sweet '-m'?\n>>\n>> Thanks.\n> \n> I still do not know if we have a good existing model system to take\n> the longer optoin name from, but at least, GNU grep seems to use -m\n> to mean a completely different thing, so I'd think that we would not\n> assign '-m' to this new feature.\n\nhttps://beyondgrep.com/feature-comparison/ is a good resource for such\nconsiderations.\n\nack and ripgrep use --column and no short option.  If git grep got\n--column-number, then users could abbreviate it to --column (until it\ngets some other option that makes it ambiguous).\n\n-m seems to be used for --max-count across the board (\"Stop searching\nin each file after NUM matches\") .\n\nRené\n"},{"id":"345324","messageId":"CAN0heSoa2CLNF7vdsmfkc2rbz2XhM_77XnuK9=5wf4LAnmX=Ww@mail.gmail.com","threadId":"48339","inReplyTo":"20180421034535.GD24606@syl.local","subject":"Re: [PATCH 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-04-21T08:32:06Z","receivedAt":"2018-04-21T08:32:11Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 21 April 2018 at 05:45, Taylor Blau <me@ttaylorr.com> wrote:\n> diff --git a/grep.c b/grep.c\n> index 29bc799ecf..7872a5d868 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -95,6 +95,10 @@ int grep_config(const char *var, const char *value, void *cb)\n>                 opt->linenum = git_config_bool(var, value);\n>                 return 0;\n>         }\n> +       if (!strcmp(var, \"grep.columnnumber\")) {\n> +               opt->columnnum = git_config_bool(var, value);\n> +               return 0;\n> +       }\n>\n>         if (!strcmp(var, \"grep.fullname\")) {\n>                 opt->relative = !git_config_bool(var, value);\n> @@ -111,6 +115,8 @@ int grep_config(const char *var, const char *value, void *cb)\n>                 color = opt->color_function;\n>         else if (!strcmp(var, \"color.grep.linenumber\"))\n>                 color = opt->color_lineno;\n> +       else if (!strcmp(var, \"color.grep.columnumber\"))\n> +               color = opt->color_columnno;\n\nmissing 'n' (s/umnum/umnnum/). Those characters are almost perfectly\ndesigned for hiding precisely this mistake. ;-)\n"},{"id":"345325","messageId":"CAN0heSp_bGqKF26g4TDOw6WpsvR2cEW6EqF3aJtKCv5POU_HmQ@mail.gmail.com","threadId":"48339","inReplyTo":"20180421034540.GF24606@syl.local","subject":"Re: [PATCH 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-04-21T08:39:17Z","receivedAt":"2018-04-21T08:39:23Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 21 April 2018 at 05:45, Taylor Blau <me@ttaylorr.com> wrote:\n> This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n> option builds upon previous commits to show the column number of the\n> first match on a non-context line.\n>\n> For example:\n>\n>   $ git grep -mn example | head -n3\n>   .clang-format:51:14:# myFunction(foo, bar, baz);\n>   .clang-format:64:7:# int foo();\n>   .clang-format:75:8:# void foo()\n\n\"example\" vs \"foo\" :-)\n\n> Now that configuration variables such as grep.columnNumber and\n> color.grep.columnNumber have a visible effect, we document them in this\n> patch as well.\n>\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n\nOne thing I've noted is that your messages are light on the imperative\n\"do this\", preferring \"this commit does\" or \"we do\". That said, I found\nmyself following along quite well in what they're saying.\n\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -1159,6 +1159,8 @@ color.grep.<slot>::\n>         function name lines (when using `-p`)\n>  `linenumber`;;\n>         line number prefix (when using `-n`)\n> +`columnnumber`;;\n> +       column number prefix (when using `-m`)\n>  `match`;;\n>         matching text (same as setting `matchContext` and `matchSelected`)\n>  `matchContext`;;\n> @@ -1708,6 +1710,9 @@ gitweb.snapshot::\n>  grep.lineNumber::\n>         If set to true, enable `-n` option by default.\n>\n> +grep.columnNumber::\n> +       If set to true, enable `-m` option by default.\n> +\n>  grep.patternType::\n>         Set the default matching behavior. Using a value of 'basic', 'extended',\n>         'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\n\nYou're doing what the immediate neighbours are doing, but the end result\nis a bit inconsistent: columnnumber vs columnNumber. I think the ideal\nend-game is columnNumber, lineNumber, and so on.\n\nMaybe use \"columnNumber\" consistently since you're introducing it and\nwant it to be perfect from the start ;-) and if that leaves \"linenumber\"\nlooking too inconsistent, then change it while at it? (I'm not suggesting\nchanging all foobar to fooBar while at it...)\n\nMartin\n"},{"id":"345412","messageId":"cover.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"20180421034530.GB24606@syl.local","subject":"[PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:20Z","receivedAt":"2018-04-22T20:47:28Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi,\n\nAttached is a re-roll of the series to add --column-number to\n'git-grep(1)'.\n\nSince last time, I have changed the following (an inter-diff is\navailable below for easier consumption):\n\n  * Removed '-m' as an alias for '--column-number', per René's\n    suggestion [1].\n\n  * Fix some incorrect spelling of 'columnnumber'.\n\n  * Change casing of 'color.grep.linenumber' to 'color.grep.lineNumber'\n    to be consistent with 'color.grep.columnNumber'. This is an\n    unrelated change, and one which I am happy to drop from this series.\n    It was suggested by Martin in [2].\n\nThanks in advance for your second round of review :-).\n\n\nThanks,\nTaylor\n\n[1]: https://public-inbox.org/git/cef29224-718f-21e9-0242-8bcd8e9c20a6@web.de/\n[2]: https://public-inbox.org/git/CAN0heSp_bGqKF26g4TDOw6WpsvR2cEW6EqF3aJtKCv5POU_HmQ@mail.gmail.com/\n\nTaylor Blau (6):\n  grep.c: take regmatch_t as argument in match_line()\n  grep.c: take column number as argument to show_line()\n  grep.[ch]: teach columnnum, color_columnno to grep_opt\n  grep.c: display column number of first match\n  builtin/grep.c: show column numbers via --column-number\n  contrib/git-jump/git-jump: use column number when grep-ing\n\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt |  8 +++++++-\n builtin/grep.c             |  1 +\n contrib/git-jump/git-jump  |  2 +-\n grep.c                     | 33 ++++++++++++++++++++++++---------\n grep.h                     |  2 ++\n t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n 7 files changed, 63 insertions(+), 12 deletions(-)\n\nInter-diff (since v1):\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 02fd4b662b..1645fcf2ae 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,10 +1157,10 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n-`columnnumber`;;\n-\tcolumn number prefix (when using `-m`)\n+`columnNumber`;;\n+\tcolumn number prefix (when using `--column-number`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex dd90f74ded..b75a039768 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number] [-m | --column-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column-number]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -172,7 +172,6 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n\n--m::\n --column-number::\n \tPrefix the 1-indexed column number of the first match on non-context lines.\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex faa65abab5..23ce97f998 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,7 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n-\t\tOPT_BOOL('m', \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n+\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/grep.c b/grep.c\nindex 5aeb893263..23250e60d0 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -115,7 +115,7 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n-\telse if (!strcmp(var, \"color.grep.columnumber\"))\n+\telse if (!strcmp(var, \"color.grep.columnnumber\"))\n \t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 0cf654824d..7349c7fadc 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -106,7 +106,7 @@ do\n \t\t\techo ${HC}file:5:foo mmap bar_mmap\n \t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n \t\t} >expected &&\n-\t\tgit -c grep.linenumber=false grep -m -w -e mmap $H >actual &&\n+\t\tgit grep --column-number -w -e mmap $H >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n@@ -117,7 +117,7 @@ do\n \t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n \t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n \t\t} >expected &&\n-\t\tgit -c grep.linenumber=false grep -n -m -w -e mmap $H >actual &&\n+\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n--\n2.17.0\n"},{"id":"345413","messageId":"73eb315b1f9daa518405c3ab1b28087c38f27ce5.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 1/6] grep.c: take regmatch_t as argument in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:24Z","receivedAt":"2018-04-22T20:47:33Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"In a subsequent patch, we teach show_line() to optionally include the\ncolumn number of the first match on each matched line.\n\nThe regmatch_t involved in match_line() and match_one_pattern() both\ncontain this information (via regmatch_t->rm_so), but their current\nimplementation throws this stack variable away at the end of the call.\n\nInstead, let's teach match_line() to take in a 'regmatch_t *' so that\ncallers can inspect the result of their calls. This will prove useful in\na subsequent commit when a caller will forward on information from the\nregmatch_t into show_line (as described above).\n\nThe return condition remains unchanged, therefore the only change\nrequired of callers is the addition of a single argument.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"345414","messageId":"5aaf7bebb27d385ea090cb83e97c596983ebae47.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:27Z","receivedAt":"2018-04-22T20:47:35Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"show_line() currently receives the line number within the\n'grep_opt->buf' in order to determine which line number to display. In\norder to display information about the matching column number--if\nrequested--we must additionally take in that information.\n\nTo do so, we extend the signature of show_line() to take in an\nadditional unsigned \"cno\". \"cno\" is either:\n\n  * A 1-indexed column number of the first match on the given line, or\n  * 0, if the column number is irrelevant (when displaying a function\n    name, context lines, etc).\n\nWe additionally modify all calls to show_line() in order to pass the new\nrequired argument.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..29bc799ecf 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1361,7 +1361,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1501,7 +1501,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1566,7 +1566,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1830,7 +1830,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1859,7 +1859,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"345415","messageId":"47f06ae36ce6af48fca06b140bdb5af2582116e1.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:30Z","receivedAt":"2018-04-22T20:47:38Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"In preparation of adding --column-number to 'git-grep(1)', we extend\ngrep_opt to take in the requisite new members.\n\nWe additionally teach the 'grep.columnnumber' and\n'color.grep.columnnumber' configuration variables to configure showing\nand coloring the column number, respectively. (These options remain\nundocumented until 'git-grep(1)' learns the --column option in a\nforthcoming commit.)\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 8 ++++++++\n grep.h | 2 ++\n 2 files changed, 10 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 29bc799ecf..922ab92eff 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -95,6 +95,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.columnnumber\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -111,6 +115,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.columnnumber\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n@@ -155,6 +161,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +171,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"345416","messageId":"4531659687de87b1bc143cb5cb364b691a58c6c9.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 4/6] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:33Z","receivedAt":"2018-04-22T20:47:41Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Building upon our work in the previous commit to add members 'columnnum'\nand 'color_columno' to 'grep_opt', we teach show_line() how to respect\nthose options.\n\nWhen requested, show_line() will display the column number of the first\nmatch on a non-context line. show_line() differentiates between context\nand non-context lines through the '&& cno' check. 'cno' will be equal to\nzero if and only if show_line() is invoked on a context line. It will be\na non-zero value otherwise.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 922ab92eff..23250e60d0 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1404,6 +1404,12 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n-- \n2.17.0\n\n"},{"id":"345417","messageId":"6dd73ad84cad5a749bf05c500295955970577e04.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:36Z","receivedAt":"2018-04-22T20:47:44Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"This commit teaches 'git-grep(1)' a new option, '--column-number'. This\noption builds upon previous commits to show the column number of the\nfirst match on a non-context line.\n\nFor example:\n\n  $ ./git-grep -n --column-number foo | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nNow that configuration variables such as grep.columnNumber and\ncolor.grep.columnNumber have a visible effect, we document them in this\npatch as well.\n\nWhile we're at it, change color.grep.linenumber to color.grep.lineNumber\nto match the casing of nearby variables.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt |  8 +++++++-\n builtin/grep.c             |  1 +\n t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n 4 files changed, 36 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..1645fcf2ae 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,8 +1157,10 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n+`columnNumber`;;\n+\tcolumn number prefix (when using `--column-number`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable `-m` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..b75a039768 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column-number]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable `-m` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\n@@ -169,6 +172,9 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+--column-number::\n+\tPrefix the 1-indexed column number of the first match on non-context lines.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..23ce97f998 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..7349c7fadc 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,28 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column-number -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n-- \n2.17.0\n\n"},{"id":"345418","messageId":"b9d2578d8dc644e68a09445e14156d789bfe395b.1524429778.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"[PATCH v2 6/6] contrib/git-jump/git-jump: use column number when grep-ing","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T20:47:38Z","receivedAt":"2018-04-22T20:47:47Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"This patch adds the '--column-number' synonym '-m' to the default\ngrep command so that callers are brought to the correct line _and_\ncolumn of each matched location.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/git-jump | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..2706963690 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n -m\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"345420","messageId":"87a7tuex47.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"47f06ae36ce6af48fca06b140bdb5af2582116e1.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-22T21:42:48Z","receivedAt":"2018-04-22T21:44:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Apr 22 2018, Taylor Blau wrote:\n\nI think [345]/6 would make much more sense as just one patch. Comments\non them to follow...\n\n> In preparation of adding --column-number to 'git-grep(1)', we extend\n> grep_opt to take in the requisite new members.\n\nJust a nit: Makes sense to refer to these camel-cased in docs & commit\nmessages.\n\n> diff --git a/grep.c b/grep.c\n> [...]\n\nAll of the boilerplate looks fine.\n"},{"id":"345421","messageId":"878t9eewu2.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"6dd73ad84cad5a749bf05c500295955970577e04.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-22T21:48:53Z","receivedAt":"2018-04-22T21:48:59Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Apr 22 2018, Taylor Blau wrote:\n\nI think this part though...\n\n> While we're at it, change color.grep.linenumber to color.grep.lineNumber\n> to match the casing of nearby variables.\n> [...]\n> -`linenumber`;;\n> +`lineNumber`;;\n\nMakes sense as its own patch at the beginning of the series, since it's\njust related cleanup.\n\n> +`columnNumber`;;\n> +\tcolumn number prefix (when using `--column-number`)\n\nHere you're using --column-number...\n\n> +grep.columnNumber::\n> +\tIf set to true, enable `-m` option by default.\n\n...But not here. This needs to be updated\n\n> +grep.columnNumber::\n> +\tIf set to true, enable `-m` option by default.\n> +\n\n...ditto.\n\n> +--column-number::\n> +\tPrefix the 1-indexed column number of the first match on non-context lines.\n> +\n> [...]\n>  \t\tOPT_GROUP(\"\"),\n>  \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> +\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n\nMaybe \"show first matching column\"? I.e. the main docs say \"just shows\nthe first\", but this seems to give a different impression.\n\nIt would also be nice if the docs briefly explained what this is for,\ni.e. the git-jump use-case.\n"},{"id":"345422","messageId":"877eoyewss.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"b9d2578d8dc644e68a09445e14156d789bfe395b.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 6/6] contrib/git-jump/git-jump: use column number when grep-ing","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-22T21:49:39Z","receivedAt":"2018-04-22T21:49:44Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Apr 22 2018, Taylor Blau wrote:\n\n> This patch adds the '--column-number' synonym '-m' to the default\n> grep command so that callers are brought to the correct line _and_\n> column of each matched location.\n> [...]\n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index 80ab0590bc..2706963690 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -52,7 +52,7 @@ mode_merge() {\n>  # editor shows them to us in the status bar.\n>  mode_grep() {\n>  \tcmd=$(git config jump.grepCmd)\n> -\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n> +\ttest -n \"$cmd\" || cmd=\"git grep -n -m\"\n>  \t$cmd \"$@\" |\n>  \tperl -pe '\n>  \ts/[ \\t]+/ /g;\n\nSo this re-roll doesn't have the alias -m anymore, but this makes use of\nit. Seems you just forgot to update this from v1, unless I'm missing\nsomething while skimming this...\n"},{"id":"345423","messageId":"CAPig+cRfCZQ8aPvc6AVoojtpuiWgNS_9A+9m5mV2mOC1BwemQQ@mail.gmail.com","threadId":"48339","inReplyTo":"73eb315b1f9daa518405c3ab1b28087c38f27ce5.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 1/6] grep.c: take regmatch_t as argument in match_line()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-22T23:14:58Z","receivedAt":"2018-04-22T23:15:04Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> In a subsequent patch, we teach show_line() to optionally include the\n> column number of the first match on each matched line.\n>\n> The regmatch_t involved in match_line() and match_one_pattern() both\n> contain this information (via regmatch_t->rm_so), but their current\n> implementation throws this stack variable away at the end of the call.\n>\n> Instead, let's teach match_line() to take in a 'regmatch_t *' so that\n> callers can inspect the result of their calls. This will prove useful in\n> a subsequent commit when a caller will forward on information from the\n> regmatch_t into show_line (as described above).\n>\n> The return condition remains unchanged, therefore the only change\n> required of callers is the addition of a single argument.\n\nIs 'rm_so' the only piece of information which callers will ever want\nto extract from 'regmatch_t'? If so, this patch's approach might be\noverly broad, unnecessarily exposing too much of match_lines()'s\ninternal implementation. An alternative would be to narrow the\ninterface and limit exposure by passing in an 'int *matched_col' or\nsome such.\n\n(Not necessarily a big deal, but something to consider.)\n\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n> diff --git a/grep.c b/grep.c\n> @@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n>  static int match_line(struct grep_opt *opt, char *bol, char *eol,\n> -                     enum grep_context ctx, int collect_hits)\n> +                     regmatch_t *match, enum grep_context ctx,\n> +                     int collect_hits)\n>  {\n>         struct grep_pat *p;\n> -       regmatch_t match;\n>\n>         if (opt->extended)\n>                 return match_expr(opt, bol, eol, ctx, collect_hits);\n\nThe new 'match' argument has no impact in the 'opt->extended' case.\nPerhaps this deserves calling out in the commit message.\n\n>         /* we do not call with collect_hits without being extended */\n>         for (p = opt->pattern_list; p; p = p->next) {\n> -               if (match_one_pattern(p, bol, eol, ctx, &match, 0))\n> +               if (match_one_pattern(p, bol, eol, ctx, match, 0))\n>                         return 1;\n>         }\n>         return 0;\n"},{"id":"345424","messageId":"20180422232447.GA48072@syl.local","threadId":"48339","inReplyTo":"87a7tuex47.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T23:24:47Z","receivedAt":"2018-04-22T23:24:54Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 11:42:48PM +0200, Ævar Arnfjörð Bjarmason wrote:\n> On Sun, Apr 22 2018, Taylor Blau wrote:\n>\n> > In preparation of adding --column-number to 'git-grep(1)', we extend\n> > grep_opt to take in the requisite new members.\n>\n> Just a nit: Makes sense to refer to these camel-cased in docs & commit\n> messages.\n\nCould you clarify which? I am not sure if you mean --column-number,\n'git-grep(1)', or grep_opt.\n\n\nThanks,\nTaylor\n"},{"id":"345425","messageId":"20180422232637.GB48072@syl.local","threadId":"48339","inReplyTo":"878t9eewu2.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T23:26:37Z","receivedAt":"2018-04-22T23:26:42Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 11:48:53PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Sun, Apr 22 2018, Taylor Blau wrote:\n>\n> I think this part though...\n>\n> > While we're at it, change color.grep.linenumber to color.grep.lineNumber\n> > to match the casing of nearby variables.\n> > [...]\n> > -`linenumber`;;\n> > +`lineNumber`;;\n>\n> Makes sense as its own patch at the beginning of the series, since it's\n> just related cleanup.\n\nThanks, I have adjusted this change in my copy and will attach it in a\nsubsequent re-roll.\n\n> > +`columnNumber`;;\n> > +\tcolumn number prefix (when using `--column-number`)\n>\n> Here you're using --column-number...\n>\n> > +grep.columnNumber::\n> > +\tIf set to true, enable `-m` option by default.\n>\n> ...But not here. This needs to be updated\n>\n> > +grep.columnNumber::\n> > +\tIf set to true, enable `-m` option by default.\n> > +\n>\n> ...ditto.\n\nFixed all of these, thanks for pointing them out :-).\n\n> > +--column-number::\n> > +\tPrefix the 1-indexed column number of the first match on non-context lines.\n> > +\n> > [...]\n> >  \t\tOPT_GROUP(\"\"),\n> >  \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> > +\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n>\n> Maybe \"show first matching column\"? I.e. the main docs say \"just shows\n> the first\", but this seems to give a different impression.\n\nI settled on \"show column number of first match\", and have noted its use\nfor callers like git-jump in the documentation.\n\nThanks,\nTaylor\n"},{"id":"345426","messageId":"20180422232704.GC48072@syl.local","threadId":"48339","inReplyTo":"877eoyewss.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 6/6] contrib/git-jump/git-jump: use column number when grep-ing","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T23:27:04Z","receivedAt":"2018-04-22T23:27:09Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 11:49:39PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Sun, Apr 22 2018, Taylor Blau wrote:\n>\n> > This patch adds the '--column-number' synonym '-m' to the default\n> > grep command so that callers are brought to the correct line _and_\n> > column of each matched location.\n> > [...]\n> > diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> > index 80ab0590bc..2706963690 100755\n> > --- a/contrib/git-jump/git-jump\n> > +++ b/contrib/git-jump/git-jump\n> > @@ -52,7 +52,7 @@ mode_merge() {\n> >  # editor shows them to us in the status bar.\n> >  mode_grep() {\n> >  \tcmd=$(git config jump.grepCmd)\n> > -\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n> > +\ttest -n \"$cmd\" || cmd=\"git grep -n -m\"\n> >  \t$cmd \"$@\" |\n> >  \tperl -pe '\n> >  \ts/[ \\t]+/ /g;\n>\n> So this re-roll doesn't have the alias -m anymore, but this makes use of\n> it. Seems you just forgot to update this from v1, unless I'm missing\n> something while skimming this...\n\nAck; another good catch. I have updated this in my copy and will include\nit in v3.\n\nThanks,\nTaylor\n"},{"id":"345427","messageId":"xmqqsh7makj5.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"cover.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-22T23:28:14Z","receivedAt":"2018-04-22T23:28:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n>   * Removed '-m' as an alias for '--column-number', per René's\n>     suggestion [1].\n>\n>   * Fix some incorrect spelling of 'columnnumber'.\n>\n>   * Change casing of 'color.grep.linenumber' to 'color.grep.lineNumber'\n>     to be consistent with 'color.grep.columnNumber'. This is an\n>     unrelated change, and one which I am happy to drop from this series.\n>     It was suggested by Martin in [2].\n\nAll sounds like good updates.\n\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> index 0cf654824d..7349c7fadc 100755\n> --- a/t/t7810-grep.sh\n> +++ b/t/t7810-grep.sh\n> @@ -106,7 +106,7 @@ do\n>  \t\t\techo ${HC}file:5:foo mmap bar_mmap\n>  \t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n>  \t\t} >expected &&\n> -\t\tgit -c grep.linenumber=false grep -m -w -e mmap $H >actual &&\n> +\t\tgit grep --column-number -w -e mmap $H >actual &&\n>  \t\ttest_cmp expected actual\n>  \t'\n>\n> @@ -117,7 +117,7 @@ do\n>  \t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n>  \t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n>  \t\t} >expected &&\n> -\t\tgit -c grep.linenumber=false grep -n -m -w -e mmap $H >actual &&\n> +\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n>  \t\ttest_cmp expected actual\n>  \t'\n\nIt seems that these two used to be \"even when it is configured not\nto show linenumber, with -n it is shown and without -n it is not,\nwhen the new --column-number feature forces the command to show the\n\"filename plus colon plus location info plus coon\" header.  I'm\nguessing that the reason why these got changed this round is because\nthe old way was found too defensive (perhaps nobody sets\ngrep.linenumber in .git/config in the tests that come before these)?\n\n"},{"id":"345428","messageId":"20180422233050.GD48072@syl.local","threadId":"48339","inReplyTo":"CAPig+cRfCZQ8aPvc6AVoojtpuiWgNS_9A+9m5mV2mOC1BwemQQ@mail.gmail.com","subject":"Re: [PATCH v2 1/6] grep.c: take regmatch_t as argument in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T23:30:50Z","receivedAt":"2018-04-22T23:30:55Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 07:14:58PM -0400, Eric Sunshine wrote:\n> On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> > In a subsequent patch, we teach show_line() to optionally include the\n> > column number of the first match on each matched line.\n> >\n> > The regmatch_t involved in match_line() and match_one_pattern() both\n> > contain this information (via regmatch_t->rm_so), but their current\n> > implementation throws this stack variable away at the end of the call.\n> >\n> > Instead, let's teach match_line() to take in a 'regmatch_t *' so that\n> > callers can inspect the result of their calls. This will prove useful in\n> > a subsequent commit when a caller will forward on information from the\n> > regmatch_t into show_line (as described above).\n> >\n> > The return condition remains unchanged, therefore the only change\n> > required of callers is the addition of a single argument.\n>\n> Is 'rm_so' the only piece of information which callers will ever want\n> to extract from 'regmatch_t'? If so, this patch's approach might be\n> overly broad, unnecessarily exposing too much of match_lines()'s\n> internal implementation. An alternative would be to narrow the\n> interface and limit exposure by passing in an 'int *matched_col' or\n> some such.\n>\n> (Not necessarily a big deal, but something to consider.)\n\nThanks; I do not think that this is overly broad, although I suppose\nthat it does bind us to the implementation of regmatch_t. The definition\nof regmatch_t, however, is fairly minimal:\n\n\ttypedef struct\n\t{\n\t\tregoff_t rm_so;  /* Byte offset from string's start to substring's start.  */\n\t\tregoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */\n\t} regmatch_t;\n\nI can imagine that other callers would be interested in the other piece\nof information, 'rm_eo', as well. Therefore, I think it makes sense to\nprovide access to it along with 'rm_so'.\n\nI think that if we are concerned with being bound to regmatch_t, then we\ncould typedef a new struct that contains a 'start' and 'end' unsigned,\nbut I think that this extra effort would not be fruitful, since the\nmajority of grep.c assumes regmatch_t (and friends).\n\n> > Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> > ---\n> > diff --git a/grep.c b/grep.c\n> > @@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n> >  static int match_line(struct grep_opt *opt, char *bol, char *eol,\n> > -                     enum grep_context ctx, int collect_hits)\n> > +                     regmatch_t *match, enum grep_context ctx,\n> > +                     int collect_hits)\n> >  {\n> >         struct grep_pat *p;\n> > -       regmatch_t match;\n> >\n> >         if (opt->extended)\n> >                 return match_expr(opt, bol, eol, ctx, collect_hits);\n>\n> The new 'match' argument has no impact in the 'opt->extended' case.\n> Perhaps this deserves calling out in the commit message.\n\nI have noted this in the commit message, which I'll include in the next\nre-roll.\n\nThanks,\nTaylor\n"},{"id":"345430","messageId":"20180422233403.GE48072@syl.local","threadId":"48339","inReplyTo":"xmqqsh7makj5.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-22T23:34:03Z","receivedAt":"2018-04-22T23:34:09Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Apr 23, 2018 at 08:28:14AM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> > index 0cf654824d..7349c7fadc 100755\n> > --- a/t/t7810-grep.sh\n> > +++ b/t/t7810-grep.sh\n> > @@ -106,7 +106,7 @@ do\n> >  \t\t\techo ${HC}file:5:foo mmap bar_mmap\n> >  \t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n> >  \t\t} >expected &&\n> > -\t\tgit -c grep.linenumber=false grep -m -w -e mmap $H >actual &&\n> > +\t\tgit grep --column-number -w -e mmap $H >actual &&\n> >  \t\ttest_cmp expected actual\n> >  \t'\n> >\n> > @@ -117,7 +117,7 @@ do\n> >  \t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n> >  \t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n> >  \t\t} >expected &&\n> > -\t\tgit -c grep.linenumber=false grep -n -m -w -e mmap $H >actual &&\n> > +\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n> >  \t\ttest_cmp expected actual\n> >  \t'\n>\n> It seems that these two used to be \"even when it is configured not\n> to show linenumber, with -n it is shown and without -n it is not,\n> when the new --column-number feature forces the command to show the\n> \"filename plus colon plus location info plus coon\" header.  I'm\n> guessing that the reason why these got changed this round is because\n> the old way was found too defensive (perhaps nobody sets\n> grep.linenumber in .git/config in the tests that come before these)?\n\nSort of. My aim with these new tests is to ensure that git-grep(1) works\nwith:\n\n  - '--line-number'\n  - '--column-number'\n  - '--line-number' and '--column-number' together\n\nIt seemed unrelated to be testing the various permutations of\ngrep.linenumber and --line-number along with the above three so I\nremoved these in order to focus only on the above three.\n\nDo you think that it is worth testing --column-number with and without\ngrep.columnnumber as above?\n\n\nThanks,\nTaylor\n"},{"id":"345432","messageId":"CAPig+cQ2+wTTXE0mhnGnp2pZug=Po0SCVwCO_2agxUDaOsFRLw@mail.gmail.com","threadId":"48339","inReplyTo":"5aaf7bebb27d385ea090cb83e97c596983ebae47.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T00:16:12Z","receivedAt":"2018-04-23T00:16:17Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> show_line() currently receives the line number within the\n> 'grep_opt->buf' in order to determine which line number to display. In\n> order to display information about the matching column number--if\n> requested--we must additionally take in that information.\n>\n> To do so, we extend the signature of show_line() to take in an\n> additional unsigned \"cno\". \"cno\" is either:\n>\n>   * A 1-indexed column number of the first match on the given line, or\n>   * 0, if the column number is irrelevant (when displaying a function\n>     name, context lines, etc).\n\nThis information about how 'cno' is interpreted seems important enough\nto have as an in-code comment somewhere. Unfortunately, this patch\nnever actually uses 'cno', so it's hard to add such a comment to\nnon-existent code. In fact, the granularity of this patch feels wrong;\nit seems to exist for some purpose but, at the same time, is a\ndo-nothing patch.\n\nThis issue illustrates a larger problem with how this patch series is\nstructured overall. In his review, Ævar suggested collapsing several\npatches into one, but the problems go deeper than that when you have\npatches which implement some bit of functionality but don't document\nthat functionality until some later step which exposes some other bit\nof functionality, and so forth. As a reviewer, I expect a patch series\nto hold my hand and lead me on a straightforward journey from building\nblocks to final product, but this series tends to jump around without\napparent logic.\n\nOne way to achieve a more coherent patch series would be to build the\nmachinery first and then expose it to the user in various ways. Also,\neach patch which implements some user-facing functionality should also\ndocument that functionality. For instance, a more understandable\nseries might be structured something like this:\n\n  1. grep: match_line: expose matched column\n  2. grep: extend grep_opt to allow showing matched column\n  3. grep: display column number of first match\n  4. builtin/grep: add --column-number option\n  5. grep: add configuration variables to show matched column\n  6. contrib/git-jump: jump to match column in addition to line\n\nThere may be fewer or more patches than shown here (I believe Ævar\nsuggested a cleanup patch), but this should give the general idea.\nPatches 4 and 5 might also be swapped if that seems more logical.\n\n(Sorry if any of the above sounds harsh; it's not meant to be, but is\nintended to be constructive.)\n\n> We additionally modify all calls to show_line() in order to pass the new\n> required argument.\n\nNit: No need to state the obvious; this final sentence could easily be dropped.\n\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n"},{"id":"345433","messageId":"CAPig+cQXsU4cXLtZPA-C84DH+PzrgN7C8_A-NZE+6e5HoJEFCA@mail.gmail.com","threadId":"48339","inReplyTo":"20180422232447.GA48072@syl.local","subject":"Re: [PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T00:21:33Z","receivedAt":"2018-04-23T00:21:37Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 7:24 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> On Sun, Apr 22, 2018 at 11:42:48PM +0200, Ęvar Arnfjörš Bjarmason wrote:\n>> On Sun, Apr 22 2018, Taylor Blau wrote:\n>> > In preparation of adding --column-number to 'git-grep(1)', we extend\n>> > grep_opt to take in the requisite new members.\n>>\n>> Just a nit: Makes sense to refer to these camel-cased in docs & commit\n>> messages.\n>\n> Could you clarify which? I am not sure if you mean --column-number,\n> 'git-grep(1)', or grep_opt.\n\nI think Ævar was referring to this bit from the commit message (which\nunfortunately got snipped in his review):\n\n    We additionally teach the 'grep.columnnumber' and\n    'color.grep.columnnumber' configuration variables to configure\n    showing and coloring the column number, respectively. (These\n    options remain undocumented until 'git-grep(1)' learns the\n    --column option in a forthcoming commit.)\n\nHe was suggesting camel-casing 'grep.columnNumber' and\n'color.grep.columNumber' even in the commit message.\n"},{"id":"345434","messageId":"CAPig+cR0unM2uKcapHyAFrvMyPx4VgsW4wDswb_GNwE4EcYb8Q@mail.gmail.com","threadId":"48339","inReplyTo":"4531659687de87b1bc143cb5cb364b691a58c6c9.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 4/6] grep.c: display column number of first match","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T00:24:55Z","receivedAt":"2018-04-23T00:24:59Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> Building upon our work in the previous commit to add members 'columnnum'\n> and 'color_columno' to 'grep_opt', we teach show_line() how to respect\n> those options.\n>\n> When requested, show_line() will display the column number of the first\n> match on a non-context line. show_line() differentiates between context\n> and non-context lines through the '&& cno' check. 'cno' will be equal to\n> zero if and only if show_line() is invoked on a context line. It will be\n> a non-zero value otherwise.\n\nThis interpretation of 'cno' seems important enough to deserve an\nin-code comment. (And, you may be able to drop some of the same\ninformation from the commit message if it merely duplicates the\nin-code comment.)\n\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n> diff --git a/grep.c b/grep.c\n> @@ -1404,6 +1404,12 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n> +       if (opt->columnnum && cno) {\n> +               char buf[32];\n> +               xsnprintf(buf, sizeof(buf), \"%d\", cno);\n> +               output_color(opt, buf, strlen(buf), opt->color_columnno);\n> +               output_sep(opt, sign);\n> +       }\n"},{"id":"345435","messageId":"CAPig+cTozduqSAxh+w4H85m7en72Yo09asdx+1KSTswqbnBr4w@mail.gmail.com","threadId":"48339","inReplyTo":"6dd73ad84cad5a749bf05c500295955970577e04.1524429778.git.me@ttaylorr.com","subject":"Re: [PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T00:32:28Z","receivedAt":"2018-04-23T00:32:33Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n> option builds upon previous commits to show the column number of the\n> first match on a non-context line.\n\nImperative mood (and dropping unnecessary \"builds upon previous\"):\n\n    Teach 'git-grep(1)' a new option '--column-number' which shows the\n    column number of the first match on a non-context line.\n\n> For example:\n>\n>   $ ./git-grep -n --column-number foo | head -n3\n>   .clang-format:51:14:# myFunction(foo, bar, baz);\n>   .clang-format:64:7:# int foo();\n>   .clang-format:75:8:# void foo()\n>\n> Now that configuration variables such as grep.columnNumber and\n> color.grep.columnNumber have a visible effect, we document them in this\n> patch as well.\n\nAs mentioned in my review of patch 2, document the configuration\nvariables in the patch which introduces them.\n\n> While we're at it, change color.grep.linenumber to color.grep.lineNumber\n> to match the casing of nearby variables.\n>\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> @@ -99,6 +99,28 @@ do\n> +       test_expect_success \"grep -w $L\" '\n> +               ...\n> +       '\n> +\n> +       test_expect_success \"grep -w $L\" '\n> +               ...\n> +       '\n> +\n>         test_expect_success \"grep -w $L\" '\n\nI realize that several existing tests in this script are already\nguilty of this sin, but please give each new test a distinct title\nreflective of what it is actually testing in order to make it easier\nto correlate failed test output with the actual test code.\n"},{"id":"345437","messageId":"20180423011135.GA78148@syl.local","threadId":"48339","inReplyTo":"CAPig+cQXsU4cXLtZPA-C84DH+PzrgN7C8_A-NZE+6e5HoJEFCA@mail.gmail.com","subject":"Re: [PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-23T01:11:35Z","receivedAt":"2018-04-23T01:11:41Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 08:21:33PM -0400, Eric Sunshine wrote:\n> On Sun, Apr 22, 2018 at 7:24 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> > On Sun, Apr 22, 2018 at 11:42:48PM +0200, Ęvar Arnfjörš Bjarmason wrote:\n> >> On Sun, Apr 22 2018, Taylor Blau wrote:\n> >> > In preparation of adding --column-number to 'git-grep(1)', we extend\n> >> > grep_opt to take in the requisite new members.\n> >>\n> >> Just a nit: Makes sense to refer to these camel-cased in docs & commit\n> >> messages.\n> >\n> > Could you clarify which? I am not sure if you mean --column-number,\n> > 'git-grep(1)', or grep_opt.\n>\n> I think Ævar was referring to this bit from the commit message (which\n> unfortunately got snipped in his review):\n>\n>     We additionally teach the 'grep.columnnumber' and\n>     'color.grep.columnnumber' configuration variables to configure\n>     showing and coloring the column number, respectively. (These\n>     options remain undocumented until 'git-grep(1)' learns the\n>     --column option in a forthcoming commit.)\n>\n> He was suggesting camel-casing 'grep.columnNumber' and\n> 'color.grep.columNumber' even in the commit message.\n\nThanks for the clarification, Eric. I have amended my copy of this\npatch to correctly case those variables.\n\nThanks,\nTaylor\n"},{"id":"345438","messageId":"20180423011244.GB78148@syl.local","threadId":"48339","inReplyTo":"CAPig+cR0unM2uKcapHyAFrvMyPx4VgsW4wDswb_GNwE4EcYb8Q@mail.gmail.com","subject":"Re: [PATCH v2 4/6] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-23T01:12:44Z","receivedAt":"2018-04-23T01:12:54Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 08:24:55PM -0400, Eric Sunshine wrote:\n> On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> > Building upon our work in the previous commit to add members 'columnnum'\n> > and 'color_columno' to 'grep_opt', we teach show_line() how to respect\n> > those options.\n> >\n> > When requested, show_line() will display the column number of the first\n> > match on a non-context line. show_line() differentiates between context\n> > and non-context lines through the '&& cno' check. 'cno' will be equal to\n> > zero if and only if show_line() is invoked on a context line. It will be\n> > a non-zero value otherwise.\n>\n> This interpretation of 'cno' seems important enough to deserve an\n> in-code comment. (And, you may be able to drop some of the same\n> information from the commit message if it merely duplicates the\n> in-code comment.)\n\nThanks, I agree that the interpretation of 'cno' is subtle and should\nnot require a 'git blame' to understand. I have adopted your proposed\ncommit structure [1] and moved this description from the patch message\ninto grep.c as a comment above the relevant conditional.\n\nThanks,\nTaylor\n"},{"id":"345439","messageId":"20180423011431.GC78148@syl.local","threadId":"48339","inReplyTo":"CAPig+cTozduqSAxh+w4H85m7en72Yo09asdx+1KSTswqbnBr4w@mail.gmail.com","subject":"Re: [PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-23T01:14:31Z","receivedAt":"2018-04-23T01:14:38Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 08:32:28PM -0400, Eric Sunshine wrote:\n> On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> > This commit teaches 'git-grep(1)' a new option, '--column-number'. This\n> > option builds upon previous commits to show the column number of the\n> > first match on a non-context line.\n>\n> Imperative mood (and dropping unnecessary \"builds upon previous\"):\n>\n>     Teach 'git-grep(1)' a new option '--column-number' which shows the\n>     column number of the first match on a non-context line.\n\nThanks. I am not used to writing in this mood, but have amended my\npatches locally to conform to your proposed layout and have reworded\neach to be in the imperative mood.\n\n> > For example:\n> >\n> >   $ ./git-grep -n --column-number foo | head -n3\n> >   .clang-format:51:14:# myFunction(foo, bar, baz);\n> >   .clang-format:64:7:# int foo();\n> >   .clang-format:75:8:# void foo()\n> >\n> > Now that configuration variables such as grep.columnNumber and\n> > color.grep.columnNumber have a visible effect, we document them in this\n> > patch as well.\n>\n> As mentioned in my review of patch 2, document the configuration\n> variables in the patch which introduces them.\n\nThanks again, I have moved this introduction to the relevant patch.\n\n> > While we're at it, change color.grep.linenumber to color.grep.lineNumber\n> > to match the casing of nearby variables.\n> >\n> > Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> > ---\n> > diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> > @@ -99,6 +99,28 @@ do\n> > +       test_expect_success \"grep -w $L\" '\n> > +               ...\n> > +       '\n> > +\n> > +       test_expect_success \"grep -w $L\" '\n> > +               ...\n> > +       '\n> > +\n> >         test_expect_success \"grep -w $L\" '\n>\n> I realize that several existing tests in this script are already\n> guilty of this sin, but please give each new test a distinct title\n> reflective of what it is actually testing in order to make it easier\n> to correlate failed test output with the actual test code.\n\n:-). I have changed this locally to indicate which is which in the hopes\nthat it will provide more clarity should these tests fail at any point.\n\n\nThanks,\nTaylor\n"},{"id":"345440","messageId":"20180423011726.GD78148@syl.local","threadId":"48339","inReplyTo":"CAPig+cQ2+wTTXE0mhnGnp2pZug=Po0SCVwCO_2agxUDaOsFRLw@mail.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-23T01:17:26Z","receivedAt":"2018-04-23T01:17:32Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Apr 22, 2018 at 08:16:12PM -0400, Eric Sunshine wrote:\n> On Sun, Apr 22, 2018 at 4:47 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> > show_line() currently receives the line number within the\n> > 'grep_opt->buf' in order to determine which line number to display. In\n> > order to display information about the matching column number--if\n> > requested--we must additionally take in that information.\n> >\n> > To do so, we extend the signature of show_line() to take in an\n> > additional unsigned \"cno\". \"cno\" is either:\n> >\n> >   * A 1-indexed column number of the first match on the given line, or\n> >   * 0, if the column number is irrelevant (when displaying a function\n> >     name, context lines, etc).\n>\n> This information about how 'cno' is interpreted seems important enough\n> to have as an in-code comment somewhere. Unfortunately, this patch\n> never actually uses 'cno', so it's hard to add such a comment to\n> non-existent code. In fact, the granularity of this patch feels wrong;\n> it seems to exist for some purpose but, at the same time, is a\n> do-nothing patch.\n>\n> This issue illustrates a larger problem with how this patch series is\n> structured overall. In his review, Ævar suggested collapsing several\n> patches into one, but the problems go deeper than that when you have\n> patches which implement some bit of functionality but don't document\n> that functionality until some later step which exposes some other bit\n> of functionality, and so forth. As a reviewer, I expect a patch series\n> to hold my hand and lead me on a straightforward journey from building\n> blocks to final product, but this series tends to jump around without\n> apparent logic.\n>\n> One way to achieve a more coherent patch series would be to build the\n> machinery first and then expose it to the user in various ways. Also,\n> each patch which implements some user-facing functionality should also\n> document that functionality. For instance, a more understandable\n> series might be structured something like this:\n>\n>   1. grep: match_line: expose matched column\n>   2. grep: extend grep_opt to allow showing matched column\n>   3. grep: display column number of first match\n>   4. builtin/grep: add --column-number option\n>   5. grep: add configuration variables to show matched column\n>   6. contrib/git-jump: jump to match column in addition to line\n>\n> There may be fewer or more patches than shown here (I believe Ævar\n> suggested a cleanup patch), but this should give the general idea.\n> Patches 4 and 5 might also be swapped if that seems more logical.\n>\n> (Sorry if any of the above sounds harsh; it's not meant to be, but is\n> intended to be constructive.)\n\nI appreciate the suggestion, and did not take it as harsh. I think that\nthe existing structure is OK, but I think that I am biased since I'm the\nauthor of the series. I have given your proposed structure a shot and I\nthink that it should improve the readability of this series for others\non the list as well.\n\nTo avoid sending more email than is necessary, I have pushed a draft of\nthis series to my copy of Git, and would greatly appreciate your\nfeedback on whether the structure of these patches is sensible. If they\nall seem OK to you, I'll happily push v3.\n\nFor your consideration: https://github.com/ttaylorr/git/compare/tb/grep-colno\n\n> > We additionally modify all calls to show_line() in order to pass the new\n> > required argument.\n>\n> Nit: No need to state the obvious; this final sentence could easily be dropped.\n\nFair; I have removed this from the patch.\n\n\nThanks,\nTaylor\n"},{"id":"345441","messageId":"CAPig+cR0dP2Hrb4JhuqmCNFzDPoy7KdqYX3irso6mKdmh9Y4VQ@mail.gmail.com","threadId":"48339","inReplyTo":"20180423011726.GD78148@syl.local","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T03:30:33Z","receivedAt":"2018-04-23T03:30:38Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Apr 22, 2018 at 9:17 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> On Sun, Apr 22, 2018 at 08:16:12PM -0400, Eric Sunshine wrote:\n>> One way to achieve a more coherent patch series would be to build the\n>> machinery first and then expose it to the user in various ways. Also,\n>> each patch which implements some user-facing functionality should also\n>> document that functionality. For instance, a more understandable\n>> series might be structured something like this:\n>>\n>>   1. grep: match_line: expose matched column\n>>   2. grep: extend grep_opt to allow showing matched column\n>>   3. grep: display column number of first match\n>>   4. builtin/grep: add --column-number option\n>>   5. grep: add configuration variables to show matched column\n>>   6. contrib/git-jump: jump to match column in addition to line\n>\n> I appreciate the suggestion, and did not take it as harsh. I think that\n> the existing structure is OK, but I think that I am biased since I'm the\n> author of the series. I have given your proposed structure a shot and I\n> think that it should improve the readability of this series for others\n> on the list as well.\n>\n> To avoid sending more email than is necessary, I have pushed a draft of\n> this series to my copy of Git, and would greatly appreciate your\n> feedback on whether the structure of these patches is sensible. If they\n> all seem OK to you, I'll happily push v3.\n>\n> For your consideration: https://github.com/ttaylorr/git/compare/tb/grep-colno\n\nThanks. Perhaps not surprisingly, I find the restructured patch series\neasier to follow and review. Each patch has a very specific purpose,\nthus demands lower review-time cognitive load than with the old\nstructure.\n\nOne important issue I noticed is that patch 3/7 neglects to update\ngrep.c:init_grep_defaults() to initialize opt.color_columnno.\n\nLooking at the tests again, are you gaining anything by placing them\ninside that for-loop? (Genuine question.)\n"},{"id":"345447","messageId":"87604ie61h.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"CAPig+cR0dP2Hrb4JhuqmCNFzDPoy7KdqYX3irso6mKdmh9Y4VQ@mail.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-23T07:27:38Z","receivedAt":"2018-04-23T07:27:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Apr 23 2018, Eric Sunshine wrote:\n\n> On Sun, Apr 22, 2018 at 9:17 PM, Taylor Blau <me@ttaylorr.com> wrote:\n> One important issue I noticed is that patch 3/7 neglects to update\n> grep.c:init_grep_defaults() to initialize opt.color_columnno.\n\nI think this is fine for fields that are 0 by default, since the struct\n is already zero'd out. See my e62ba43244 (\"grep: remove redundant\n double assignment to 0\", 2017-06-29) for some prior art.\n\n> Looking at the tests again, are you gaining anything by placing them\n> inside that for-loop? (Genuine question.)\n\nThe tests in that loop are just to stress-test grep with/without a\nworking tree. Even though we can see from the implementation that it's\nthe same in both cases here, I think it makes sense to add new stuff to\nthat loop by default to stress that case.\n"},{"id":"345448","messageId":"CAPig+cRXkSrPHPyEEhp6_ndRBNW3hE7HkspSk1atPSE5pn_sMw@mail.gmail.com","threadId":"48339","inReplyTo":"87604ie61h.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-23T07:34:21Z","receivedAt":"2018-04-23T07:34:26Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Apr 23, 2018 at 3:27 AM, Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> On Mon, Apr 23 2018, Eric Sunshine wrote:\n>> One important issue I noticed is that patch 3/7 neglects to update\n>> grep.c:init_grep_defaults() to initialize opt.color_columnno.\n>\n> I think this is fine for fields that are 0 by default, since the struct\n>  is already zero'd out. See my e62ba43244 (\"grep: remove redundant\n>  double assignment to 0\", 2017-06-29) for some prior art.\n\nIndeed, I wasn't worried about opt.columnnum, which is fine being\nzero'd out by the memset(). What I was concerned about was\nopt.color_columnno; the corresponding opt.color_lineno is handled\nexplicitly in init_grep_defaults():\n\n    color_set(opt->color_lineno, \"\");\n\nI'd expect opt.color_columnno to be treated likewise.\n"},{"id":"345449","messageId":"874lk2e4he.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"20180423011726.GD78148@syl.local","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-04-23T08:01:17Z","receivedAt":"2018-04-23T08:01:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Apr 23 2018, Taylor Blau wrote:\n\n> For your consideration: https://github.com/ttaylorr/git/compare/tb/grep-colno\n\nLooks good to me aside from two minor issues I noticed:\n\n * In \"grep.c: display column number of first match\" you use a comment\n   style we don't normally use, i.e. /**\\n not /*\\n. See \"Multi-line\n   comments\" in Documentation/CodingGuidelines.\n\n * You're not updating contrib/git-jump/README to document the new\n   output format. It just refers to the old format, but now depending on\n   if you use \"grep\" or not it'll use this new thing. It also makes\n   sense to update the example added in 007d06aa57 (\"contrib/git-jump:\n   allow to configure the grep command\", 2017-11-20) which seems to have\n   added jump.grepCmd as a workaround for not having this.\n\nBut also, after just looking at this the second time around; Is there a\nreason we shouldn't just call this --column, not --column-number? I\nrealize the former works because of the lazyness of our getopt parsing\n(also --colu though..).\n\nI think when we add features to git-grep we should be as close to GNU\ngrep as possible (e.g. not add this -m alias meaning something different\nas in your v1), but if GNU grep doesn't have something go with the trend\nof other grep tools, as noted at\nhttps://beyondgrep.com/feature-comparison/ (and I found another one that\nhas this: https://github.com/beyondgrep/website/pull/83), so there's\nalready 3 prominent grep tools that call this just --column.\n\nI think we should just go with that.\n\nAlso, as a bonus question, since you're poking at this column code\nanyway, interested in implementing -o (--only-matching)? That would be\nsuper-useful (see\nhttps://public-inbox.org/git/87in9ucsbb.fsf@evledraar.gmail.com/) :)\n"},{"id":"345462","messageId":"xmqq7eoy9gs9.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180422233403.GE48072@syl.local","subject":"Re: [PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-23T13:46:46Z","receivedAt":"2018-04-23T13:46:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n>> It seems that these two used to be \"even when it is configured not\n>> to show linenumber, with -n it is shown and without -n it is not,\n>> when the new --column-number feature forces the command to show the\n>> \"filename plus colon plus location info plus coon\" header.  I'm\n>> guessing that the reason why these got changed this round is because\n>> the old way was found too defensive (perhaps nobody sets\n>> grep.linenumber in .git/config in the tests that come before these)?\n> ...\n> Do you think that it is worth testing --column-number with and without\n> grep.columnnumber as above?\n\nI view the \"git -c var.val=foo cmd\" as a reasonable way to make sure\nthat the test is not affected by any stale state in .git/config left\nbehind by an earlier test that did \"git config var.val bar\" and then\nfailed to clean itself up, but I do not think it is all that\nintereseting to test the inter-changeability between config and\ncommand line option \"-n\" while checking its interaction with another\noption e.g. \"--column\".\n"},{"id":"345606","messageId":"20180424042739.GA82093@syl.local","threadId":"48339","inReplyTo":"CAPig+cRXkSrPHPyEEhp6_ndRBNW3hE7HkspSk1atPSE5pn_sMw@mail.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T04:27:39Z","receivedAt":"2018-04-24T04:27:46Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Apr 23, 2018 at 03:34:21AM -0400, Eric Sunshine wrote:\n> On Mon, Apr 23, 2018 at 3:27 AM, Ævar Arnfjörð Bjarmason\n> <avarab@gmail.com> wrote:\n> > On Mon, Apr 23 2018, Eric Sunshine wrote:\n> >> One important issue I noticed is that patch 3/7 neglects to update\n> >> grep.c:init_grep_defaults() to initialize opt.color_columnno.\n> >\n> > I think this is fine for fields that are 0 by default, since the struct\n> >  is already zero'd out. See my e62ba43244 (\"grep: remove redundant\n> >  double assignment to 0\", 2017-06-29) for some prior art.\n>\n> Indeed, I wasn't worried about opt.columnnum, which is fine being\n> zero'd out by the memset(). What I was concerned about was\n> opt.color_columnno; the corresponding opt.color_lineno is handled\n> explicitly in init_grep_defaults():\n>\n>     color_set(opt->color_lineno, \"\");\n>\n> I'd expect opt.color_columnno to be treated likewise.\n\nI agree with Ævar and Eric, we should certainly zero-out\nopt->color_lineno in grep.c's init_grep_defaults().\n\nI recall doing this in v1, but I think that I must have dropped this\npart of the patch on the floor. In either case, I have amended my local\ncopy to include this color_set() invocation and will include it in v3\n(which I hope to send later this evening).\n\n\nThanks,\nTaylor\n"},{"id":"345607","messageId":"20180424043140.GA82406@syl.local","threadId":"48339","inReplyTo":"874lk2e4he.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T04:31:40Z","receivedAt":"2018-04-24T04:31:46Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Apr 23, 2018 at 10:01:17AM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Mon, Apr 23 2018, Taylor Blau wrote:\n>\n> > For your consideration: https://github.com/ttaylorr/git/compare/tb/grep-colno\n>\n> Looks good to me aside from two minor issues I noticed:\n>\n>  * In \"grep.c: display column number of first match\" you use a comment\n>    style we don't normally use, i.e. /**\\n not /*\\n. See \"Multi-line\n>    comments\" in Documentation/CodingGuidelines.\n>\n>  * You're not updating contrib/git-jump/README to document the new\n>    output format. It just refers to the old format, but now depending on\n>    if you use \"grep\" or not it'll use this new thing. It also makes\n>    sense to update the example added in 007d06aa57 (\"contrib/git-jump:\n>    allow to configure the grep command\", 2017-11-20) which seems to have\n>    added jump.grepCmd as a workaround for not having this.\n>\n> But also, after just looking at this the second time around; Is there a\n> reason we shouldn't just call this --column, not --column-number? I\n> realize the former works because of the lazyness of our getopt parsing\n> (also --colu though..).\n>\n> I think when we add features to git-grep we should be as close to GNU\n> grep as possible (e.g. not add this -m alias meaning something different\n> as in your v1), but if GNU grep doesn't have something go with the trend\n> of other grep tools, as noted at\n> https://beyondgrep.com/feature-comparison/ (and I found another one that\n> has this: https://github.com/beyondgrep/website/pull/83), so there's\n> already 3 prominent grep tools that call this just --column.\n>\n> I think we should just go with that.\n\nI would be happy with either, though I think that my preference is to\nretain '--column-number', as introduced in v2. I think that given the\nchoice between (1) staying closer to our conventions (i.e.,\n'--line-number' instead of '--line') and (2) staying closer to other\ntools', I'd choose (1).\n\nThat said, I'll happily pick up whichever the majority prefers, so if\nthat's --column and not --column-number, that works OK for me. I believe\nthat the ultimate say should be up to Junio.\n\n> Also, as a bonus question, since you're poking at this column code\n> anyway, interested in implementing -o (--only-matching)? That would be\n> super-useful (see\n> https://public-inbox.org/git/87in9ucsbb.fsf@evledraar.gmail.com/) :)\n\nSure, thanks for pointing me in the right direction :-).\n\n\nThanks,\nTaylor\n"},{"id":"345609","messageId":"cover.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"20180421034530.GB24606@syl.local","subject":"[PATCH v3 0/7] Teach '--column-number' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:34Z","receivedAt":"2018-04-24T05:07:40Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi,\n\nAttached is v3 of my series to teach '--column-numbers' to 'git-grep(1)'.\n\nSince last time, I have:\n\n  * Removed '-m' in a few places that I forgot to during v2 [1] [2].\n\n  * Expanded upon the definition of '--column-number' in 'git grep\n    --help'. [3]\n\n  * Initialized some new fields in grep_opt to 0 that would be avoided\n    by memset(). [4]\n\n  * Block comment to indicate the desired use of 'cno' in grep.c's\n    'show_line()' [5], [6].\n\n  * Annotated the new tests with the permutation that they are testing.\n\nThe most notable change since last time is reorganizing the series to\nmatch Eric's suggestion, which I hope makes the reviewing experience a\nlittle easier. I will strive to apply these lessons in future series.\n\nLittle has changed on the implementation front since v2, so I think that\nthe most outstanding further discussion will be centered around --column\nvs --column-number. I have posted some thoughts about that in [7].\n\nThanks as always for your review :-).\n\n\nThanks,\nTaylor\n\n[1]: https://public-inbox.org/git/878t9eewu2.fsf@evledraar.gmail.com\n[2]: https://public-inbox.org/git/877eoyewss.fsf@evledraar.gmail.com\n[3]: https://public-inbox.org/git/878t9eewu2.fsf@evledraar.gmail.com\n[4]: https://public-inbox.org/git/CAPig+cRXkSrPHPyEEhp6_ndRBNW3hE7HkspSk1atPSE5pn_sMw@mail.gmail.com\n[5]: https://public-inbox.org/git/CAPig+cQ2+wTTXE0mhnGnp2pZug=Po0SCVwCO_2agxUDaOsFRLw@mail.gmail.com\n[6]: https://public-inbox.org/git/CAPig+cR0unM2uKcapHyAFrvMyPx4VgsW4wDswb_GNwE4EcYb8Q@mail.gmail.com\n[7]: https://public-inbox.org/git/20180424043140.GA82406@syl.local\n\nTaylor Blau (7):\n  Documentation/config.txt: camel-case lineNumber for consistency\n  grep.c: expose matched column in match_line()\n  grep.[ch]: extend grep_opt to allow showing matched column\n  grep.c: display column number of first match\n  builtin/grep.c: add '--column-number' option to 'git-grep(1)'\n  grep.c: add configuration variables to show matched option\n  contrib/git-jump/git-jump: jump to match column in addition to line\n\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt |  8 +++++++-\n builtin/grep.c             |  1 +\n contrib/git-jump/git-jump  |  2 +-\n grep.c                     | 39 +++++++++++++++++++++++++++++---------\n grep.h                     |  2 ++\n t/t7810-grep.sh            | 22 +++++++++++++++++++++\n 7 files changed, 69 insertions(+), 12 deletions(-)\n\nInter-diff (since v2):\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 1645fcf2ae..8a2893d1e1 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1711,7 +1711,7 @@ grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n\n grep.columnNumber::\n-\tIf set to true, enable `-m` option by default.\n+\tIf set to true, enable the `--column-number` option by default.\n\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex b75a039768..c5c4d712e6 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -45,7 +45,7 @@ grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n\n grep.columnNumber::\n-\tIf set to true, enable `-m` option by default.\n+\tIf set to true, enable the `--column-number` option by default.\n\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 23ce97f998..512f60c591 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,7 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n-\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column numbers\")),\n+\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 2706963690..8bc57ea0f8 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n -m\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column-number\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\ndiff --git a/grep.c b/grep.c\nindex 23250e60d0..7284dec155 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -46,6 +46,7 @@ void init_grep_defaults(void)\n \tcolor_set(opt->color_filename, \"\");\n \tcolor_set(opt->color_function, \"\");\n \tcolor_set(opt->color_lineno, \"\");\n+\tcolor_set(opt->color_columnno, \"\");\n \tcolor_set(opt->color_match_context, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_selected, \"\");\n@@ -1404,6 +1405,11 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\t/**\n+\t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n+\t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n+\t * being called with a context line.\n+\t */\n \tif (opt->columnnum && cno) {\n \t\tchar buf[32];\n \t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 7349c7fadc..bbce57c8b1 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,7 +99,7 @@ do\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep -w $L\" '\n+\ttest_expect_success \"grep -w $L (with --column-number)\" '\n \t\t{\n \t\t\techo ${HC}file:5:foo mmap bar\n \t\t\techo ${HC}file:14:foo_mmap bar mmap\n@@ -110,7 +110,7 @@ do\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep -w $L\" '\n+\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n \t\t{\n \t\t\techo ${HC}file:1:5:foo mmap bar\n \t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n\n--\n2.17.0\n"},{"id":"345610","messageId":"95bd565d1b976d8503a13ce7cd4125f38fbf8e8b.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 1/7] Documentation/config.txt: camel-case lineNumber for consistency","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:36Z","receivedAt":"2018-04-24T05:07:45Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"lineNumber has casing that is inconsistent with surrounding options,\nlike color.grep.matchContext, and color.grep.matchSelected. Re-case this\ndocumentation in order to be consistent with the text around it, and to\nensure that new entries are consistent, too.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..6e8d969f52 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,7 +1157,7 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n-- \n2.17.0\n\n"},{"id":"345611","messageId":"c9fcd2a1eef70aaeb4e030b23558f2829f66ddc4.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 2/7] grep.c: expose matched column in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:39Z","receivedAt":"2018-04-24T05:07:47Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"When calling match_line(), callers presently cannot determine the\nrelative offset of the match because match_line() discards the\n'regmatch_t' that contains this information.\n\nInstead, teach match_line() to take in a 'regmatch_t *' so that callers\ncan inspect the match's starting and ending offset from the beginning of\nthe line. This additional argument has no effect when opt->extended is\nnon-zero.\n\nWe will later pass the starting offset from 'regmatch_t *' to\nshow_line() in order to display the column number of the first match.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"345612","messageId":"f6f74e43eec63e9e7a9037a2a40075feb5fa0ac4.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 4/7] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:44Z","receivedAt":"2018-04-24T05:08:00Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To prepare for 'git grep' learning '--column-number', teach grep.c's\nshow_line() how to show the column of the first match on non-context\nline.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex fb0fa23231..d58d940afb 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1364,7 +1364,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1399,6 +1399,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\t/**\n+\t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n+\t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n+\t * being called with a context line.\n+\t */\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n@@ -1504,7 +1515,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1569,7 +1580,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1833,7 +1844,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1862,7 +1873,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"345613","messageId":"a5cd76f715d270bd60152d42892443ab8a518ee8.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 6/7] grep.c: add configuration variables to show matched option","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:48Z","receivedAt":"2018-04-24T05:08:00Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support git-grep(1)'s new option, '--column-number', document and\nteach grep.c how to interpret relevant configuration options, similar to\nthose associated with '--line-number'.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   | 5 +++++\n Documentation/git-grep.txt | 3 +++\n grep.c                     | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 6e8d969f52..8a2893d1e1 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,6 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `lineNumber`;;\n \tline number prefix (when using `-n`)\n+`columnNumber`;;\n+\tcolumn number prefix (when using `--column-number`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable the `--column-number` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 51dcfa5093..c5c4d712e6 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.columnNumber::\n+\tIf set to true, enable the `--column-number` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/grep.c b/grep.c\nindex d58d940afb..7284dec155 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -96,6 +96,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.columnnumber\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -112,6 +116,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.columnnumber\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n-- \n2.17.0\n\n"},{"id":"345614","messageId":"23ea226b544e9e5fcdbbcda3adb5982e2cae2123.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:51Z","receivedAt":"2018-04-24T05:08:04Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Take advantage of 'git-grep(1)''s new option, '--column-number' in order\nto teach Peff's 'git-jump' script how to jump to the correct column for\nany given match.\n\n'git-grep(1)''s output is in the correct format for Vim's jump list, so\nno additional cleanup is necessary.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/git-jump | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..8bc57ea0f8 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column-number\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"345615","messageId":"21857b3e647f3de0d23253c41fb9aaf9f614d323.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 5/7] builtin/grep.c: add '--column-number' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:46Z","receivedAt":"2018-04-24T05:08:05Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Teach 'git-grep(1)' a new option, '--column-number', to show the column\nnumber of the first match on a non-context line.\n\nFor example:\n\n  $ ./git-grep -n --column-number foo | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/git-grep.txt |  5 ++++-\n builtin/grep.c             |  1 +\n t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n 3 files changed, 27 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..51dcfa5093 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column-number]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -169,6 +169,9 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+--column-number::\n+\tPrefix the 1-indexed column number of the first match on non-context lines.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..512f60c591 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..bbce57c8b1 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,28 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L (with --column-number)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column-number -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n-- \n2.17.0\n\n"},{"id":"345616","messageId":"49579b4ce7b0964c156435cb0314184e6e7d7a13.1524545768.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1524545768.git.me@ttaylorr.com","subject":"[PATCH v3 3/7] grep.[ch]: extend grep_opt to allow showing matched column","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T05:07:41Z","receivedAt":"2018-04-24T05:08:06Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support showing the matched column when calling 'git-grep(1)', teach\n'grep_opt' the normal set of options to configure the default behavior\nand colorization of this feature.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 3 +++\n grep.h | 2 ++\n 2 files changed, 5 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..fb0fa23231 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -46,6 +46,7 @@ void init_grep_defaults(void)\n \tcolor_set(opt->color_filename, \"\");\n \tcolor_set(opt->color_function, \"\");\n \tcolor_set(opt->color_lineno, \"\");\n+\tcolor_set(opt->color_columnno, \"\");\n \tcolor_set(opt->color_match_context, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_selected, \"\");\n@@ -155,6 +156,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +166,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"345620","messageId":"CAPig+cTep_WuRy3qVHpZUMstc9Tgt9gFW=F8_0E8CZQQ8Jyq7g@mail.gmail.com","threadId":"48339","inReplyTo":"23ea226b544e9e5fcdbbcda3adb5982e2cae2123.1524545768.git.me@ttaylorr.com","subject":"Re: [PATCH v3 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-24T05:37:36Z","receivedAt":"2018-04-24T05:37:40Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Apr 24, 2018 at 1:07 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> Take advantage of 'git-grep(1)''s new option, '--column-number' in order\n> to teach Peff's 'git-jump' script how to jump to the correct column for\n> any given match.\n>\n> 'git-grep(1)''s output is in the correct format for Vim's jump list, so\n> no additional cleanup is necessary.\n>\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n>  contrib/git-jump/git-jump | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n\nBased upon Ævar review[1], I was expecting to see git-jump/README\nmodified by this patch, as well. Perhaps you overlooked or forgot\nabout that review comment, or perhaps you disagreed with it?\n\n[1]: https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com/\n\n> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\n> index 80ab0590bc..8bc57ea0f8 100755\n> --- a/contrib/git-jump/git-jump\n> +++ b/contrib/git-jump/git-jump\n> @@ -52,7 +52,7 @@ mode_merge() {\n>  # editor shows them to us in the status bar.\n>  mode_grep() {\n>         cmd=$(git config jump.grepCmd)\n> -       test -n \"$cmd\" || cmd=\"git grep -n\"\n> +       test -n \"$cmd\" || cmd=\"git grep -n --column-number\"\n>         $cmd \"$@\" |\n>         perl -pe '\n>         s/[ \\t]+/ /g;\n> --\n> 2.17.0\n"},{"id":"345621","messageId":"CAPig+cTPmJW9S-3Mu_4eBkLULNZetd9agjSShf0AMEd+iLbc2w@mail.gmail.com","threadId":"48339","inReplyTo":"f6f74e43eec63e9e7a9037a2a40075feb5fa0ac4.1524545768.git.me@ttaylorr.com","subject":"Re: [PATCH v3 4/7] grep.c: display column number of first match","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-04-24T05:42:24Z","receivedAt":"2018-04-24T05:42:28Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Apr 24, 2018 at 1:07 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> To prepare for 'git grep' learning '--column-number', teach grep.c's\n> show_line() how to show the column of the first match on non-context\n> line.\n>\n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n> diff --git a/grep.c b/grep.c\n> @@ -1399,6 +1399,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n> +       /**\n> +        * Treat 'cno' as the 1-indexed offset from the start of a non-context\n> +        * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n> +        * being called with a context line.\n> +        */\n\nNit: Ævar's review[1] mentioned that this project tends to use\n/*...*/, not /**...*/.\n\n[1]: https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com/\n\n> +       if (opt->columnnum && cno) {\n> +               char buf[32];\n> +               xsnprintf(buf, sizeof(buf), \"%d\", cno);\n> +               output_color(opt, buf, strlen(buf), opt->color_columnno);\n> +               output_sep(opt, sign);\n> +       }\n"},{"id":"345622","messageId":"xmqqtvs15dy4.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"874lk2e4he.fsf@evledraar.gmail.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-24T06:13:55Z","receivedAt":"2018-04-24T06:14:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> I think when we add features to git-grep we should be as close to GNU\n> grep as possible (e.g. not add this -m alias meaning something different\n> as in your v1), but if GNU grep doesn't have something go with the trend\n> of other grep tools, as noted at\n> https://beyondgrep.com/feature-comparison/ (and I found another one that\n> has this: https://github.com/beyondgrep/website/pull/83), so there's\n> already 3 prominent grep tools that call this just --column.\n>\n> I think we should just go with that.\n\nOK.  If they called it --column-number, that might have been more in\nline with GNU grep's --line-number, but that is not something we can\ndictate retroactively anyway, so --column to match them would be\nbetter than trying to be consistent and ending up with being\ndifferent from everybody else.\n\n> Also, as a bonus question, since you're poking at this column code\n> anyway, interested in implementing -o (--only-matching)? That would be\n> super-useful (see\n> https://public-inbox.org/git/87in9ucsbb.fsf@evledraar.gmail.com/) :)\n\nSounds good ;-).\n\n"},{"id":"345662","messageId":"20180424183401.GA13208@syl.local","threadId":"48339","inReplyTo":"xmqqtvs15dy4.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v2 2/6] grep.c: take column number as argument to show_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T18:34:01Z","receivedAt":"2018-04-24T18:34:10Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Apr 24, 2018 at 03:13:55PM +0900, Junio C Hamano wrote:\n> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n>\n> > I think when we add features to git-grep we should be as close to GNU\n> > grep as possible (e.g. not add this -m alias meaning something different\n> > as in your v1), but if GNU grep doesn't have something go with the trend\n> > of other grep tools, as noted at\n> > https://beyondgrep.com/feature-comparison/ (and I found another one that\n> > has this: https://github.com/beyondgrep/website/pull/83), so there's\n> > already 3 prominent grep tools that call this just --column.\n> >\n> > I think we should just go with that.\n>\n> OK.  If they called it --column-number, that might have been more in\n> line with GNU grep's --line-number, but that is not something we can\n> dictate retroactively anyway, so --column to match them would be\n> better than trying to be consistent and ending up with being\n> different from everybody else.\n\nThat sounds sensible. Let's call the new option '--column', and the\nconfiguration options grep.column and color.grep.column to match\n(instead of s/column/columnNumber/g), yes?\n\nThanks,\nTaylor\n"},{"id":"345663","messageId":"20180424183925.GA13637@syl.local","threadId":"48339","inReplyTo":"CAPig+cTep_WuRy3qVHpZUMstc9Tgt9gFW=F8_0E8CZQQ8Jyq7g@mail.gmail.com","subject":"Re: [PATCH v3 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-04-24T18:39:25Z","receivedAt":"2018-04-24T18:39:32Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Tue, Apr 24, 2018 at 01:37:36AM -0400, Eric Sunshine wrote:\n> On Tue, Apr 24, 2018 at 1:07 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> > Take advantage of 'git-grep(1)''s new option, '--column-number' in order\n> > to teach Peff's 'git-jump' script how to jump to the correct column for\n> > any given match.\n> >\n> > 'git-grep(1)''s output is in the correct format for Vim's jump list, so\n> > no additional cleanup is necessary.\n> >\n> > Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> > ---\n> >  contrib/git-jump/git-jump | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> Based upon Ævar review[1], I was expecting to see git-jump/README\n> modified by this patch, as well. Perhaps you overlooked or forgot\n> about that review comment, or perhaps you disagreed with it?\n\nYes, and thank you for pointing that out. I recall reading his mail and\nthought that when I prepared v3 that I had already included his changes,\nbut I had in fact not done so.\n\nI amended the git-jump's README to prepare for v4, but was somewhat\nconfused by Ævar's comment when I reread [1]. I believe he was\nsuggesting updating the example to remove a reference to ag(1)'s\n'--column' when configuring jump.grepCmd to 'ag --column'. Since\ngit-{grep,jump} support this now by default, I changed that line to\nsimply 'ag', instead of 'ag --column', as such:\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..7630e16854 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -37,3 +37,3 @@ Git-jump can generate four types of interesting lists:\n\n-  3. Any grep matches.\n+  3. Any grep matches, including the column of the first match on a line.\n\n@@ -67,3 +67,3 @@ git jump grep -i foo_bar\n # use the silver searcher for git jump grep\n-git config jump.grepCmd \"ag --column\"\n+git config jump.grepCmd \"ag\"\n --------------------------------------------------\n@@ -84,3 +84,3 @@ leaving you to locate subsequent hits in that file or other files using\n the editor or pager. By contrast, git-jump provides the editor with a\n-complete list of files and line numbers for each match.\n+complete list of files, lines, and a column number for each match.\n\n---\n\nDoes this look OK?\n\nThanks,\nTaylor\n"},{"id":"346696","messageId":"cover.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"20180421034530.GB24606@syl.local","subject":"[PATCH v4 0/7] Teach '--column' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:42:50Z","receivedAt":"2018-05-05T02:42:57Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi,\n\nAttached is my fourth--and what I anticipate to be the final--re-roll of\nmy series to add teach 'git-grep(1)' a new '--column' flag.\n\nSince last time, I have changed the following:\n\n  * Respond to Ævar's review suggesting that I (1) change git-jump's\n    README, (2) use --column over --column-number, and (3) use /*\\n, not\n    /**\\n. [1].\n\nThis change comprises the majority of the inter-diff between v3..v4,\nwhich is added below for conveniency. I have chosen to additionally\nrename the configuration variables from columnNumber to column, to be\nconsistent with the new flag name.\n\nThanks in advance for your review. I am going to send out my next patch\n(which Ævar suggested) to add '--only-matching' to 'git-grep(1)'.\n\n\nThanks,\nTaylor\n\n[1]: https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com\n\nTaylor Blau (7):\n  Documentation/config.txt: camel-case lineNumber for consistency\n  grep.c: expose matched column in match_line()\n  grep.[ch]: extend grep_opt to allow showing matched column\n  grep.c: display column number of first match\n  builtin/grep.c: add '--column' option to 'git-grep(1)'\n  grep.c: add configuration variables to show matched option\n  contrib/git-jump/git-jump: jump to match column in addition to line\n\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt |  8 +++++++-\n builtin/grep.c             |  1 +\n contrib/git-jump/README    |  6 +++---\n contrib/git-jump/git-jump  |  2 +-\n grep.c                     | 39 +++++++++++++++++++++++++++++---------\n grep.h                     |  2 ++\n t/t7810-grep.sh            | 22 +++++++++++++++++++++\n 8 files changed, 72 insertions(+), 15 deletions(-)\n\nInter-diff (since v3):\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 8a2893d1e1..b3c861c5c3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,8 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `lineNumber`;;\n \tline number prefix (when using `-n`)\n-`columnNumber`;;\n-\tcolumn number prefix (when using `--column-number`)\n+`column`;;\n+\tcolumn number prefix (when using `--column`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1710,8 +1710,8 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n\n-grep.columnNumber::\n-\tIf set to true, enable the `--column-number` option by default.\n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex c5c4d712e6..d451cd8883 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number] [--column-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -44,8 +44,8 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n\n-grep.columnNumber::\n-\tIf set to true, enable the `--column-number` option by default.\n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n@@ -172,7 +172,7 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n\n---column-number::\n+--column::\n \tPrefix the 1-indexed column number of the first match on non-context lines.\n\n -l::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 512f60c591..5c83f17759 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,7 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n-\t\tOPT_BOOL(0, \"column-number\", &opt.columnnum, N_(\"show column number of first match\")),\n+\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..7630e16854 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -35,7 +35,7 @@ Git-jump can generate four types of interesting lists:\n\n   2. The beginning of any merge conflict markers.\n\n-  3. Any grep matches.\n+  3. Any grep matches, including the column of the first match on a line.\n\n   4. Any whitespace errors detected by `git diff --check`.\n\n@@ -65,7 +65,7 @@ git jump grep foo_bar\n git jump grep -i foo_bar\n\n # use the silver searcher for git jump grep\n-git config jump.grepCmd \"ag --column\"\n+git config jump.grepCmd \"ag\"\n --------------------------------------------------\n\n\n@@ -82,7 +82,7 @@ which does something similar to `git jump grep`. However, it is limited\n to positioning the cursor to the correct line in only the first file,\n leaving you to locate subsequent hits in that file or other files using\n the editor or pager. By contrast, git-jump provides the editor with a\n-complete list of files and line numbers for each match.\n+complete list of files, lines, and a column number for each match.\n\n\n Limitations\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 8bc57ea0f8..931b0fe3a9 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n --column-number\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\ndiff --git a/grep.c b/grep.c\nindex 7284dec155..37bb39a4a8 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -96,7 +96,7 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n-\tif (!strcmp(var, \"grep.columnnumber\")) {\n+\tif (!strcmp(var, \"grep.column\")) {\n \t\topt->columnnum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n@@ -116,7 +116,7 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n-\telse if (!strcmp(var, \"color.grep.columnnumber\"))\n+\telse if (!strcmp(var, \"color.grep.column\"))\n \t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n@@ -1405,7 +1405,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n-\t/**\n+\t/*\n \t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n \t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n \t * being called with a context line.\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex bbce57c8b1..a03c3416e7 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,14 +99,14 @@ do\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep -w $L (with --column-number)\" '\n+\ttest_expect_success \"grep -w $L (with --column)\" '\n \t\t{\n \t\t\techo ${HC}file:5:foo mmap bar\n \t\t\techo ${HC}file:14:foo_mmap bar mmap\n \t\t\techo ${HC}file:5:foo mmap bar_mmap\n \t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n \t\t} >expected &&\n-\t\tgit grep --column-number -w -e mmap $H >actual &&\n+\t\tgit grep --column -w -e mmap $H >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n@@ -117,7 +117,7 @@ do\n \t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n \t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n \t\t} >expected &&\n-\t\tgit grep -n --column-number -w -e mmap $H >actual &&\n+\t\tgit grep -n --column -w -e mmap $H >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n--\n2.17.0\n"},{"id":"346697","messageId":"7c4bdff4ecd74448efffd35726681f62de7a9ed6.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 1/7] Documentation/config.txt: camel-case lineNumber for consistency","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:42:52Z","receivedAt":"2018-05-05T02:42:59Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"lineNumber has casing that is inconsistent with surrounding options,\nlike color.grep.matchContext, and color.grep.matchSelected. Re-case this\ndocumentation in order to be consistent with the text around it, and to\nensure that new entries are consistent, too.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..6e8d969f52 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,7 +1157,7 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n-- \n2.17.0\n\n"},{"id":"346698","messageId":"5281d6bdc1f6614b9330315cd9931ec9b2232445.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 2/7] grep.c: expose matched column in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:42:55Z","receivedAt":"2018-05-05T02:43:03Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"When calling match_line(), callers presently cannot determine the\nrelative offset of the match because match_line() discards the\n'regmatch_t' that contains this information.\n\nInstead, teach match_line() to take in a 'regmatch_t *' so that callers\ncan inspect the match's starting and ending offset from the beginning of\nthe line. This additional argument has no effect when opt->extended is\nnon-zero.\n\nWe will later pass the starting offset from 'regmatch_t *' to\nshow_line() in order to display the column number of the first match.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"346699","messageId":"d03ab96629e6cd001d738d3f35d9cd4b42fa848b.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 3/7] grep.[ch]: extend grep_opt to allow showing matched column","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:42:57Z","receivedAt":"2018-05-05T02:43:04Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support showing the matched column when calling 'git-grep(1)', teach\n'grep_opt' the normal set of options to configure the default behavior\nand colorization of this feature.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 3 +++\n grep.h | 2 ++\n 2 files changed, 5 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..fb0fa23231 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -46,6 +46,7 @@ void init_grep_defaults(void)\n \tcolor_set(opt->color_filename, \"\");\n \tcolor_set(opt->color_function, \"\");\n \tcolor_set(opt->color_lineno, \"\");\n+\tcolor_set(opt->color_columnno, \"\");\n \tcolor_set(opt->color_match_context, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_selected, \"\");\n@@ -155,6 +156,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +166,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"346700","messageId":"defb078e349848793d120103676635d44e361f1e.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 4/7] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:43:00Z","receivedAt":"2018-05-05T02:43:08Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To prepare for 'git grep' learning '--column', teach grep.c's\nshow_line() how to show the column of the first match on non-context\nline.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex fb0fa23231..f3fe416791 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1364,7 +1364,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1399,6 +1399,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\t/*\n+\t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n+\t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n+\t * being called with a context line.\n+\t */\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n@@ -1504,7 +1515,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1569,7 +1580,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1833,7 +1844,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1862,7 +1873,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"346701","messageId":"9a596d53d6b2523bc94e58678aa43e68068859b6.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:43:02Z","receivedAt":"2018-05-05T02:43:10Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Teach 'git-grep(1)' a new option, '--column', to show the column\nnumber of the first match on a non-context line.\n\nFor example:\n\n  $ git grep -n --column foo | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/git-grep.txt |  5 ++++-\n builtin/grep.c             |  1 +\n t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n 3 files changed, 27 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..5409a24399 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -169,6 +169,9 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+--column::\n+\tPrefix the 1-indexed column number of the first match on non-context lines.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..5c83f17759 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..a03c3416e7 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,28 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L (with --column)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep -n --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n-- \n2.17.0\n\n"},{"id":"346702","messageId":"81c686385848056723883b9ef031b9dc5393f9f6.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 6/7] grep.c: add configuration variables to show matched option","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:43:04Z","receivedAt":"2018-05-05T02:43:14Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support git-grep(1)'s new option, '--column', document and teach\ngrep.c how to interpret relevant configuration options, similar to those\nassociated with '--line-number'.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   | 5 +++++\n Documentation/git-grep.txt | 3 +++\n grep.c                     | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 6e8d969f52..b3c861c5c3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,6 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `lineNumber`;;\n \tline number prefix (when using `-n`)\n+`column`;;\n+\tcolumn number prefix (when using `--column`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 5409a24399..d451cd8883 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/grep.c b/grep.c\nindex f3fe416791..37bb39a4a8 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -96,6 +96,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.column\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -112,6 +116,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.column\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n-- \n2.17.0\n\n"},{"id":"346703","messageId":"326d07b48654ab2a64d09eb17d995a26d06bcdb1.1525488108.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525488108.git.me@ttaylorr.com","subject":"[PATCH v4 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-05T02:43:07Z","receivedAt":"2018-05-05T02:43:17Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Take advantage of 'git-grep(1)''s new option, '--column' in order to\nteach Peff's 'git-jump' script how to jump to the correct column for any\ngiven match.\n\n'git-grep(1)''s output is in the correct format for Vim's jump list, so\nno additional cleanup is necessary.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/README   | 6 +++---\n contrib/git-jump/git-jump | 2 +-\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..7630e16854 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -35,7 +35,7 @@ Git-jump can generate four types of interesting lists:\n \n   2. The beginning of any merge conflict markers.\n \n-  3. Any grep matches.\n+  3. Any grep matches, including the column of the first match on a line.\n \n   4. Any whitespace errors detected by `git diff --check`.\n \n@@ -65,7 +65,7 @@ git jump grep foo_bar\n git jump grep -i foo_bar\n \n # use the silver searcher for git jump grep\n-git config jump.grepCmd \"ag --column\"\n+git config jump.grepCmd \"ag\"\n --------------------------------------------------\n \n \n@@ -82,7 +82,7 @@ which does something similar to `git jump grep`. However, it is limited\n to positioning the cursor to the correct line in only the first file,\n leaving you to locate subsequent hits in that file or other files using\n the editor or pager. By contrast, git-jump provides the editor with a\n-complete list of files and line numbers for each match.\n+complete list of files, lines, and a column number for each match.\n \n \n Limitations\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..931b0fe3a9 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"346707","messageId":"CACsJy8BdJ0=gWZQVfSqy-vjtZVT4uZNzRaPYxRYxx2WNzaLodw@mail.gmail.com","threadId":"48339","inReplyTo":"9a596d53d6b2523bc94e58678aa43e68068859b6.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-05T06:15:03Z","receivedAt":"2018-05-05T06:15:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, May 5, 2018 at 4:43 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> Teach 'git-grep(1)' a new option, '--column', to show the column\n> number of the first match on a non-context line.\n\nWhy? Or put it another way, what is this option used for? Only\ngit-jump? (which should also be mentioned here if true)\n\n>\n> For example:\n>\n>   $ git grep -n --column foo | head -n3\n>   .clang-format:51:14:# myFunction(foo, bar, baz);\n>   .clang-format:64:7:# int foo();\n>   .clang-format:75:8:# void foo()\n>\n-- \nDuy\n"},{"id":"346769","messageId":"CAN0heSoiOd-oXj_0kJbc2qQCQAortCuXERpxF4Cro8pi4x1eBQ@mail.gmail.com","threadId":"48339","inReplyTo":"326d07b48654ab2a64d09eb17d995a26d06bcdb1.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-05-06T14:43:46Z","receivedAt":"2018-05-06T14:43:50Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 5 May 2018 at 04:43, Taylor Blau <me@ttaylorr.com> wrote:\n> Take advantage of 'git-grep(1)''s new option, '--column' in order to\n> teach Peff's 'git-jump' script how to jump to the correct column for any\n> given match.\n>\n> 'git-grep(1)''s output is in the correct format for Vim's jump list, so\n> no additional cleanup is necessary.\n\n> diff --git a/contrib/git-jump/README b/contrib/git-jump/README\n> index 4484bda410..7630e16854 100644\n\n>  # use the silver searcher for git jump grep\n> -git config jump.grepCmd \"ag --column\"\n> +git config jump.grepCmd \"ag\"\n\nI think this change originates from Ævar's comment that it \"also makes\nsense to update the example added in 007d06aa57 [...] which seems to\nhave added jump.grepCmd as a workaround for not having this\" [1].\n\nSomehow though, this approach seems a bit backwards to me. I do believe\nthat your series reduces the reasons for using `jump.grepCmd`, but\nregressing this example usage of `jump.grepCmd` seems a bit hostile. If\nsomeone wants to use `ag`, wouldn't we want to hint that they will\nprobably want to use `--column`?\n\nIs there some other `ag --column --foo` that we can give, where `--foo`\nis not yet in `git grep`? ;-)\n\nMartin\n\n[1] https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com/\n"},{"id":"346776","messageId":"20bc9baf-a85e-f00e-859e-e796ab4324f6@talktalk.net","threadId":"48339","inReplyTo":"9a596d53d6b2523bc94e58678aa43e68068859b6.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Phillip Wood","fromEmail":"phillip.wood@talktalk.net","sentAt":"2018-05-06T17:43:41Z","receivedAt":"2018-05-06T17:43:48Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Taylor\n\nOn 05/05/18 03:43, Taylor Blau wrote:\n> \n> Teach 'git-grep(1)' a new option, '--column', to show the column\n> number of the first match on a non-context line.\n> \n> For example:\n> \n>   $ git grep -n --column foo | head -n3\n>   .clang-format:51:14:# myFunction(foo, bar, baz);\n>   .clang-format:64:7:# int foo();\n>   .clang-format:75:8:# void foo()\n> \n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n>  Documentation/git-grep.txt |  5 ++++-\n>  builtin/grep.c             |  1 +\n>  t/t7810-grep.sh            | 22 ++++++++++++++++++++++\n>  3 files changed, 27 insertions(+), 1 deletion(-)\n> \n> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\n> index 18b494731f..5409a24399 100644\n> --- a/Documentation/git-grep.txt\n> +++ b/Documentation/git-grep.txt\n> @@ -13,7 +13,7 @@ SYNOPSIS\n>  \t   [-v | --invert-match] [-h|-H] [--full-name]\n>  \t   [-E | --extended-regexp] [-G | --basic-regexp]\n>  \t   [-P | --perl-regexp]\n> -\t   [-F | --fixed-strings] [-n | --line-number]\n> +\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n>  \t   [-l | --files-with-matches] [-L | --files-without-match]\n>  \t   [(-O | --open-files-in-pager) [<pager>]]\n>  \t   [-z | --null]\n> @@ -169,6 +169,9 @@ providing this option will cause it to die.\n>  --line-number::\n>  \tPrefix the line number to matching lines.\n>  \n> +--column::\n> +\tPrefix the 1-indexed column number of the first match on non-context lines.\n> +\n\nI think it would be useful to explain what the column number actually is\nso that users know how to consume it. Is it a count of bytes, multi-byte\ncharacters or graphemes? It would probably be worth testing with a file\nthat contains multi-byte characters to check for future regressions.\n\nBest Wishes\n\nPhillip\n\n>  -l::\n>  --files-with-matches::\n>  --name-only::\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 5f32d2ce84..5c83f17759 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>  \t\t\t    GREP_PATTERN_TYPE_PCRE),\n>  \t\tOPT_GROUP(\"\"),\n>  \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> +\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n>  \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n>  \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n>  \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> index 1797f632a3..a03c3416e7 100755\n> --- a/t/t7810-grep.sh\n> +++ b/t/t7810-grep.sh\n> @@ -99,6 +99,28 @@ do\n>  \t\ttest_cmp expected actual\n>  \t'\n>  \n> +\ttest_expect_success \"grep -w $L (with --column)\" '\n> +\t\t{\n> +\t\t\techo ${HC}file:5:foo mmap bar\n> +\t\t\techo ${HC}file:14:foo_mmap bar mmap\n> +\t\t\techo ${HC}file:5:foo mmap bar_mmap\n> +\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n> +\t\t} >expected &&\n> +\t\tgit grep --column -w -e mmap $H >actual &&\n> +\t\ttest_cmp expected actual\n> +\t'\n> +\n> +\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n> +\t\t{\n> +\t\t\techo ${HC}file:1:5:foo mmap bar\n> +\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n> +\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n> +\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n> +\t\t} >expected &&\n> +\t\tgit grep -n --column -w -e mmap $H >actual &&\n> +\t\ttest_cmp expected actual\n> +\t'\n> +\n>  \ttest_expect_success \"grep -w $L\" '\n>  \t\t{\n>  \t\t\techo ${HC}file:1:foo mmap bar\n> \n\n"},{"id":"346778","messageId":"87efioy8f9.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"9a596d53d6b2523bc94e58678aa43e68068859b6.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-05-06T17:56:42Z","receivedAt":"2018-05-06T17:57:09Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, May 05 2018, Taylor Blau wrote:\n\n\n> +\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n\nIt's now --column in v4 but this still refers to v3 --column-number.\n"},{"id":"346779","messageId":"87d0y8y84q.fsf@evledraar.gmail.com","threadId":"48339","inReplyTo":"CAN0heSoiOd-oXj_0kJbc2qQCQAortCuXERpxF4Cro8pi4x1eBQ@mail.gmail.com","subject":"Re: [PATCH v4 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-05-06T18:03:01Z","receivedAt":"2018-05-06T18:03:07Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, May 06 2018, Martin Ågren wrote:\n\n> On 5 May 2018 at 04:43, Taylor Blau <me@ttaylorr.com> wrote:\n>> Take advantage of 'git-grep(1)''s new option, '--column' in order to\n>> teach Peff's 'git-jump' script how to jump to the correct column for any\n>> given match.\n>>\n>> 'git-grep(1)''s output is in the correct format for Vim's jump list, so\n>> no additional cleanup is necessary.\n>\n>> diff --git a/contrib/git-jump/README b/contrib/git-jump/README\n>> index 4484bda410..7630e16854 100644\n>\n>>  # use the silver searcher for git jump grep\n>> -git config jump.grepCmd \"ag --column\"\n>> +git config jump.grepCmd \"ag\"\n>\n> I think this change originates from Ævar's comment that it \"also makes\n> sense to update the example added in 007d06aa57 [...] which seems to\n> have added jump.grepCmd as a workaround for not having this\" [1].\n>\n> Somehow though, this approach seems a bit backwards to me. I do believe\n> that your series reduces the reasons for using `jump.grepCmd`, but\n> regressing this example usage of `jump.grepCmd` seems a bit hostile. If\n> someone wants to use `ag`, wouldn't we want to hint that they will\n> probably want to use `--column`?\n>\n> Is there some other `ag --column --foo` that we can give, where `--foo`\n> is not yet in `git grep`? ;-)\n>\n> Martin\n>\n> [1] https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com/\n\nYeah it doesn't make sense to drop --column here, FWIW what I had in\nmind was something closer to:\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..357f79371a 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -25,6 +25,13 @@ git-jump will feed this to the editor:\n foo.c:2: printf(\"hello word!\\n\");\n -----------------------------------\n\n+Or, when running 'git jump grep' column numbers will also be emitted,\n+e.g. `git jump grep \"hello\"' would return:\n+\n+-----------------------------------\n+foo.c:2:10: printf(\"hello word!\\n\");\n+-----------------------------------\n+\n Obviously this trivial case isn't that interesting; you could just open\n `foo.c` yourself. But when you have many changes scattered across a\n project, you can use the editor's support to \"jump\" from point to point.\n\nI.e. let's note what the output format is now like for 'grep', and no\nneed to change the jump.grepCmd.\n\nThe above patch may be incorrect when it comes to the line numbe /\ncolumn number / format, I just wrote that by hand.\n"},{"id":"346867","messageId":"xmqqk1sfpn9j.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"9a596d53d6b2523bc94e58678aa43e68068859b6.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-07T14:13:12Z","receivedAt":"2018-05-07T14:13:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\n> index 18b494731f..5409a24399 100644\n> --- a/Documentation/git-grep.txt\n> +++ b/Documentation/git-grep.txt\n> @@ -13,7 +13,7 @@ SYNOPSIS\n>  \t   [-v | --invert-match] [-h|-H] [--full-name]\n>  \t   [-E | --extended-regexp] [-G | --basic-regexp]\n>  \t   [-P | --perl-regexp]\n> -\t   [-F | --fixed-strings] [-n | --line-number]\n> +\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n>  \t   [-l | --files-with-matches] [-L | --files-without-match]\n>  \t   [(-O | --open-files-in-pager) [<pager>]]\n>  \t   [-z | --null]\n> @@ -169,6 +169,9 @@ providing this option will cause it to die.\n>  --line-number::\n>  \tPrefix the line number to matching lines.\n>  \n> +--column::\n> +\tPrefix the 1-indexed column number of the first match on non-context lines.\n> +\n\nTwo questions.\n\n - It is fine that the leftmost column is 1, but what does this\n   number count?  The number of bytes on the same line before the\n   first byte of the hit (plus 1)?  The display width of the initial\n   non-matching part of the line (plus 1) on a fixed-width terminal?\n   The number of \"characters\"?  Something else?\n\n - Does --column combined with -v make any sense?  If not, shouldn't\n   the command error out when both are given at the same time?\n"},{"id":"346929","messageId":"20180507233539.GA77370@syl.local","threadId":"48339","inReplyTo":"87d0y8y84q.fsf@evledraar.gmail.com","subject":"Re: [PATCH v4 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-07T23:35:39Z","receivedAt":"2018-05-07T23:35:45Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, May 06, 2018 at 08:03:01PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Sun, May 06 2018, Martin Ågren wrote:\n>\n> > On 5 May 2018 at 04:43, Taylor Blau <me@ttaylorr.com> wrote:\n> >> Take advantage of 'git-grep(1)''s new option, '--column' in order to\n> >> teach Peff's 'git-jump' script how to jump to the correct column for any\n> >> given match.\n> >>\n> >> 'git-grep(1)''s output is in the correct format for Vim's jump list, so\n> >> no additional cleanup is necessary.\n> >\n> >> diff --git a/contrib/git-jump/README b/contrib/git-jump/README\n> >> index 4484bda410..7630e16854 100644\n> >\n> >>  # use the silver searcher for git jump grep\n> >> -git config jump.grepCmd \"ag --column\"\n> >> +git config jump.grepCmd \"ag\"\n> >\n> > I think this change originates from Ævar's comment that it \"also makes\n> > sense to update the example added in 007d06aa57 [...] which seems to\n> > have added jump.grepCmd as a workaround for not having this\" [1].\n> >\n> > Somehow though, this approach seems a bit backwards to me. I do believe\n> > that your series reduces the reasons for using `jump.grepCmd`, but\n> > regressing this example usage of `jump.grepCmd` seems a bit hostile. If\n> > someone wants to use `ag`, wouldn't we want to hint that they will\n> > probably want to use `--column`?\n> >\n> > Is there some other `ag --column --foo` that we can give, where `--foo`\n> > is not yet in `git grep`? ;-)\n> >\n> > Martin\n> >\n> > [1] https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com/\n>\n> Yeah it doesn't make sense to drop --column here, FWIW what I had in\n> mind was something closer to:\n\nThanks; I wasn't quite clear on what you had suggested in [1], so the\nattached diff is very helpful.\n\n> diff --git a/contrib/git-jump/README b/contrib/git-jump/README\n> index 4484bda410..357f79371a 100644\n> --- a/contrib/git-jump/README\n> +++ b/contrib/git-jump/README\n> @@ -25,6 +25,13 @@ git-jump will feed this to the editor:\n>  foo.c:2: printf(\"hello word!\\n\");\n>  -----------------------------------\n>\n> +Or, when running 'git jump grep' column numbers will also be emitted,\n> +e.g. `git jump grep \"hello\"' would return:\n> +\n> +-----------------------------------\n> +foo.c:2:10: printf(\"hello word!\\n\");\n> +-----------------------------------\n> +\n>  Obviously this trivial case isn't that interesting; you could just open\n>  `foo.c` yourself. But when you have many changes scattered across a\n>  project, you can use the editor's support to \"jump\" from point to point.\n>\n> I.e. let's note what the output format is now like for 'grep', and no\n> need to change the jump.grepCmd.\n\nApplied (mostly) the above patch to my copy, and will attach as part of\nv5.\n\n> The above patch may be incorrect when it comes to the line numbe /\n> column number / format, I just wrote that by hand.\n\nYes; the only thing that was wrong was the column number. The \"w\" is in\nthe 10th 1-indexed column, and 'git grep --column' uses 1-indexed\ncolumns.\n\nThanks,\nTaylor\n"},{"id":"346930","messageId":"20180507233807.GB77370@syl.local","threadId":"48339","inReplyTo":"CACsJy8BdJ0=gWZQVfSqy-vjtZVT4uZNzRaPYxRYxx2WNzaLodw@mail.gmail.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-07T23:38:07Z","receivedAt":"2018-05-07T23:38:13Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sat, May 05, 2018 at 08:15:03AM +0200, Duy Nguyen wrote:\n> On Sat, May 5, 2018 at 4:43 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> > Teach 'git-grep(1)' a new option, '--column', to show the column\n> > number of the first match on a non-context line.\n>\n> Why? Or put it another way, what is this option used for? Only\n> git-jump? (which should also be mentioned here if true)\n\nGood question. My primary intention is giving\n'contrib/git-jump/git-jump' the information it needs in order to tell\n$EDITOR how to seek to the relevant position within a line.\n\nI have amended this patch to include the relevant bits, and will attach\nin v5.\n\n\nThanks,\nTaylor\n"},{"id":"346932","messageId":"20180507234022.GC77370@syl.local","threadId":"48339","inReplyTo":"87efioy8f9.fsf@evledraar.gmail.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-07T23:40:22Z","receivedAt":"2018-05-07T23:40:27Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, May 06, 2018 at 07:56:42PM +0200, Ævar Arnfjörð Bjarmason wrote:\n>\n> On Sat, May 05 2018, Taylor Blau wrote:\n>\n>\n> > +\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n>\n> It's now --column in v4 but this still refers to v3 --column-number.\n\nThanks, I certainly missed this one.\n\n\nThanks,\nTaylor\n"},{"id":"346936","messageId":"20180508000853.GD77370@syl.local","threadId":"48339","inReplyTo":"xmqqk1sfpn9j.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-08T00:08:53Z","receivedAt":"2018-05-08T00:09:09Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, May 07, 2018 at 11:13:12PM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\n> > index 18b494731f..5409a24399 100644\n> > --- a/Documentation/git-grep.txt\n> > +++ b/Documentation/git-grep.txt\n> > @@ -13,7 +13,7 @@ SYNOPSIS\n> >  \t   [-v | --invert-match] [-h|-H] [--full-name]\n> >  \t   [-E | --extended-regexp] [-G | --basic-regexp]\n> >  \t   [-P | --perl-regexp]\n> > -\t   [-F | --fixed-strings] [-n | --line-number]\n> > +\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n> >  \t   [-l | --files-with-matches] [-L | --files-without-match]\n> >  \t   [(-O | --open-files-in-pager) [<pager>]]\n> >  \t   [-z | --null]\n> > @@ -169,6 +169,9 @@ providing this option will cause it to die.\n> >  --line-number::\n> >  \tPrefix the line number to matching lines.\n> >\n> > +--column::\n> > +\tPrefix the 1-indexed column number of the first match on non-context lines.\n> > +\n>\n> Two questions.\n>\n>  - It is fine that the leftmost column is 1, but what does this\n>    number count?  The number of bytes on the same line before the\n>    first byte of the hit (plus 1)?  The display width of the initial\n>    non-matching part of the line (plus 1) on a fixed-width terminal?\n>    The number of \"characters\"?  Something else?\n\nThe count is the byte offset from the 1-index (which is the beginning of\nthe line, as you noted).\n\nIncidentally, Peff and I chatted briefly offline about this, and agree\nthat it makes the most sense, since (1) Vim treats it correctly, and (2)\nwe can't be sure of options like display width, character count, etc.,\nwithout knowing the character encoding.\n\nNonetheless, other folks in this thread seem to be curious about this\nas well. I'll add it to the documentation for --column in\nDocumentation/git-grep.txt.\n\n>  - Does --column combined with -v make any sense?  If not, shouldn't\n>    the command error out when both are given at the same time?\n\nI hadn't thought of this. They do not work together, since 'git grep -v\n--column' would require us to either (1) not output the column number,\nor (2) output '0', or some other non-value.\n\nI think that both (1) and (2) require callers to complicate their\nscripts to understand either approach. As such, I think that we should\ndie() here, and add a test in t7810 to ensure that that's indeed what\nhappens.\n\nDoes this seem sensible to include in v5?\n\n\nThanks,\nTaylor\n"},{"id":"346969","messageId":"d030b4ee-5a92-4863-a29c-de2642bfae8d@web.de","threadId":"48339","inReplyTo":"5281d6bdc1f6614b9330315cd9931ec9b2232445.1525488108.git.me@ttaylorr.com","subject":"Re: [PATCH v4 2/7] grep.c: expose matched column in match_line()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-05-08T06:08:47Z","receivedAt":"2018-05-08T06:08:53Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 05.05.2018 um 04:42 schrieb Taylor Blau:\n> When calling match_line(), callers presently cannot determine the\n> relative offset of the match because match_line() discards the\n> 'regmatch_t' that contains this information.\n> \n> Instead, teach match_line() to take in a 'regmatch_t *' so that callers\n> can inspect the match's starting and ending offset from the beginning of\n> the line. This additional argument has no effect when opt->extended is\n> non-zero.\n> \n> We will later pass the starting offset from 'regmatch_t *' to\n> show_line() in order to display the column number of the first match.\n> \n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n>   grep.c | 9 +++++----\n>   1 file changed, 5 insertions(+), 4 deletions(-)\n> \n> diff --git a/grep.c b/grep.c\n> index 65b90c10a3..1c25782355 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n>   }\n>   \n>   static int match_line(struct grep_opt *opt, char *bol, char *eol,\n> -\t\t      enum grep_context ctx, int collect_hits)\n> +\t\t      regmatch_t *match, enum grep_context ctx,\n> +\t\t      int collect_hits)\n>   {\n>   \tstruct grep_pat *p;\n> -\tregmatch_t match;\n>   \n>   \tif (opt->extended)\n>   \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n\nIf ->extended is set then match won't be touched...\n\n>   \n>   \t/* we do not call with collect_hits without being extended */\n>   \tfor (p = opt->pattern_list; p; p = p->next) {\n> -\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n> +\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n>   \t\t\treturn 1;\n>   \t}\n>   \treturn 0;\n> @@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n>   \tint try_lookahead = 0;\n>   \tint show_function = 0;\n>   \tstruct userdiff_driver *textconv = NULL;\n> +\tregmatch_t match;\n>   \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n>   \txdemitconf_t xecfg;\n>   \n> @@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n>   \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n>   \t\t\tctx = GREP_CONTEXT_BODY;\n>   \n> -\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n> +\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n>   \t\t*eol = ch;\n>   \n>   \t\tif (collect_hits)\n> \n\n... which leaves it uninitialized.\n\nSo at least the combination of extended matches and --column should error\nout.  Supporting it would be better, of course.  That could get tricky for\nnegations, though (e.g. git grep --not -e foo).\n\nRené\n"},{"id":"347041","messageId":"cover.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"20180421034530.GB24606@syl.local","subject":"[PATCH v5 0/7] Teach '--column' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:26Z","receivedAt":"2018-05-09T02:13:35Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi,\n\nAttached is my fifth re-roll of the series to add '--column' to\n'git-grep(1)'.\n\nThe main changes are from a René's concerns in [1]. He points out that\n'--column' with certain extended expressions can produce nonsense\n(particularly because we leave the regmatch_t uninitialized).\n\n> So at least the combination of extended matches and --column should error\n> out.  Supporting it would be better, of course.  That could get tricky for\n> negations, though (e.g. git grep --not -e foo).\n\nI have opted for the die() option, instead of supporting extended\nmatches with --column. The problem with extended matches in this case is\nthat _sometimes_ --column can produce sensible results, and other times\nit cannot.\n\nFor instance, an extended expression containing a single atom\nhas a known answer for --column, but one containing a negative atom does\nonly sometimes. Specifically: if an NOT atom is at the top-level, we\n_never_ have a sensible answer for --column, but only sometimes do when\nit is not at the top-level.\n\nSo, this leaves us two choices: (1) don't support --column and extended\nexpressions, or (2) support --column with extended expressions by not\nprinting columnar information when we don't have an answer. Option (2)\nrequires callers to perform deep inspection of their extended\nexpressions, and determine whether or not there is a answer that Git\ncould produce. This is too much to ask a caller to reasonably consider\nwhen scripting. On the other hand, option (1) does not allow the caller\nto do as much under certain circumstances, but simplifies their lives\nwhen scripting, etc. For those reasons, let's pick (1).\n\nBeyond that, here is a summary of what has changed since last time:\n\n  * die() when given --extended, or compiling to an extended grammar,\n    like in the case of 'git grep --column --not -e foo' [1].\n\n  * Clarify patch 5/7 and indicate the intended purpose of supporting\n    '--column' [2].\n\n  * Clarify that '--column' gives a 1-indexed _byte_ offset, nothing\n    else [3,5].\n\n  * Remove a dangling reference to '--column-number' [4].\n\n  * Clean up contrib/git-jump/README to Ævar's suggestion [6].\n\n\nThanks as always for your kind review.\n\n\nThanks,\nTaylor\n\n[1]: https://public-inbox.org/git/d030b4ee-5a92-4863-a29c-de2642bfae8d@web.de\n[2]: https://public-inbox.org/git/CACsJy8BdJ0=gWZQVfSqy-vjtZVT4uZNzRaPYxRYxx2WNzaLodw@mail.gmail.com\n[3]: https://public-inbox.org/git/20bc9baf-a85e-f00e-859e-e796ab4324f6@talktalk.net\n[4]: https://public-inbox.org/git/87efioy8f9.fsf@evledraar.gmail.com\n[5]: https://public-inbox.org/git/xmqqk1sfpn9j.fsf@gitster-ct.c.googlers.com\n[6]: https://public-inbox.org/git/87d0y8y84q.fsf@evledraar.gmail.com/\n\nTaylor Blau (7):\n  Documentation/config.txt: camel-case lineNumber for consistency\n  grep.c: expose matched column in match_line()\n  grep.[ch]: extend grep_opt to allow showing matched column\n  grep.c: display column number of first match\n  builtin/grep.c: add '--column' option to 'git-grep(1)'\n  grep.c: add configuration variables to show matched option\n  contrib/git-jump/git-jump: jump to match column in addition to line\n\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt |  9 +++++++-\n builtin/grep.c             |  4 ++++\n contrib/git-jump/README    | 12 +++++++++--\n contrib/git-jump/git-jump  |  2 +-\n grep.c                     | 42 ++++++++++++++++++++++++++++++--------\n grep.h                     |  2 ++\n t/t7810-grep.sh            | 32 +++++++++++++++++++++++++++++\n 8 files changed, 96 insertions(+), 14 deletions(-)\n\nInter-diff (since v5):\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex d451cd8883..dc8f76ce99 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -173,7 +173,8 @@ providing this option will cause it to die.\n \tPrefix the line number to matching lines.\n\n --column::\n-\tPrefix the 1-indexed column number of the first match on non-context lines.\n+\tPrefix the 1-indexed byte-offset of the first match on non-context lines. This\n+\toption is incompatible with '--invert-match', and extended expressions.\n\n -l::\n --files-with-matches::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5c83f17759..f9f516dfc4 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -1112,6 +1112,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\thit = grep_objects(&opt, &pathspec, the_repository, &list);\n \t}\n\n+\tif (opt.columnnum && opt.invert)\n+\t\tdie(_(\"--column and --invert-match cannot be combined\"));\n+\n \tif (num_threads)\n \t\thit |= wait_all();\n \tif (hit && show_in_pager)\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 7630e16854..2f618a7f97 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -25,6 +25,13 @@ git-jump will feed this to the editor:\n foo.c:2: printf(\"hello word!\\n\");\n -----------------------------------\n\n+Or, when running 'git jump grep', column numbers will also be emitted,\n+e.g. `git jump grep \"hello\"` would return:\n+\n+-----------------------------------\n+foo.c:2:9: printf(\"hello word!\\n\");\n+-----------------------------------\n+\n Obviously this trivial case isn't that interesting; you could just open\n `foo.c` yourself. But when you have many changes scattered across a\n project, you can use the editor's support to \"jump\" from point to point.\n@@ -35,7 +42,8 @@ Git-jump can generate four types of interesting lists:\n\n   2. The beginning of any merge conflict markers.\n\n-  3. Any grep matches, including the column of the first match on a line.\n+  3. Any grep matches, including the column of the first match on a\n+     line.\n\n   4. Any whitespace errors detected by `git diff --check`.\n\n@@ -65,7 +73,7 @@ git jump grep foo_bar\n git jump grep -i foo_bar\n\n # use the silver searcher for git jump grep\n-git config jump.grepCmd \"ag\"\n+git config jump.grepCmd \"ag --column\"\n --------------------------------------------------\n\n\ndiff --git a/grep.c b/grep.c\nindex 37bb39a4a8..5d904810ad 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1001,6 +1001,9 @@ static void compile_grep_patterns_real(struct grep_opt *opt)\n \telse if (!opt->extended && !opt->debug)\n \t\treturn;\n\n+\tif (opt->columnnum && opt->extended)\n+\t\tdie(_(\"--column and extended expressions cannot be combined\"));\n+\n \tp = opt->pattern_list;\n \tif (p)\n \t\topt->pattern_expression = compile_pattern_expr(&p);\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex a03c3416e7..aa56b21ed9 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -110,7 +110,7 @@ do\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep -w $L (with --{line,column}-number)\" '\n+\ttest_expect_success \"grep -w $L (with --line-number, --column)\" '\n \t\t{\n \t\t\techo ${HC}file:1:5:foo mmap bar\n \t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n@@ -1612,4 +1612,14 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n\n+test_expect_success 'grep does not allow --column, --invert-match' '\n+\ttest_must_fail git grep --column --invert-match pat 2>err &&\n+\ttest_i18ngrep \"\\-\\-column and \\-\\-invert-match cannot be combined\" err\n+'\n+\n+test_expect_success 'grep does not allow --column, extended' '\n+\ttest_must_fail git grep --column --not -e pat 2>err &&\n+\ttest_i18ngrep \"\\-\\-column and extended expressions cannot be combined\" err\n+'\n+\n test_done\n\n--\n2.17.0\n"},{"id":"347042","messageId":"7c4bdff4ecd74448efffd35726681f62de7a9ed6.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 1/7] Documentation/config.txt: camel-case lineNumber for consistency","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:29Z","receivedAt":"2018-05-09T02:13:40Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"lineNumber has casing that is inconsistent with surrounding options,\nlike color.grep.matchContext, and color.grep.matchSelected. Re-case this\ndocumentation in order to be consistent with the text around it, and to\nensure that new entries are consistent, too.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..6e8d969f52 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,7 +1157,7 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n-- \n2.17.0\n\n"},{"id":"347043","messageId":"d03ab96629e6cd001d738d3f35d9cd4b42fa848b.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 3/7] grep.[ch]: extend grep_opt to allow showing matched column","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:34Z","receivedAt":"2018-05-09T02:13:42Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support showing the matched column when calling 'git-grep(1)', teach\n'grep_opt' the normal set of options to configure the default behavior\nand colorization of this feature.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 3 +++\n grep.h | 2 ++\n 2 files changed, 5 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..fb0fa23231 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -46,6 +46,7 @@ void init_grep_defaults(void)\n \tcolor_set(opt->color_filename, \"\");\n \tcolor_set(opt->color_function, \"\");\n \tcolor_set(opt->color_lineno, \"\");\n+\tcolor_set(opt->color_columnno, \"\");\n \tcolor_set(opt->color_match_context, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_selected, \"\");\n@@ -155,6 +156,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +166,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"347044","messageId":"defb078e349848793d120103676635d44e361f1e.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 4/7] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:36Z","receivedAt":"2018-05-09T02:13:45Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To prepare for 'git grep' learning '--column', teach grep.c's\nshow_line() how to show the column of the first match on non-context\nline.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex fb0fa23231..f3fe416791 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1364,7 +1364,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1399,6 +1399,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\t/*\n+\t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n+\t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n+\t * being called with a context line.\n+\t */\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n@@ -1504,7 +1515,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1569,7 +1580,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1833,7 +1844,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1862,7 +1873,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"347045","messageId":"1b187e77c26a075878d6fc561ad289a0408f797e.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 6/7] grep.c: add configuration variables to show matched option","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:40Z","receivedAt":"2018-05-09T02:13:47Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support git-grep(1)'s new option, '--column', document and teach\ngrep.c how to interpret relevant configuration options, similar to those\nassociated with '--line-number'.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   | 5 +++++\n Documentation/git-grep.txt | 3 +++\n grep.c                     | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 6e8d969f52..b3c861c5c3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,6 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `lineNumber`;;\n \tline number prefix (when using `-n`)\n+`column`;;\n+\tcolumn number prefix (when using `--column`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 75f1561112..dc8f76ce99 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/grep.c b/grep.c\nindex f4228c23ac..5d904810ad 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -96,6 +96,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.column\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -112,6 +116,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.column\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n-- \n2.17.0\n\n"},{"id":"347046","messageId":"0ab0a422fea29233fad37e6b8d57648f43db6b89.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:43Z","receivedAt":"2018-05-09T02:13:53Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Take advantage of 'git-grep(1)''s new option, '--column' in order to\nteach Peff's 'git-jump' script how to jump to the correct column for any\ngiven match.\n\n'git-grep(1)''s output is in the correct format for Vim's jump list, so\nno additional cleanup is necessary.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/README   | 12 ++++++++++--\n contrib/git-jump/git-jump |  2 +-\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..2f618a7f97 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -25,6 +25,13 @@ git-jump will feed this to the editor:\n foo.c:2: printf(\"hello word!\\n\");\n -----------------------------------\n \n+Or, when running 'git jump grep', column numbers will also be emitted,\n+e.g. `git jump grep \"hello\"` would return:\n+\n+-----------------------------------\n+foo.c:2:9: printf(\"hello word!\\n\");\n+-----------------------------------\n+\n Obviously this trivial case isn't that interesting; you could just open\n `foo.c` yourself. But when you have many changes scattered across a\n project, you can use the editor's support to \"jump\" from point to point.\n@@ -35,7 +42,8 @@ Git-jump can generate four types of interesting lists:\n \n   2. The beginning of any merge conflict markers.\n \n-  3. Any grep matches.\n+  3. Any grep matches, including the column of the first match on a\n+     line.\n \n   4. Any whitespace errors detected by `git diff --check`.\n \n@@ -82,7 +90,7 @@ which does something similar to `git jump grep`. However, it is limited\n to positioning the cursor to the correct line in only the first file,\n leaving you to locate subsequent hits in that file or other files using\n the editor or pager. By contrast, git-jump provides the editor with a\n-complete list of files and line numbers for each match.\n+complete list of files, lines, and a column number for each match.\n \n \n Limitations\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..931b0fe3a9 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"347047","messageId":"9222f0ee470884a984c1174cf218dece43f77f87.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:38Z","receivedAt":"2018-05-09T02:14:00Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Teach 'git-grep(1)' a new option, '--column', to show the column\nnumber of the first match on a non-context line. This makes it possible\nto teach 'contrib/git-jump/git-jump' how to seek to the first matching\nposition of a grep match in your editor, and allows similar additional\nscripting capabilities.\n\nFor example:\n\n  $ git grep -n --column foo | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/git-grep.txt |  6 +++++-\n builtin/grep.c             |  4 ++++\n grep.c                     |  3 +++\n t/t7810-grep.sh            | 32 ++++++++++++++++++++++++++++++++\n 4 files changed, 44 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..75f1561112 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -169,6 +169,10 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+--column::\n+\tPrefix the 1-indexed byte-offset of the first match on non-context lines. This\n+\toption is incompatible with '--invert-match', and extended expressions.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..f9f516dfc4 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\n@@ -1111,6 +1112,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\thit = grep_objects(&opt, &pathspec, the_repository, &list);\n \t}\n \n+\tif (opt.columnnum && opt.invert)\n+\t\tdie(_(\"--column and --invert-match cannot be combined\"));\n+\n \tif (num_threads)\n \t\thit |= wait_all();\n \tif (hit && show_in_pager)\ndiff --git a/grep.c b/grep.c\nindex f3fe416791..f4228c23ac 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -995,6 +995,9 @@ static void compile_grep_patterns_real(struct grep_opt *opt)\n \telse if (!opt->extended && !opt->debug)\n \t\treturn;\n \n+\tif (opt->columnnum && opt->extended)\n+\t\tdie(_(\"--column and extended expressions cannot be combined\"));\n+\n \tp = opt->pattern_list;\n \tif (p)\n \t\topt->pattern_expression = compile_pattern_expr(&p);\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..aa56b21ed9 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,28 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L (with --column)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L (with --line-number, --column)\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep -n --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n@@ -1590,4 +1612,14 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'grep does not allow --column, --invert-match' '\n+\ttest_must_fail git grep --column --invert-match pat 2>err &&\n+\ttest_i18ngrep \"\\-\\-column and \\-\\-invert-match cannot be combined\" err\n+'\n+\n+test_expect_success 'grep does not allow --column, extended' '\n+\ttest_must_fail git grep --column --not -e pat 2>err &&\n+\ttest_i18ngrep \"\\-\\-column and extended expressions cannot be combined\" err\n+'\n+\n test_done\n-- \n2.17.0\n\n"},{"id":"347048","messageId":"5281d6bdc1f6614b9330315cd9931ec9b2232445.1525831201.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1525831201.git.me@ttaylorr.com","subject":"[PATCH v5 2/7] grep.c: expose matched column in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T02:13:31Z","receivedAt":"2018-05-09T02:14:06Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"When calling match_line(), callers presently cannot determine the\nrelative offset of the match because match_line() discards the\n'regmatch_t' that contains this information.\n\nInstead, teach match_line() to take in a 'regmatch_t *' so that callers\ncan inspect the match's starting and ending offset from the beginning of\nthe line. This additional argument has no effect when opt->extended is\nnon-zero.\n\nWe will later pass the starting offset from 'regmatch_t *' to\nshow_line() in order to display the column number of the first match.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"347060","messageId":"882bdfe8-6caa-dd9c-7752-ee4884f135f9@talktalk.net","threadId":"48339","inReplyTo":"9222f0ee470884a984c1174cf218dece43f77f87.1525831201.git.me@ttaylorr.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Phillip Wood","fromEmail":"phillip.wood@talktalk.net","sentAt":"2018-05-09T10:41:02Z","receivedAt":"2018-05-09T10:41:15Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Taylor\n\nOn 09/05/18 03:13, Taylor Blau wrote:\n> Teach 'git-grep(1)' a new option, '--column', to show the column\n> number of the first match on a non-context line. This makes it possible\n> to teach 'contrib/git-jump/git-jump' how to seek to the first matching\n> position of a grep match in your editor, and allows similar additional\n> scripting capabilities.\n> \n> For example:\n> \n>    $ git grep -n --column foo | head -n3\n>    .clang-format:51:14:# myFunction(foo, bar, baz);\n>    .clang-format:64:7:# int foo();\n>    .clang-format:75:8:# void foo()\n> \n> Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> ---\n>   Documentation/git-grep.txt |  6 +++++-\n>   builtin/grep.c             |  4 ++++\n>   grep.c                     |  3 +++\n>   t/t7810-grep.sh            | 32 ++++++++++++++++++++++++++++++++\n>   4 files changed, 44 insertions(+), 1 deletion(-)\n> \n> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\n> index 18b494731f..75f1561112 100644\n> --- a/Documentation/git-grep.txt\n> +++ b/Documentation/git-grep.txt\n> @@ -13,7 +13,7 @@ SYNOPSIS\n>   \t   [-v | --invert-match] [-h|-H] [--full-name]\n>   \t   [-E | --extended-regexp] [-G | --basic-regexp]\n>   \t   [-P | --perl-regexp]\n> -\t   [-F | --fixed-strings] [-n | --line-number]\n> +\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n>   \t   [-l | --files-with-matches] [-L | --files-without-match]\n>   \t   [(-O | --open-files-in-pager) [<pager>]]\n>   \t   [-z | --null]\n> @@ -169,6 +169,10 @@ providing this option will cause it to die.\n>   --line-number::\n>   \tPrefix the line number to matching lines.\n>   \n> +--column::\n> +\tPrefix the 1-indexed byte-offset of the first match on non-context lines. This\n> +\toption is incompatible with '--invert-match', and extended expressions.\n> +\n\nSorry to be fussy, but while this is clearer I think to could be \nimproved to make it clear that it is the offset from the start of the \nmatching line. Also the mention of 'extended expressions' made me think \nof 'grep -E' but I think (correct me if I'm wrong) you mean the boolean \noptions '--and', '--not' and '--or'. The man page only uses the word \nextended when talking about extended regexes. I think something like\n\nPrint the 1-indexed byte-offset of the first match from the start of the \nmatching line. This option is incompatible with '--invert-match', \n'--and', '--not' and '--or'.\n\nwould be clearer\n\nBest Wishes\n\nPhillip\n\n\n>   -l::\n>   --files-with-matches::\n>   --name-only::\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 5f32d2ce84..f9f516dfc4 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>   \t\t\t    GREP_PATTERN_TYPE_PCRE),\n>   \t\tOPT_GROUP(\"\"),\n>   \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> +\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n>   \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n>   \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n>   \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\n> @@ -1111,6 +1112,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>   \t\thit = grep_objects(&opt, &pathspec, the_repository, &list);\n>   \t}\n>   \n> +\tif (opt.columnnum && opt.invert)\n> +\t\tdie(_(\"--column and --invert-match cannot be combined\"));\n> +\n>   \tif (num_threads)\n>   \t\thit |= wait_all();\n>   \tif (hit && show_in_pager)\n> diff --git a/grep.c b/grep.c\n> index f3fe416791..f4228c23ac 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -995,6 +995,9 @@ static void compile_grep_patterns_real(struct grep_opt *opt)\n>   \telse if (!opt->extended && !opt->debug)\n>   \t\treturn;\n>   \n> +\tif (opt->columnnum && opt->extended)\n> +\t\tdie(_(\"--column and extended expressions cannot be combined\"));\n> +\n>   \tp = opt->pattern_list;\n>   \tif (p)\n>   \t\topt->pattern_expression = compile_pattern_expr(&p);\n> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\n> index 1797f632a3..aa56b21ed9 100755\n> --- a/t/t7810-grep.sh\n> +++ b/t/t7810-grep.sh\n> @@ -99,6 +99,28 @@ do\n>   \t\ttest_cmp expected actual\n>   \t'\n>   \n> +\ttest_expect_success \"grep -w $L (with --column)\" '\n> +\t\t{\n> +\t\t\techo ${HC}file:5:foo mmap bar\n> +\t\t\techo ${HC}file:14:foo_mmap bar mmap\n> +\t\t\techo ${HC}file:5:foo mmap bar_mmap\n> +\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n> +\t\t} >expected &&\n> +\t\tgit grep --column -w -e mmap $H >actual &&\n> +\t\ttest_cmp expected actual\n> +\t'\n> +\n> +\ttest_expect_success \"grep -w $L (with --line-number, --column)\" '\n> +\t\t{\n> +\t\t\techo ${HC}file:1:5:foo mmap bar\n> +\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n> +\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n> +\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n> +\t\t} >expected &&\n> +\t\tgit grep -n --column -w -e mmap $H >actual &&\n> +\t\ttest_cmp expected actual\n> +\t'\n> +\n>   \ttest_expect_success \"grep -w $L\" '\n>   \t\t{\n>   \t\t\techo ${HC}file:1:foo mmap bar\n> @@ -1590,4 +1612,14 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n>   \ttest_cmp expected actual\n>   '\n>   \n> +test_expect_success 'grep does not allow --column, --invert-match' '\n> +\ttest_must_fail git grep --column --invert-match pat 2>err &&\n> +\ttest_i18ngrep \"\\-\\-column and \\-\\-invert-match cannot be combined\" err\n> +'\n> +\n> +test_expect_success 'grep does not allow --column, extended' '\n> +\ttest_must_fail git grep --column --not -e pat 2>err &&\n> +\ttest_i18ngrep \"\\-\\-column and extended expressions cannot be combined\" err\n> +'\n> +\n>   test_done\n> \n\n"},{"id":"347094","messageId":"CACsJy8DLthWhxH6a7zwCvdirkuntanHasXZwfdADeo7iV8X79w@mail.gmail.com","threadId":"48339","inReplyTo":"9222f0ee470884a984c1174cf218dece43f77f87.1525831201.git.me@ttaylorr.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-09T16:17:20Z","receivedAt":"2018-05-09T16:17:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, May 9, 2018 at 4:13 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 5f32d2ce84..f9f516dfc4 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>                             GREP_PATTERN_TYPE_PCRE),\n>                 OPT_GROUP(\"\"),\n>                 OPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> +               OPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n\nTwo things to consider:\n\n- do we ever want columnar output in git-grep? Something like \"git\ngrep --column -l\" could make sense (if you don't have very large\nworktree). --column is currently used for column output in git-branch,\ngit-tag and git-status, which makes me think maybe we should reserve\n\"--column\" for that purpose and use another name here, even if we\ndon't ever want column output in git-grep, for consistency.\n\n- If this is to help git-jump only and rarely manually specified on\ncommand line, you could add the flag PARSE_OPT_NOCOMPLETE to hide it\nfrom \"git grep --<tab>\" completion. You would need to use OPT_BOOL_F()\ninstead of OPT_BOOL() in order to add extra flags.\n-- \nDuy\n"},{"id":"347109","messageId":"CAN0heSpXCajyDKwOrXuQHWRODsVnFewUWTMitOoRQueFV4eSiw@mail.gmail.com","threadId":"48339","inReplyTo":"882bdfe8-6caa-dd9c-7752-ee4884f135f9@talktalk.net","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-05-09T17:26:57Z","receivedAt":"2018-05-09T17:27:04Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On 9 May 2018 at 12:41, Phillip Wood <phillip.wood@talktalk.net> wrote:\n> On 09/05/18 03:13, Taylor Blau wrote:\n>>\n>>   +--column::\n>> +       Prefix the 1-indexed byte-offset of the first match on non-context\n>> lines. This\n>> +       option is incompatible with '--invert-match', and extended\n>> expressions.\n>> +\n>\n>\n> Sorry to be fussy, but while this is clearer I think to could be improved to\n> make it clear that it is the offset from the start of the matching line.\n> Also the mention of 'extended expressions' made me think of 'grep -E' but I\n> think (correct me if I'm wrong) you mean the boolean options '--and',\n> '--not' and '--or'. The man page only uses the word extended when talking\n> about extended regexes. I think something like\n>\n> Print the 1-indexed byte-offset of the first match from the start of the\n> matching line. This option is incompatible with '--invert-match', '--and',\n> '--not' and '--or'.\n>\n> would be clearer\n\n>> +       if (opt->columnnum && opt->extended)\n>> +               die(_(\"--column and extended expressions cannot be combined\"));\n>> +\n\nJust so it doesn't get missed: Phillip's comment (which I agree with)\nabout \"extended\" would apply here as well. This would work fine, no?\n\nOne thing to notice is that dying for `--column --not` in combination\nwith patch 7/7 makes git-jump unable to handle `--not` (and friends).\nThat would be a regression? I suppose git-jump could use a special\n`--maybe-column` which would be \"please use --column, unless I give you\nsomething that won't play well with it\". Or --column could do that kind\nof falling back on its own. Or, git-jump could scan the arguments to\ndecide whether to use `--column` or not. Hmm... Tricky. :-/\n\nMartin\n"},{"id":"347147","messageId":"20180509234815.GA68889@syl.local","threadId":"48339","inReplyTo":"CACsJy8DLthWhxH6a7zwCvdirkuntanHasXZwfdADeo7iV8X79w@mail.gmail.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T23:48:15Z","receivedAt":"2018-05-09T23:48:36Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, May 09, 2018 at 06:17:20PM +0200, Duy Nguyen wrote:\n> On Wed, May 9, 2018 at 4:13 AM, Taylor Blau <me@ttaylorr.com> wrote:\n> > diff --git a/builtin/grep.c b/builtin/grep.c\n> > index 5f32d2ce84..f9f516dfc4 100644\n> > --- a/builtin/grep.c\n> > +++ b/builtin/grep.c\n> > @@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n> >                             GREP_PATTERN_TYPE_PCRE),\n> >                 OPT_GROUP(\"\"),\n> >                 OPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n> > +               OPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n>\n> Two things to consider:\n>\n> - do we ever want columnar output in git-grep? Something like \"git\n> grep --column -l\" could make sense (if you don't have very large\n> worktree). --column is currently used for column output in git-branch,\n> git-tag and git-status, which makes me think maybe we should reserve\n> \"--column\" for that purpose and use another name here, even if we\n> don't ever want column output in git-grep, for consistency.\n\nI think that this is a valid concern. I had a similar thought when\nadding 'git config --color' (as a new type specifier) that we might be\nsquatting on '--color' and instead opted for '[--type=<type>]'.\n\nI don't feel that the tradeoff between '--column' as a good name and the\nconcern that we _might_ want to output in a columnar format in 'git\ngrep' someday warrants the change.\n\n> - If this is to help git-jump only and rarely manually specified on\n> command line, you could add the flag PARSE_OPT_NOCOMPLETE to hide it\n> from \"git grep --<tab>\" completion. You would need to use OPT_BOOL_F()\n> instead of OPT_BOOL() in order to add extra flags.\n\nI believe that this option is worth auto-completing. Its primarily\nmotivated for use within 'git-jump', but I feel as if it would be\nuseful for other callers, as well.\n\nThanks,\nTaylor\n"},{"id":"347148","messageId":"20180509234935.GB68889@syl.local","threadId":"48339","inReplyTo":"882bdfe8-6caa-dd9c-7752-ee4884f135f9@talktalk.net","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T23:49:35Z","receivedAt":"2018-05-09T23:49:40Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, May 09, 2018 at 11:41:02AM +0100, Phillip Wood wrote:\n> Hi Taylor\n>\n> On 09/05/18 03:13, Taylor Blau wrote:\n> > Teach 'git-grep(1)' a new option, '--column', to show the column\n> > number of the first match on a non-context line. This makes it possible\n> > to teach 'contrib/git-jump/git-jump' how to seek to the first matching\n> > position of a grep match in your editor, and allows similar additional\n> > scripting capabilities.\n> >\n> > For example:\n> >\n> >    $ git grep -n --column foo | head -n3\n> >    .clang-format:51:14:# myFunction(foo, bar, baz);\n> >    .clang-format:64:7:# int foo();\n> >    .clang-format:75:8:# void foo()\n> >\n> > Signed-off-by: Taylor Blau <me@ttaylorr.com>\n> > ---\n> >   Documentation/git-grep.txt |  6 +++++-\n> >   builtin/grep.c             |  4 ++++\n> >   grep.c                     |  3 +++\n> >   t/t7810-grep.sh            | 32 ++++++++++++++++++++++++++++++++\n> >   4 files changed, 44 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\n> > index 18b494731f..75f1561112 100644\n> > --- a/Documentation/git-grep.txt\n> > +++ b/Documentation/git-grep.txt\n> > @@ -13,7 +13,7 @@ SYNOPSIS\n> >   \t   [-v | --invert-match] [-h|-H] [--full-name]\n> >   \t   [-E | --extended-regexp] [-G | --basic-regexp]\n> >   \t   [-P | --perl-regexp]\n> > -\t   [-F | --fixed-strings] [-n | --line-number]\n> > +\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n> >   \t   [-l | --files-with-matches] [-L | --files-without-match]\n> >   \t   [(-O | --open-files-in-pager) [<pager>]]\n> >   \t   [-z | --null]\n> > @@ -169,6 +169,10 @@ providing this option will cause it to die.\n> >   --line-number::\n> >   \tPrefix the line number to matching lines.\n> > +--column::\n> > +\tPrefix the 1-indexed byte-offset of the first match on non-context lines. This\n> > +\toption is incompatible with '--invert-match', and extended expressions.\n> > +\n>\n> Sorry to be fussy, but while this is clearer I think to could be improved to\n> make it clear that it is the offset from the start of the matching line.\n> Also the mention of 'extended expressions' made me think of 'grep -E' but I\n> think (correct me if I'm wrong) you mean the boolean options '--and',\n> '--not' and '--or'. The man page only uses the word extended when talking\n> about extended regexes. I think something like\n>\n> Print the 1-indexed byte-offset of the first match from the start of the\n> matching line. This option is incompatible with '--invert-match', '--and',\n> '--not' and '--or'.\n>\n> would be clearer\n\nI agree, and would be happy to change it as-such. I think that there is\nsome pending discussion about regressing 'git-jump' no longer supporting\n'--not', so I'll wait for that to resolve before resending this patch.\n\nThanks,\nTaylor\n"},{"id":"347149","messageId":"20180509235251.GC68889@syl.local","threadId":"48339","inReplyTo":"CAN0heSpXCajyDKwOrXuQHWRODsVnFewUWTMitOoRQueFV4eSiw@mail.gmail.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-09T23:52:51Z","receivedAt":"2018-05-09T23:52:58Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, May 09, 2018 at 07:26:57PM +0200, Martin Ågren wrote:\n> On 9 May 2018 at 12:41, Phillip Wood <phillip.wood@talktalk.net> wrote:\n> > On 09/05/18 03:13, Taylor Blau wrote:\n> >>\n> >>   +--column::\n> >> +       Prefix the 1-indexed byte-offset of the first match on non-context\n> >> lines. This\n> >> +       option is incompatible with '--invert-match', and extended\n> >> expressions.\n> >> +\n> >\n> >\n> > Sorry to be fussy, but while this is clearer I think to could be improved to\n> > make it clear that it is the offset from the start of the matching line.\n> > Also the mention of 'extended expressions' made me think of 'grep -E' but I\n> > think (correct me if I'm wrong) you mean the boolean options '--and',\n> > '--not' and '--or'. The man page only uses the word extended when talking\n> > about extended regexes. I think something like\n> >\n> > Print the 1-indexed byte-offset of the first match from the start of the\n> > matching line. This option is incompatible with '--invert-match', '--and',\n> > '--not' and '--or'.\n> >\n> > would be clearer\n>\n> >> +       if (opt->columnnum && opt->extended)\n> >> +               die(_(\"--column and extended expressions cannot be combined\"));\n> >> +\n>\n> Just so it doesn't get missed: Phillip's comment (which I agree with)\n> about \"extended\" would apply here as well. This would work fine, no?\n\nThis check we should retain and change the wording to mention '--and',\n'--or', and '--not' specifically.\n\n> One thing to notice is that dying for `--column --not` in combination\n> with patch 7/7 makes git-jump unable to handle `--not` (and friends).\n> That would be a regression? I suppose git-jump could use a special\n> `--maybe-column` which would be \"please use --column, unless I give you\n> something that won't play well with it\". Or --column could do that kind\n> of falling back on its own. Or, git-jump could scan the arguments to\n> decide whether to use `--column` or not. Hmm... Tricky. :-/\n\nAgree that this is tricky. I don't think that --maybe-column is a\ndirection that we should take for the reasons I outlined in the cover\nletter. Like I said, there are cases under an extended grammar where we\ncan and cannot display meaningful column offsets.\n\nWith regards to regressing 'git-jump', I feel as if 'git-jump --not' is\nan uncommon-enough case that I would be comfortable with the tradeoff.\nIf a caller _is_ using '--not' in 'git-jump', they can reconfigure\n'jump.grepCmd' to work around this issue.\n\nPerhaps this is worth warning about in 'git-jump'? Peff, what do you\nthink?\n\n\nThanks,\nTaylor\n"},{"id":"347150","messageId":"xmqqefikl6jx.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180509235251.GC68889@syl.local","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-10T00:04:34Z","receivedAt":"2018-05-10T00:04:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> This check we should retain and change the wording to mention '--and',\n> '--or', and '--not' specifically.\n\nWhy are these problematic in the first place?  If I said\n\n    $ git grep -e first --and -e these\n    $ git grep -e first --and --not -e those\n    $ git grep -e first --or -e those\n\nI'd expect that the first line of this paragraph will hit, and the\nfirst hit for these three are \"these\", \"first\" and \"first\",\nrespectively.  Most importantly, in the last one, \"--or\" can be\nomitted and the whole thing stops being \"extended\", so rejecting\nextended as a whole does not make much sense.\n\n    $ git grep -v second\n    $ git grep --not -e second\n\nmay hit all lines in this message (except for the obvious two\nlines), but we cannot say which column we found a hit.  I am\nwondering if it is too grave a sin to report \"the whole line is what\nsatisfied the criteria given\" and say the match lies at column #1.\n\nBy doing so, obviously we can sidestep the whole \"this mode is\nsometimes incompatible\" and \"I need to compute a lot to see if the\ngiven expression is compatible or not\" issues.\n"},{"id":"347176","messageId":"4640b041-f66c-3c1f-1329-baa4580df5cc@web.de","threadId":"48339","inReplyTo":"xmqqefikl6jx.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-05-10T05:58:47Z","receivedAt":"2018-05-10T05:59:08Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 10.05.2018 um 02:04 schrieb Junio C Hamano:\n> Taylor Blau <me@ttaylorr.com> writes:\n> \n>> This check we should retain and change the wording to mention '--and',\n>> '--or', and '--not' specifically.\n> \n> Why are these problematic in the first place?  If I said\n> \n>      $ git grep -e first --and -e these\n>      $ git grep -e first --and --not -e those\n>      $ git grep -e first --or -e those\n> \n> I'd expect that the first line of this paragraph will hit, and the\n> first hit for these three are \"these\", \"first\" and \"first\",\n> respectively.  Most importantly, in the last one, \"--or\" can be\n> omitted and the whole thing stops being \"extended\", so rejecting\n> extended as a whole does not make much sense.\n> \n>      $ git grep -v second\n>      $ git grep --not -e second\n> \n> may hit all lines in this message (except for the obvious two\n> lines), but we cannot say which column we found a hit.  I am\n> wondering if it is too grave a sin to report \"the whole line is what\n> satisfied the criteria given\" and say the match lies at column #1.\n> \n> By doing so, obviously we can sidestep the whole \"this mode is\n> sometimes incompatible\" and \"I need to compute a lot to see if the\n> given expression is compatible or not\" issues.\n\nFWIW, Silver Searcher 2.1.0 does just that:\n\n\t$ echo a | ag --column -v b\n\t1:a\n\nripgrep 0.8.1 as well:\n\n\t$ echo a | rg --column -v b\n\t1:1:a\n\nSide note: This example also shows that --column implies --line-number\nfor ripgrep because column numbers are mostly useless without line\nnumbers (https://github.com/BurntSushi/ripgrep/issues/243).  I'm not\nsure I'm buying that reasoning.\n\nack-grep 2.22 seems to have problems with that combination:\n\n\t$ echo a | ack --column -v b\n\ta\n\n\t$ echo a | ack -H --column -v b\n\t-\n\tUse of uninitialized value $line_parts[1] in join or string at /usr/bin/ack line 653, <STDIN> line 1.\n\t1::a\n\nRené\n"},{"id":"347182","messageId":"xmqqk1scj9il.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"4640b041-f66c-3c1f-1329-baa4580df5cc@web.de","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-10T06:43:30Z","receivedAt":"2018-05-10T06:43:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Am 10.05.2018 um 02:04 schrieb Junio C Hamano:\n> ...\n>>      $ git grep -v second\n>>      $ git grep --not -e second\n>> \n>> may hit all lines in this message (except for the obvious two\n>> lines), but we cannot say which column we found a hit.  I am\n>> wondering if it is too grave a sin to report \"the whole line is what\n>> satisfied the criteria given\" and say the match lies at column #1.\n\nAnd if we are planning to use this to implement '-o', then I'd\nsuggest that we'd say the matched part of the line is the whole\nthing (i.e. so is column #1, eo is at the eol).\n\n>> By doing so, obviously we can sidestep the whole \"this mode is\n>> sometimes incompatible\" and \"I need to compute a lot to see if the\n>> given expression is compatible or not\" issues.\n>\n> FWIW, Silver Searcher 2.1.0 does just that:\n>\n> \t$ echo a | ag --column -v b\n> \t1:a\n>\n> ripgrep 0.8.1 as well:\n>\n> \t$ echo a | rg --column -v b\n> \t1:1:a\n\nThanks for additional datapoints.\n\n"},{"id":"347406","messageId":"cover.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"20180421034530.GB24606@syl.local","subject":"[PATCH v6 0/7] Teach '--column' to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:10:57Z","receivedAt":"2018-05-12T03:11:15Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi,\n\nAttached is my sixth re-roll of a series to add '--column' to 'git\ngrep'.\n\nThe main change since v5 is supporting --column with queries containing\n--and, --or, or --not. Previously, I had chosen to die() in this case\nsince there isn't always a good answer to \"what is the first column of\n<complicated expression>?\" but have gone back on this for two reasons:\n\n  1. It is important not to regress calls to git-jump/contrib/git-jump\n  that contain --and, --or, or --not.\n\n  2. It is not that hard to detect the absence of column data in scripts.\n     Likewise, git-jump will happily accept lines with or without\n     columnar information, and Vim will accept it as-is.\n\nSo, let's support --column and only die() when also given\n--invert-match. When we don't have a good answer, print nothing.\n\nThanks,\nTaylor\n\nTaylor Blau (7):\n  Documentation/config.txt: camel-case lineNumber for consistency\n  grep.c: expose matched column in match_line()\n  grep.[ch]: extend grep_opt to allow showing matched column\n  grep.c: display column number of first match\n  builtin/grep.c: add '--column' option to 'git-grep(1)'\n  grep.c: add configuration variables to show matched option\n  contrib/git-jump/git-jump: jump to match column in addition to line\n\n Documentation/config.txt   |  7 ++++++-\n Documentation/git-grep.txt | 10 +++++++++-\n builtin/grep.c             |  4 ++++\n contrib/git-jump/README    | 12 ++++++++++--\n contrib/git-jump/git-jump  |  2 +-\n grep.c                     | 40 +++++++++++++++++++++++++++++---------\n grep.h                     |  2 ++\n t/t7810-grep.sh            | 39 +++++++++++++++++++++++++++++++++++++\n 8 files changed, 102 insertions(+), 14 deletions(-)\n\nInter-diff (since v5):\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex dc8f76ce99..c48a578cb1 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -173,8 +173,9 @@ providing this option will cause it to die.\n \tPrefix the line number to matching lines.\n\n --column::\n-\tPrefix the 1-indexed byte-offset of the first match on non-context lines. This\n-\toption is incompatible with '--invert-match', and extended expressions.\n+\tPrefix the 1-indexed byte-offset of the first match from the start of the\n+\tmatching line. This option is incompatible with '--invert-match', and\n+\tignored with expressions using '--and', '--or', '--not'.\n\n -l::\n --files-with-matches::\ndiff --git a/grep.c b/grep.c\nindex 5d904810ad..5ba1b05526 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1001,9 +1001,6 @@ static void compile_grep_patterns_real(struct grep_opt *opt)\n \telse if (!opt->extended && !opt->debug)\n \t\treturn;\n\n-\tif (opt->columnnum && opt->extended)\n-\t\tdie(_(\"--column and extended expressions cannot be combined\"));\n-\n \tp = opt->pattern_list;\n \tif (p)\n \t\topt->pattern_expression = compile_pattern_expr(&p);\n@@ -1411,9 +1408,10 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t/*\n \t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n \t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n-\t * being called with a context line.\n+\t * being called with a context line, or we are --extended, and cannot\n+\t * always show an answer.\n \t */\n-\tif (opt->columnnum && cno) {\n+\tif (opt->columnnum && sign == ':' && !opt->extended) {\n \t\tchar buf[32];\n \t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n \t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex aa56b21ed9..491b2e044a 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -110,6 +110,18 @@ do\n \t\ttest_cmp expected actual\n \t'\n\n+\ttest_expect_success \"grep -w $L (with --column, -C)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file-foo_mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column -w -C1 -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L (with --line-number, --column)\" '\n \t\t{\n \t\t\techo ${HC}file:1:5:foo mmap bar\n@@ -1617,9 +1629,4 @@ test_expect_success 'grep does not allow --column, --invert-match' '\n \ttest_i18ngrep \"\\-\\-column and \\-\\-invert-match cannot be combined\" err\n '\n\n-test_expect_success 'grep does not allow --column, extended' '\n-\ttest_must_fail git grep --column --not -e pat 2>err &&\n-\ttest_i18ngrep \"\\-\\-column and extended expressions cannot be combined\" err\n-'\n-\n test_done\n\n--\n2.17.0\n"},{"id":"347407","messageId":"7c4bdff4ecd74448efffd35726681f62de7a9ed6.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 1/7] Documentation/config.txt: camel-case lineNumber for consistency","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:00Z","receivedAt":"2018-05-12T03:11:15Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"lineNumber has casing that is inconsistent with surrounding options,\nlike color.grep.matchContext, and color.grep.matchSelected. Re-case this\ndocumentation in order to be consistent with the text around it, and to\nensure that new entries are consistent, too.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 2659153cb3..6e8d969f52 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1157,7 +1157,7 @@ color.grep.<slot>::\n \tfilename prefix (when not using `-h`)\n `function`;;\n \tfunction name lines (when using `-p`)\n-`linenumber`;;\n+`lineNumber`;;\n \tline number prefix (when using `-n`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n-- \n2.17.0\n\n"},{"id":"347408","messageId":"5281d6bdc1f6614b9330315cd9931ec9b2232445.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 2/7] grep.c: expose matched column in match_line()","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:03Z","receivedAt":"2018-05-12T03:11:15Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"When calling match_line(), callers presently cannot determine the\nrelative offset of the match because match_line() discards the\n'regmatch_t' that contains this information.\n\nInstead, teach match_line() to take in a 'regmatch_t *' so that callers\ncan inspect the match's starting and ending offset from the beginning of\nthe line. This additional argument has no effect when opt->extended is\nnon-zero.\n\nWe will later pass the starting offset from 'regmatch_t *' to\nshow_line() in order to display the column number of the first match.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex 65b90c10a3..1c25782355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1299,17 +1299,17 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static int match_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      enum grep_context ctx, int collect_hits)\n+\t\t      regmatch_t *match, enum grep_context ctx,\n+\t\t      int collect_hits)\n {\n \tstruct grep_pat *p;\n-\tregmatch_t match;\n \n \tif (opt->extended)\n \t\treturn match_expr(opt, bol, eol, ctx, collect_hits);\n \n \t/* we do not call with collect_hits without being extended */\n \tfor (p = opt->pattern_list; p; p = p->next) {\n-\t\tif (match_one_pattern(p, bol, eol, ctx, &match, 0))\n+\t\tif (match_one_pattern(p, bol, eol, ctx, match, 0))\n \t\t\treturn 1;\n \t}\n \treturn 0;\n@@ -1699,6 +1699,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \tint try_lookahead = 0;\n \tint show_function = 0;\n \tstruct userdiff_driver *textconv = NULL;\n+\tregmatch_t match;\n \tenum grep_context ctx = GREP_CONTEXT_HEAD;\n \txdemitconf_t xecfg;\n \n@@ -1788,7 +1789,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\tif ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))\n \t\t\tctx = GREP_CONTEXT_BODY;\n \n-\t\thit = match_line(opt, bol, eol, ctx, collect_hits);\n+\t\thit = match_line(opt, bol, eol, &match, ctx, collect_hits);\n \t\t*eol = ch;\n \n \t\tif (collect_hits)\n-- \n2.17.0\n\n"},{"id":"347409","messageId":"d03ab96629e6cd001d738d3f35d9cd4b42fa848b.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 3/7] grep.[ch]: extend grep_opt to allow showing matched column","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:06Z","receivedAt":"2018-05-12T03:11:15Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support showing the matched column when calling 'git-grep(1)', teach\n'grep_opt' the normal set of options to configure the default behavior\nand colorization of this feature.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 3 +++\n grep.h | 2 ++\n 2 files changed, 5 insertions(+)\n\ndiff --git a/grep.c b/grep.c\nindex 1c25782355..fb0fa23231 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -46,6 +46,7 @@ void init_grep_defaults(void)\n \tcolor_set(opt->color_filename, \"\");\n \tcolor_set(opt->color_function, \"\");\n \tcolor_set(opt->color_lineno, \"\");\n+\tcolor_set(opt->color_columnno, \"\");\n \tcolor_set(opt->color_match_context, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);\n \tcolor_set(opt->color_selected, \"\");\n@@ -155,6 +156,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \topt->extended_regexp_option = def->extended_regexp_option;\n \topt->pattern_type_option = def->pattern_type_option;\n \topt->linenum = def->linenum;\n+\topt->columnnum = def->columnnum;\n \topt->max_depth = def->max_depth;\n \topt->pathname = def->pathname;\n \topt->relative = def->relative;\n@@ -164,6 +166,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)\n \tcolor_set(opt->color_filename, def->color_filename);\n \tcolor_set(opt->color_function, def->color_function);\n \tcolor_set(opt->color_lineno, def->color_lineno);\n+\tcolor_set(opt->color_columnno, def->color_columnno);\n \tcolor_set(opt->color_match_context, def->color_match_context);\n \tcolor_set(opt->color_match_selected, def->color_match_selected);\n \tcolor_set(opt->color_selected, def->color_selected);\ndiff --git a/grep.h b/grep.h\nindex 399381c908..08a0b391c5 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -127,6 +127,7 @@ struct grep_opt {\n \tint prefix_length;\n \tregex_t regexp;\n \tint linenum;\n+\tint columnnum;\n \tint invert;\n \tint ignore_case;\n \tint status_only;\n@@ -159,6 +160,7 @@ struct grep_opt {\n \tchar color_filename[COLOR_MAXLEN];\n \tchar color_function[COLOR_MAXLEN];\n \tchar color_lineno[COLOR_MAXLEN];\n+\tchar color_columnno[COLOR_MAXLEN];\n \tchar color_match_context[COLOR_MAXLEN];\n \tchar color_match_selected[COLOR_MAXLEN];\n \tchar color_selected[COLOR_MAXLEN];\n-- \n2.17.0\n\n"},{"id":"347410","messageId":"defb078e349848793d120103676635d44e361f1e.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 4/7] grep.c: display column number of first match","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:09Z","receivedAt":"2018-05-12T03:11:19Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To prepare for 'git grep' learning '--column', teach grep.c's\nshow_line() how to show the column of the first match on non-context\nline.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n grep.c | 21 ++++++++++++++++-----\n 1 file changed, 16 insertions(+), 5 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex fb0fa23231..f3fe416791 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1364,7 +1364,7 @@ static int next_match(struct grep_opt *opt, char *bol, char *eol,\n }\n \n static void show_line(struct grep_opt *opt, char *bol, char *eol,\n-\t\t      const char *name, unsigned lno, char sign)\n+\t\t      const char *name, unsigned lno, unsigned cno, char sign)\n {\n \tint rest = eol - bol;\n \tconst char *match_color, *line_color = NULL;\n@@ -1399,6 +1399,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t\toutput_color(opt, buf, strlen(buf), opt->color_lineno);\n \t\toutput_sep(opt, sign);\n \t}\n+\t/*\n+\t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n+\t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n+\t * being called with a context line.\n+\t */\n+\tif (opt->columnnum && cno) {\n+\t\tchar buf[32];\n+\t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n+\t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\n+\t\toutput_sep(opt, sign);\n+\t}\n \tif (opt->color) {\n \t\tregmatch_t match;\n \t\tenum grep_context ctx = GREP_CONTEXT_BODY;\n@@ -1504,7 +1515,7 @@ static void show_funcname_line(struct grep_opt *opt, struct grep_source *gs,\n \t\t\tbreak;\n \n \t\tif (match_funcname(opt, gs, bol, eol)) {\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '=');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, 0, '=');\n \t\t\tbreak;\n \t\t}\n \t}\n@@ -1569,7 +1580,7 @@ static void show_pre_context(struct grep_opt *opt, struct grep_source *gs,\n \n \t\twhile (*eol != '\\n')\n \t\t\teol++;\n-\t\tshow_line(opt, bol, eol, gs->name, cur, sign);\n+\t\tshow_line(opt, bol, eol, gs->name, cur, 0, sign);\n \t\tbol = eol + 1;\n \t\tcur++;\n \t}\n@@ -1833,7 +1844,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t\tshow_pre_context(opt, gs, bol, eol, lno);\n \t\t\telse if (opt->funcname)\n \t\t\t\tshow_funcname_line(opt, gs, bol, lno);\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, ':');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, ':');\n \t\t\tlast_hit = lno;\n \t\t\tif (opt->funcbody)\n \t\t\t\tshow_function = 1;\n@@ -1862,7 +1873,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle\n \t\t\t/* If the last hit is within the post context,\n \t\t\t * we need to show this line.\n \t\t\t */\n-\t\t\tshow_line(opt, bol, eol, gs->name, lno, '-');\n+\t\t\tshow_line(opt, bol, eol, gs->name, lno, match.rm_so+1, '-');\n \t\t}\n \n \tnext_line:\n-- \n2.17.0\n\n"},{"id":"347411","messageId":"cb697d32ee6a2e5d45f331a809bd5e7cb1ba7a9c.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:12Z","receivedAt":"2018-05-12T03:11:19Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Teach 'git-grep(1)' a new option, '--column', to show the column\nnumber of the first match on a non-context line. This makes it possible\nto teach 'contrib/git-jump/git-jump' how to seek to the first matching\nposition of a grep match in your editor, and allows similar additional\nscripting capabilities.\n\nFor example:\n\n  $ git grep -n --column foo | head -n3\n  .clang-format:51:14:# myFunction(foo, bar, baz);\n  .clang-format:64:7:# int foo();\n  .clang-format:75:8:# void foo()\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/git-grep.txt |  7 ++++++-\n builtin/grep.c             |  4 ++++\n grep.c                     |  5 +++--\n t/t7810-grep.sh            | 39 ++++++++++++++++++++++++++++++++++++++\n 4 files changed, 52 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 18b494731f..cec4665df5 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -13,7 +13,7 @@ SYNOPSIS\n \t   [-v | --invert-match] [-h|-H] [--full-name]\n \t   [-E | --extended-regexp] [-G | --basic-regexp]\n \t   [-P | --perl-regexp]\n-\t   [-F | --fixed-strings] [-n | --line-number]\n+\t   [-F | --fixed-strings] [-n | --line-number] [--column]\n \t   [-l | --files-with-matches] [-L | --files-without-match]\n \t   [(-O | --open-files-in-pager) [<pager>]]\n \t   [-z | --null]\n@@ -169,6 +169,11 @@ providing this option will cause it to die.\n --line-number::\n \tPrefix the line number to matching lines.\n \n+--column::\n+\tPrefix the 1-indexed byte-offset of the first match from the start of the\n+\tmatching line. This option is incompatible with '--invert-match', and\n+\tignored with expressions using '--and', '--or', '--not'.\n+\n -l::\n --files-with-matches::\n --name-only::\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 5f32d2ce84..f9f516dfc4 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -829,6 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n+\t\tOPT_BOOL(0, \"column\", &opt.columnnum, N_(\"show column number of first match\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\n \t\tOPT_BIT('H', NULL, &opt.pathname, N_(\"show filenames\"), 1),\n \t\tOPT_NEGBIT(0, \"full-name\", &opt.relative,\n@@ -1111,6 +1112,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\thit = grep_objects(&opt, &pathspec, the_repository, &list);\n \t}\n \n+\tif (opt.columnnum && opt.invert)\n+\t\tdie(_(\"--column and --invert-match cannot be combined\"));\n+\n \tif (num_threads)\n \t\thit |= wait_all();\n \tif (hit && show_in_pager)\ndiff --git a/grep.c b/grep.c\nindex f3fe416791..7396b49a2d 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -1402,9 +1402,10 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,\n \t/*\n \t * Treat 'cno' as the 1-indexed offset from the start of a non-context\n \t * line to its first match. Otherwise, 'cno' is 0 indicating that we are\n-\t * being called with a context line.\n+\t * being called with a context line, or we are --extended, and cannot\n+\t * always show an answer.\n \t */\n-\tif (opt->columnnum && cno) {\n+\tif (opt->columnnum && sign == ':' && !opt->extended) {\n \t\tchar buf[32];\n \t\txsnprintf(buf, sizeof(buf), \"%d\", cno);\n \t\toutput_color(opt, buf, strlen(buf), opt->color_columnno);\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 1797f632a3..491b2e044a 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -99,6 +99,40 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L (with --column)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L (with --column, -C)\" '\n+\t\t{\n+\t\t\techo ${HC}file:5:foo mmap bar\n+\t\t\techo ${HC}file-foo_mmap bar\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep --column -w -C1 -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep -w $L (with --line-number, --column)\" '\n+\t\t{\n+\t\t\techo ${HC}file:1:5:foo mmap bar\n+\t\t\techo ${HC}file:3:14:foo_mmap bar mmap\n+\t\t\techo ${HC}file:4:5:foo mmap bar_mmap\n+\t\t\techo ${HC}file:5:14:foo_mmap bar mmap baz\n+\t\t} >expected &&\n+\t\tgit grep -n --column -w -e mmap $H >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L\" '\n \t\t{\n \t\t\techo ${HC}file:1:foo mmap bar\n@@ -1590,4 +1624,9 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'grep does not allow --column, --invert-match' '\n+\ttest_must_fail git grep --column --invert-match pat 2>err &&\n+\ttest_i18ngrep \"\\-\\-column and \\-\\-invert-match cannot be combined\" err\n+'\n+\n test_done\n-- \n2.17.0\n\n"},{"id":"347412","messageId":"dfd8be62befbbe173faa0d4992b08e82964209c2.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 6/7] grep.c: add configuration variables to show matched option","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:15Z","receivedAt":"2018-05-12T03:11:23Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"To support git-grep(1)'s new option, '--column', document and teach\ngrep.c how to interpret relevant configuration options, similar to those\nassociated with '--line-number'.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n Documentation/config.txt   | 5 +++++\n Documentation/git-grep.txt | 3 +++\n grep.c                     | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 6e8d969f52..b3c861c5c3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1159,6 +1159,8 @@ color.grep.<slot>::\n \tfunction name lines (when using `-p`)\n `lineNumber`;;\n \tline number prefix (when using `-n`)\n+`column`;;\n+\tcolumn number prefix (when using `--column`)\n `match`;;\n \tmatching text (same as setting `matchContext` and `matchSelected`)\n `matchContext`;;\n@@ -1708,6 +1710,9 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex cec4665df5..c48a578cb1 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -44,6 +44,9 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable `-n` option by default.\n \n+grep.column::\n+\tIf set to true, enable the `--column` option by default.\n+\n grep.patternType::\n \tSet the default matching behavior. Using a value of 'basic', 'extended',\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\ndiff --git a/grep.c b/grep.c\nindex 7396b49a2d..5ba1b05526 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -96,6 +96,10 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\topt->linenum = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"grep.column\")) {\n+\t\topt->columnnum = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (!strcmp(var, \"grep.fullname\")) {\n \t\topt->relative = !git_config_bool(var, value);\n@@ -112,6 +116,8 @@ int grep_config(const char *var, const char *value, void *cb)\n \t\tcolor = opt->color_function;\n \telse if (!strcmp(var, \"color.grep.linenumber\"))\n \t\tcolor = opt->color_lineno;\n+\telse if (!strcmp(var, \"color.grep.column\"))\n+\t\tcolor = opt->color_columnno;\n \telse if (!strcmp(var, \"color.grep.matchcontext\"))\n \t\tcolor = opt->color_match_context;\n \telse if (!strcmp(var, \"color.grep.matchselected\"))\n-- \n2.17.0\n\n"},{"id":"347413","messageId":"12381a35b2332950a098b077c312bf587b3db230.1526094383.git.me@ttaylorr.com","threadId":"48339","inReplyTo":"cover.1526094383.git.me@ttaylorr.com","subject":"[PATCH v6 7/7] contrib/git-jump/git-jump: jump to match column in addition to line","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:11:18Z","receivedAt":"2018-05-12T03:11:26Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Take advantage of 'git-grep(1)''s new option, '--column' in order to\nteach Peff's 'git-jump' script how to jump to the correct column for any\ngiven match.\n\n'git-grep(1)''s output is in the correct format for Vim's jump list, so\nno additional cleanup is necessary.\n\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n contrib/git-jump/README   | 12 ++++++++++--\n contrib/git-jump/git-jump |  2 +-\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/git-jump/README b/contrib/git-jump/README\nindex 4484bda410..2f618a7f97 100644\n--- a/contrib/git-jump/README\n+++ b/contrib/git-jump/README\n@@ -25,6 +25,13 @@ git-jump will feed this to the editor:\n foo.c:2: printf(\"hello word!\\n\");\n -----------------------------------\n \n+Or, when running 'git jump grep', column numbers will also be emitted,\n+e.g. `git jump grep \"hello\"` would return:\n+\n+-----------------------------------\n+foo.c:2:9: printf(\"hello word!\\n\");\n+-----------------------------------\n+\n Obviously this trivial case isn't that interesting; you could just open\n `foo.c` yourself. But when you have many changes scattered across a\n project, you can use the editor's support to \"jump\" from point to point.\n@@ -35,7 +42,8 @@ Git-jump can generate four types of interesting lists:\n \n   2. The beginning of any merge conflict markers.\n \n-  3. Any grep matches.\n+  3. Any grep matches, including the column of the first match on a\n+     line.\n \n   4. Any whitespace errors detected by `git diff --check`.\n \n@@ -82,7 +90,7 @@ which does something similar to `git jump grep`. However, it is limited\n to positioning the cursor to the correct line in only the first file,\n leaving you to locate subsequent hits in that file or other files using\n the editor or pager. By contrast, git-jump provides the editor with a\n-complete list of files and line numbers for each match.\n+complete list of files, lines, and a column number for each match.\n \n \n Limitations\ndiff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump\nindex 80ab0590bc..931b0fe3a9 100755\n--- a/contrib/git-jump/git-jump\n+++ b/contrib/git-jump/git-jump\n@@ -52,7 +52,7 @@ mode_merge() {\n # editor shows them to us in the status bar.\n mode_grep() {\n \tcmd=$(git config jump.grepCmd)\n-\ttest -n \"$cmd\" || cmd=\"git grep -n\"\n+\ttest -n \"$cmd\" || cmd=\"git grep -n --column\"\n \t$cmd \"$@\" |\n \tperl -pe '\n \ts/[ \\t]+/ /g;\n-- \n2.17.0\n"},{"id":"347417","messageId":"20180512032733.GA65308@syl.local","threadId":"48339","inReplyTo":"xmqqefikl6jx.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T03:27:33Z","receivedAt":"2018-05-12T03:27:39Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Thu, May 10, 2018 at 09:04:34AM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > This check we should retain and change the wording to mention '--and',\n> > '--or', and '--not' specifically.\n>\n> Why are these problematic in the first place?  If I said\n>\n>     $ git grep -e first --and -e these\n>     $ git grep -e first --and --not -e those\n>     $ git grep -e first --or -e those\n>\n> I'd expect that the first line of this paragraph will hit, and the\n> first hit for these three are \"these\", \"first\" and \"first\",\n> respectively.  Most importantly, in the last one, \"--or\" can be\n> omitted and the whole thing stops being \"extended\", so rejecting\n> extended as a whole does not make much sense.\n\nAgreed that this is what I would expect, too. The trouble is that we\nnever do a compilation step from containing --and, --or, --not to a\nPOSIX regexp. So, if we're extended, we have to assume that there might\nnot be an answer.\n\nGiven this, I don't think we should categorically die() when we\nencounter this (more below in the next hunk of this mail). I think this\nthread has established that there are certainly cases where we cannot\nprovide a meaningful answer, (--not at the top-level, for instance) but\nthere are cases where we can (as you indicate above).\n\nOne day, I would like to support --column with --and, --or, or --not in\ncases where there _is_ a definite answer. That said, omitting this\ninformation for now and at least not die()-ing I think is worth taking\nthis patch earlier, and leaving some #leftoverbits.\n\n>     $ git grep -v second\n>     $ git grep --not -e second\n>\n> may hit all lines in this message (except for the obvious two\n> lines), but we cannot say which column we found a hit.  I am\n> wondering if it is too grave a sin to report \"the whole line is what\n> satisfied the criteria given\" and say the match lies at column #1.\n\nI think that is sensible. I previously was opposed to this because I\nthought that it would be too difficult to script around the 'sometimes\nwe have columns but other times not' and 'I gave --column' but have to\ncheck whether or not they are really there.\n\nI no longer believe that my above argument is sound. It simplifies the\nmatter greatly to simply not share columns when we don't have a good\nanswer, and do when we do.\n\nIn other terms:\n\n  * not giving '--column' will _never_ give a column,\n  * '--column --invert' will _always_ die(), and\n  * '--column --[and | or | not]' will _never_ give a column.\n\nThanks,\nTaylor\n"},{"id":"347418","messageId":"xmqqbmdlfokf.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180512032733.GA65308@syl.local","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-12T05:08:48Z","receivedAt":"2018-05-12T05:08:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n>>     $ git grep -v second\n>>     $ git grep --not -e second\n>>\n>> may hit all lines in this message (except for the obvious two\n>> lines), but we cannot say which column we found a hit.  I am\n>> wondering if it is too grave a sin to report \"the whole line is what\n>> satisfied the criteria given\" and say the match lies at column #1.\n>\n> I think that is sensible. I previously was opposed to this because I\n> thought that it would be too difficult to script around the 'sometimes\n> we have columns but other times not' and 'I gave --column' but have to\n> check whether or not they are really there.\n\nI am not sure if you really got what I meant.  I am suggesting that\n\"git grep -v --column second\" should report that the entire line has\nhit for each and every line that does not have \"second\" on it, which\nis a good answer and eliminate \"sometimes there is column answer (or\nanswer to -o query) and sometimes not\" at the same time.\n\n> In other terms:\n>\n>   * not giving '--column' will _never_ give a column,\n>   * '--column --invert' will _always_ die(), and\n>   * '--column --[and | or | not]' will _never_ give a column.\n\nSo this is completely opposite from what I would have expected. to\nsomebody who said \"I think that is sensible.\" over there.\n\n\n"},{"id":"347419","messageId":"20180512051902.GA70598@syl.local","threadId":"48339","inReplyTo":"xmqqbmdlfokf.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-12T05:19:02Z","receivedAt":"2018-05-12T05:19:08Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sat, May 12, 2018 at 02:08:48PM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> >>     $ git grep -v second\n> >>     $ git grep --not -e second\n> >>\n> >> may hit all lines in this message (except for the obvious two\n> >> lines), but we cannot say which column we found a hit.  I am\n> >> wondering if it is too grave a sin to report \"the whole line is what\n> >> satisfied the criteria given\" and say the match lies at column #1.\n> >\n> > I think that is sensible. I previously was opposed to this because I\n> > thought that it would be too difficult to script around the 'sometimes\n> > we have columns but other times not' and 'I gave --column' but have to\n> > check whether or not they are really there.\n>\n> I am not sure if you really got what I meant.  I am suggesting that\n> \"git grep -v --column second\" should report that the entire line has\n> hit for each and every line that does not have \"second\" on it, which\n> is a good answer and eliminate \"sometimes there is column answer (or\n> answer to -o query) and sometimes not\" at the same time.\n\nI re-read your note and understand more clearly now what your suggestion\nis. To ensure that we're in agreement, do you mean:\n\n  1. '--column -v' will _never_ give a column, but will never die(),\n      either\n\n  2. '--column --[and | or | not]' will never give a column, but will\n      also never die(), either.\n\nI think that _those_ semantics are sensible, and I apologize for\nmisinterpreting your original note.\n\n> > In other terms:\n> >\n> >   * not giving '--column' will _never_ give a column,\n> >   * '--column --invert' will _always_ die(), and\n> >   * '--column --[and | or | not]' will _never_ give a column.\n>\n> So this is completely opposite from what I would have expected. to\n> somebody who said \"I think that is sensible.\" over there.\n\nThanks,\nTaylor\n"},{"id":"347420","messageId":"xmqq7eo9flvb.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180512051902.GA70598@syl.local","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-12T06:07:04Z","receivedAt":"2018-05-12T06:07:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> I re-read your note and understand more clearly now what your suggestion\n> is. To ensure that we're in agreement, do you mean:\n>\n>   1. '--column -v' will _never_ give a column, but will never die(),\n>       either\n\nNo, I don't.\n\n>   2. '--column --[and | or | not]' will never give a column, but will\n>       also never die(), either.\n\nNo, I don't.\n\nIf a file does not have substring \"foo\", then\n\n\tgit grep -v -e foo file\n\tgit grep --not -e foo file\n\nwould hit all lines, just like\n\n\tgit grep -e '.*' file\n\ndoes.\n\nI would expect that all of these\n\n\tgit grep --column/-o -v -e foo file\n\tgit grep --column/-o --not -e foo file\n\tgit grep --column/-o -e '.*' file\n\ngive the same output, which is what we would get if we consider the\nhit from \"choose lines that lack 'foo'\" on a line without 'foo' is\ncaused by the entire contents on the line.  That is in line with\n\"choose lines that has anything (including nothing)\" aka \".*\" would\nresult in the entire line being reported via -o.  The byte offset of\nthe first hit on such a line reported by --column is also 1, and\nthat is a good and real answer to the question \"git grep --column/-o\"\ncan give.  \n\nIn an earlier message, you sounded like you do not think \"we did not\nhave 'foo' on that line, and that is why we are emitting because we\nare operating under -v\" lack a definite answer for --column, but I\nthink you are wrong.  \"On the entire line, we didn't find 'foo'\nanywhere\" is good enough reason for me to make the answer \"the\nentire line contributed to this hit\" a definite one.\n\nExactly the same applies for \"git grep --not -e foo\".\n\nWhen \"git grep -e bar [--or] --not -e foo\" shows a line because the\nline has 'bar' on it, we have --column that points at 'b' of the\nfirst 'bar' on the line.  When it shows a line because the line has\nneither 'bar' or 'foo', then \"--not -e foo\" part would give a\ndefinite \"the entire line contributed to this decision that it does\nnot have 'foo'\".\n\n\n"},{"id":"347967","messageId":"20180518033817.GA61335@syl.local","threadId":"48339","inReplyTo":"xmqq7eo9flvb.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-18T03:38:17Z","receivedAt":"2018-05-18T03:38:25Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sat, May 12, 2018 at 03:07:04PM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > I re-read your note and understand more clearly now what your suggestion\n> > is. To ensure that we're in agreement, do you mean:\n> >\n> >   1. '--column -v' will _never_ give a column, but will never die(),\n> >       either\n>\n> No, I don't.\n>\n> >   2. '--column --[and | or | not]' will never give a column, but will\n> >       also never die(), either.\n>\n> No, I don't.\n>\n> If a file does not have substring \"foo\", then\n>\n> \tgit grep -v -e foo file\n> \tgit grep --not -e foo file\n>\n> would hit all lines, just like\n>\n> \tgit grep -e '.*' file\n>\n> does.\n>\n> I would expect that all of these\n>\n> \tgit grep --column/-o -v -e foo file\n> \tgit grep --column/-o --not -e foo file\n> \tgit grep --column/-o -e '.*' file\n>\n> give the same output, which is what we would get if we consider the\n> hit from \"choose lines that lack 'foo'\" on a line without 'foo' is\n> caused by the entire contents on the line.  That is in line with\n> \"choose lines that has anything (including nothing)\" aka \".*\" would\n> result in the entire line being reported via -o.  The byte offset of\n> the first hit on such a line reported by --column is also 1, and\n> that is a good and real answer to the question \"git grep --column/-o\"\n> can give.\n\nI agree with your message now and thank you for explaining what you\nhad written. I spoke with Peff off-list for a while to determine what I\nthink is essentially the answer to ``what are a set of semantics for\nfilling out a regmatch_t given an extended expression?''\n\nIt's helpful to recognize that the extended expressions are implemented\nvery much like a tree, so a reasonable semantics will lend itself well\nto the way in which match_expr_eval() is implemented. Here's what we\ncame up with:\n\n  * `git grep -e foo`. This is the case where the extended expression\n    has a single atomic node in its tree. This falls into the \"just call\n    match_one_pattern()\" case and has a simple answer: the starting\n    offset and ending offset are that of whatever match_one_pattern\n    gives.\n\n  * `git grep --not -e foo`. This has the set of semantics that you\n    describe above (the starting offset is 1), with the addition that\n    the ending offset is the end of the line. This is similar to the\n    fact that `--not foo` is very similar to `.$`.\n\n  * `git grep --and -e foo -e bar`. This binary operation should recur\n    on its sub-expressions and take the minimum of the starting offset\n    and the maximum of the ending offset.\n\n    For inputs of the form \"foobar\" and \"foo bar\", it will do the right\n    thing (give the starting and ending offset for \"foobar\" and give no\n    match, respectively).\n\n  * `git grep --or -e foo -e bar`. This is the most complicated case, in\n    my opinion. In going with the min/max idea in the and case above, I\n    think that `--or` should also min/max its sub-expressions, but in\n    fact we short-circuit evaluating the second sub-expression when we\n    find a match for the first.\n\n    So, in cases like matching `--or -e foo -e bar` with \"foo baz bar\",\n    we'll do the right thing, since `foo` is the first sub-expression\n    and happens to be the left-most match. In other words, we __adhere\n    to our answer with the left-most match first__ semantics, but only\n    because __the first sub-expression is the left-most match__.\n\n    In the other case where we try and match the same expression against\n    \"bar baz foo\", we'll return the starting offset of \"foo\", even\n    though it isn't the left-most match, violating our semantics.\n\nSo, I propose we adopt the following: use the trivial answer for \"foo\",\nthe whole line for \"--not\", and min/max the starting/ending offsets for\nbinary operators, knowing that we will sometimes produce a weird answer\nfor --or.\n\nI think that the semantics for --or are OK to go forward with, but would\nbe interested in the thoughts of others to figure out whether this is\nsensible to everyone else.\n\nDoes this seem like an OK approach? Perhaps Peff can clarify some of\nwhat's shared here, since we did speak elsewhere about it.\n\nThanks,\nTaylor\n"},{"id":"347970","messageId":"xmqqh8n54gwv.fsf@gitster-ct.c.googlers.com","threadId":"48339","inReplyTo":"20180518033817.GA61335@syl.local","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-18T06:27:44Z","receivedAt":"2018-05-18T06:27:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n>   * `git grep --and -e foo -e bar`. This binary operation should recur\n>     on its sub-expressions and take the minimum of the starting offset\n>     and the maximum of the ending offset.\n\nWe use infix notation, so the above is \"git grep -e foo --and -e\nbar\" actually ;-).\n\nBut you raise an interesting point.  A line with \"hello foo bar baz\"\non it would match, so does a line with \"goodbye bar baz foo\", as\nboth of them hits pattern \"foo\" *and* pattern \"bar\".  It is not\nquite clear what it means to \"show the first hit on the line\".  One\ninterpretation would be to take the minimum span that makes both\nsides of \"--and\" happy (your \"minimum of start, maximum of end\").\nAnother might be to pick \"foo\" in the first and \"bar\" in the second\nline, as that is the \"first hit\" on the line, which is consistent\nwith how \"git grep -e foo\" would say about \"a foo b foo c foo\" (I\nexpect that the leftmost \"foo\" would be the first hit).  So there\nmay be multiple, equally plausible answer to the question.\n\n>     For inputs of the form \"foobar\" and \"foo bar\", it will do the right\n>     thing (give the starting and ending offset for \"foobar\" and give no\n>     match, respectively).\n\nI think I agree with \"foobar\", but I do not understand why there is\nno match for \"foo bar\".\n\n>   * `git grep --or -e foo -e bar`. This is the most complicated case, in\n>     my opinion. In going with the min/max idea in the and case above, I\n>     think that `--or` should also min/max its sub-expressions, but in\n>     fact we short-circuit evaluating the second sub-expression when we\n>     find a match for the first.\n\nI am not sure I follow.  \"git grep -e foo --or -e bar\" is just a\nlonghand for \"git grep -e foo -e bar\".  Shouldn't it highlight\nwhichever between foo and bar that appears leftmost on the line?\n\n>     So, in cases like matching `--or -e foo -e bar` with \"foo baz bar\",\n>     we'll do the right thing, since `foo` is the first sub-expression\n>     and happens to be the left-most match. In other words, we __adhere\n>     to our answer with the left-most match first__ semantics, but only\n>     because __the first sub-expression is the left-most match__.\n>\n>     In the other case where we try and match the same expression against\n>     \"bar baz foo\", we'll return the starting offset of \"foo\", even\n>     though it isn't the left-most match, violating our semantics.\n\nI am not sure why you think your min-starting/max-ending would lead\nto such a conclusion.  'foo baz bar' would be covered in its\nentirety, 'bar baz foo' would also, as starting of hits with pattern\n'foo' and pattern 'bar' would be 'b' in 'bar' on that three-word\nline, and ending of hits with these two patterns would be the last\n'o' in 'foo' on the line.  \n\nI'd expect that a line 'foo baz bar' matched against \"-e foo --or -e\nbar\" would say \"among three words on me, 'f' in foo is the first\nlocation of the match\", though.\n"},{"id":"348009","messageId":"20180518215021.GA36543@syl.local","threadId":"48339","inReplyTo":"xmqqh8n54gwv.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-18T21:50:21Z","receivedAt":"2018-05-18T21:50:29Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Thanks for your thoughtful response. I answered in detail below, but I\nthink that we're in agreement about the semantics, with a few\ncorrections on my part. I'd like to push forward with this series,\nincluding the proposed changes below, but feel that sending it as v7\nwould be asking too much of a reviewer. Would it be OK if I sent this a\nnew series entirely and we abandon this thread?\n\nOn Fri, May 18, 2018 at 03:27:44PM +0900, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> >   * `git grep --and -e foo -e bar`. This binary operation should recur\n> >     on its sub-expressions and take the minimum of the starting offset\n> >     and the maximum of the ending offset.\n>\n> We use infix notation, so the above is \"git grep -e foo --and -e\n> bar\" actually ;-).\n\nThanks for catching that :-).\n\n> But you raise an interesting point.  A line with \"hello foo bar baz\"\n> on it would match, so does a line with \"goodbye bar baz foo\", as\n> both of them hits pattern \"foo\" *and* pattern \"bar\".  It is not\n> quite clear what it means to \"show the first hit on the line\".  One\n> interpretation would be to take the minimum span that makes both\n> sides of \"--and\" happy (your \"minimum of start, maximum of end\").\n\nIt's funny you should mention: this was nearly the exact phrase I used\nwhen speaking with Peff.\n\n> Another might be to pick \"foo\" in the first and \"bar\" in the second\n> line, as that is the \"first hit\" on the line, which is consistent\n> with how \"git grep -e foo\" would say about \"a foo b foo c foo\" (I\n> expect that the leftmost \"foo\" would be the first hit).  So there\n> may be multiple, equally plausible answer to the question.\n\nThis is the largest fact in my mind pertaining to this discussion: there\nare probably many different interpretations of semantics for this, all\nequally valid in their own way. I am partial to the minimum substring\ninterpretation (which follows naturally from the minimum-start,\nmaximum-end idea), accepting the shortcoming that `--or` sometimes\ndoesn't ``do the right thing.''\n\n> >     For inputs of the form \"foobar\" and \"foo bar\", it will do the right\n> >     thing (give the starting and ending offset for \"foobar\" and give no\n> >     match, respectively).\n>\n> I think I agree with \"foobar\", but I do not understand why there is\n> no match for \"foo bar\".\n\nAh, I think this is my mistake -- when I wrote this note last night. The\ncase of `-e foo --and -e bar` should clearly match both `foo bar` _and_\n`foobar`.\n\n> >   * `git grep --or -e foo -e bar`. This is the most complicated case, in\n> >     my opinion. In going with the min/max idea in the and case above, I\n> >     think that `--or` should also min/max its sub-expressions, but in\n> >     fact we short-circuit evaluating the second sub-expression when we\n> >     find a match for the first.\n>\n> I am not sure I follow.  \"git grep -e foo --or -e bar\" is just a\n> longhand for \"git grep -e foo -e bar\".  Shouldn't it highlight\n> whichever between foo and bar that appears leftmost on the line?\n\nI don't believe that the two are treated the same, but I think that this\nis another case where I was incorrect in my judgement of the\nimplementation last night. In fact, the only time when we _don't_ recur\non both sub-expressions of `--or` is when 'collect_hits' is zero. That's\nfine, I believe.\n\n> >     So, in cases like matching `--or -e foo -e bar` with \"foo baz bar\",\n> >     we'll do the right thing, since `foo` is the first sub-expression\n> >     and happens to be the left-most match. In other words, we __adhere\n> >     to our answer with the left-most match first__ semantics, but only\n> >     because __the first sub-expression is the left-most match__.\n> >\n> >     In the other case where we try and match the same expression against\n> >     \"bar baz foo\", we'll return the starting offset of \"foo\", even\n> >     though it isn't the left-most match, violating our semantics.\n>\n> I am not sure why you think your min-starting/max-ending would lead\n> to such a conclusion.  'foo baz bar' would be covered in its\n> entirety, 'bar baz foo' would also, as starting of hits with pattern\n> 'foo' and pattern 'bar' would be 'b' in 'bar' on that three-word\n> line, and ending of hits with these two patterns would be the last\n> 'o' in 'foo' on the line.\n\nRight, I think with the understanding in my last stanza of this response\n(\"I don't believe that ...\") this issue is resolved, and the\nmin-starting/max-ending _will_ do the right thing.\n\n> I'd expect that a line 'foo baz bar' matched against \"-e foo --or -e\n> bar\" would say \"among three words on me, 'f' in foo is the first\n> location of the match\", though.\n\nI would, too.\n\nThanks,\nTaylor\n"},{"id":"348047","messageId":"20180519044428.GA81936@syl.local","threadId":"48339","inReplyTo":"20180518215021.GA36543@syl.local","subject":"Re: [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)'","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2018-05-19T04:44:28Z","receivedAt":"2018-05-19T04:44:35Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, May 18, 2018 at 02:50:21PM -0700, Taylor Blau wrote:\n> [...]\n>\n> > Another might be to pick \"foo\" in the first and \"bar\" in the second\n> > line, as that is the \"first hit\" on the line, which is consistent\n> > with how \"git grep -e foo\" would say about \"a foo b foo c foo\" (I\n> > expect that the leftmost \"foo\" would be the first hit).  So there\n> > may be multiple, equally plausible answer to the question.\n>\n> This is the largest fact in my mind pertaining to this discussion: there\n> are probably many different interpretations of semantics for this, all\n> equally valid in their own way. I am partial to the minimum substring\n> interpretation (which follows naturally from the minimum-start,\n> maximum-end idea), accepting the shortcoming that `--or` sometimes\n> doesn't ``do the right thing.''\n\nIgnore this last part. `--or` _does_ do the right thing, as noted below.\n\nThanks,\nTaylor\n"}]}