git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: avarab@gmail.com, gitster@pobox.com, l.s.r@web.de,
	martin.agren@gmail.com, peff@peff.net, sunshine@sunshineco.com
Subject: [PATCH v3 0/7] Teach '--column-number' to 'git-grep(1)'
Date: Mon, 23 Apr 2018 22:07:34 -0700	[thread overview]
Message-ID: <cover.1524545768.git.me@ttaylorr.com> (raw)
In-Reply-To: <20180421034530.GB24606@syl.local>

Hi,

Attached is v3 of my series to teach '--column-numbers' to 'git-grep(1)'.

Since last time, I have:

  * Removed '-m' in a few places that I forgot to during v2 [1] [2].

  * Expanded upon the definition of '--column-number' in 'git grep
    --help'. [3]

  * Initialized some new fields in grep_opt to 0 that would be avoided
    by memset(). [4]

  * Block comment to indicate the desired use of 'cno' in grep.c's
    'show_line()' [5], [6].

  * Annotated the new tests with the permutation that they are testing.

The most notable change since last time is reorganizing the series to
match Eric's suggestion, which I hope makes the reviewing experience a
little easier. I will strive to apply these lessons in future series.

Little has changed on the implementation front since v2, so I think that
the most outstanding further discussion will be centered around --column
vs --column-number. I have posted some thoughts about that in [7].

Thanks as always for your review :-).


Thanks,
Taylor

[1]: https://public-inbox.org/git/878t9eewu2.fsf@evledraar.gmail.com
[2]: https://public-inbox.org/git/877eoyewss.fsf@evledraar.gmail.com
[3]: https://public-inbox.org/git/878t9eewu2.fsf@evledraar.gmail.com
[4]: https://public-inbox.org/git/CAPig+cRXkSrPHPyEEhp6_ndRBNW3hE7HkspSk1atPSE5pn_sMw@mail.gmail.com
[5]: https://public-inbox.org/git/CAPig+cQ2+wTTXE0mhnGnp2pZug=Po0SCVwCO_2agxUDaOsFRLw@mail.gmail.com
[6]: https://public-inbox.org/git/CAPig+cR0unM2uKcapHyAFrvMyPx4VgsW4wDswb_GNwE4EcYb8Q@mail.gmail.com
[7]: https://public-inbox.org/git/20180424043140.GA82406@syl.local

Taylor Blau (7):
  Documentation/config.txt: camel-case lineNumber for consistency
  grep.c: expose matched column in match_line()
  grep.[ch]: extend grep_opt to allow showing matched column
  grep.c: display column number of first match
  builtin/grep.c: add '--column-number' option to 'git-grep(1)'
  grep.c: add configuration variables to show matched option
  contrib/git-jump/git-jump: jump to match column in addition to line

 Documentation/config.txt   |  7 ++++++-
 Documentation/git-grep.txt |  8 +++++++-
 builtin/grep.c             |  1 +
 contrib/git-jump/git-jump  |  2 +-
 grep.c                     | 39 +++++++++++++++++++++++++++++---------
 grep.h                     |  2 ++
 t/t7810-grep.sh            | 22 +++++++++++++++++++++
 7 files changed, 69 insertions(+), 12 deletions(-)

Inter-diff (since v2):

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1645fcf2ae..8a2893d1e1 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1711,7 +1711,7 @@ grep.lineNumber::
 	If set to true, enable `-n` option by default.

 grep.columnNumber::
-	If set to true, enable `-m` option by default.
+	If set to true, enable the `--column-number` option by default.

 grep.patternType::
 	Set the default matching behavior. Using a value of 'basic', 'extended',
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index b75a039768..c5c4d712e6 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -45,7 +45,7 @@ grep.lineNumber::
 	If set to true, enable `-n` option by default.

 grep.columnNumber::
-	If set to true, enable `-m` option by default.
+	If set to true, enable the `--column-number` option by default.

 grep.patternType::
 	Set the default matching behavior. Using a value of 'basic', 'extended',
diff --git a/builtin/grep.c b/builtin/grep.c
index 23ce97f998..512f60c591 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -829,7 +829,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			    GREP_PATTERN_TYPE_PCRE),
 		OPT_GROUP(""),
 		OPT_BOOL('n', "line-number", &opt.linenum, N_("show line numbers")),
-		OPT_BOOL(0, "column-number", &opt.columnnum, N_("show column numbers")),
+		OPT_BOOL(0, "column-number", &opt.columnnum, N_("show column number of first match")),
 		OPT_NEGBIT('h', NULL, &opt.pathname, N_("don't show filenames"), 1),
 		OPT_BIT('H', NULL, &opt.pathname, N_("show filenames"), 1),
 		OPT_NEGBIT(0, "full-name", &opt.relative,
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 2706963690..8bc57ea0f8 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -52,7 +52,7 @@ mode_merge() {
 # editor shows them to us in the status bar.
 mode_grep() {
 	cmd=$(git config jump.grepCmd)
-	test -n "$cmd" || cmd="git grep -n -m"
+	test -n "$cmd" || cmd="git grep -n --column-number"
 	$cmd "$@" |
 	perl -pe '
 	s/[ \t]+/ /g;
diff --git a/grep.c b/grep.c
index 23250e60d0..7284dec155 100644
--- a/grep.c
+++ b/grep.c
@@ -46,6 +46,7 @@ void init_grep_defaults(void)
 	color_set(opt->color_filename, "");
 	color_set(opt->color_function, "");
 	color_set(opt->color_lineno, "");
+	color_set(opt->color_columnno, "");
 	color_set(opt->color_match_context, GIT_COLOR_BOLD_RED);
 	color_set(opt->color_match_selected, GIT_COLOR_BOLD_RED);
 	color_set(opt->color_selected, "");
@@ -1404,6 +1405,11 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 		output_color(opt, buf, strlen(buf), opt->color_lineno);
 		output_sep(opt, sign);
 	}
+	/**
+	 * Treat 'cno' as the 1-indexed offset from the start of a non-context
+	 * line to its first match. Otherwise, 'cno' is 0 indicating that we are
+	 * being called with a context line.
+	 */
 	if (opt->columnnum && cno) {
 		char buf[32];
 		xsnprintf(buf, sizeof(buf), "%d", cno);
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 7349c7fadc..bbce57c8b1 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -99,7 +99,7 @@ do
 		test_cmp expected actual
 	'

-	test_expect_success "grep -w $L" '
+	test_expect_success "grep -w $L (with --column-number)" '
 		{
 			echo ${HC}file:5:foo mmap bar
 			echo ${HC}file:14:foo_mmap bar mmap
@@ -110,7 +110,7 @@ do
 		test_cmp expected actual
 	'

-	test_expect_success "grep -w $L" '
+	test_expect_success "grep -w $L (with --{line,column}-number)" '
 		{
 			echo ${HC}file:1:5:foo mmap bar
 			echo ${HC}file:3:14:foo_mmap bar mmap

--
2.17.0

  parent reply	other threads:[~2018-04-24  5:07 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1524281843.git.me@ttaylorr.com>
2018-04-21  3:45 ` [PATCH 1/6] grep.c: take regmatch_t as argument in match_line() Taylor Blau
2018-04-22 20:47   ` [PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)' Taylor Blau
2018-04-22 20:47     ` [PATCH v2 1/6] grep.c: take regmatch_t as argument in match_line() Taylor Blau
2018-04-22 23:14       ` Eric Sunshine
2018-04-22 23:30         ` Taylor Blau
2018-04-22 20:47     ` [PATCH v2 2/6] grep.c: take column number as argument to show_line() Taylor Blau
2018-04-23  0:16       ` Eric Sunshine
2018-04-23  1:17         ` Taylor Blau
2018-04-23  3:30           ` Eric Sunshine
2018-04-23  7:27             ` Ævar Arnfjörð Bjarmason
2018-04-23  7:34               ` Eric Sunshine
2018-04-24  4:27                 ` Taylor Blau
2018-04-23  8:01           ` Ævar Arnfjörð Bjarmason
2018-04-24  4:31             ` Taylor Blau
2018-04-24  6:13             ` Junio C Hamano
2018-04-24 18:34               ` Taylor Blau
2018-04-22 20:47     ` [PATCH v2 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt Taylor Blau
2018-04-22 21:42       ` Ævar Arnfjörð Bjarmason
2018-04-22 23:24         ` Taylor Blau
2018-04-23  0:21           ` Eric Sunshine
2018-04-23  1:11             ` Taylor Blau
2018-04-22 20:47     ` [PATCH v2 4/6] grep.c: display column number of first match Taylor Blau
2018-04-23  0:24       ` Eric Sunshine
2018-04-23  1:12         ` Taylor Blau
2018-04-22 20:47     ` [PATCH v2 5/6] builtin/grep.c: show column numbers via --column-number Taylor Blau
2018-04-22 21:48       ` Ævar Arnfjörð Bjarmason
2018-04-22 23:26         ` Taylor Blau
2018-04-23  0:32       ` Eric Sunshine
2018-04-23  1:14         ` Taylor Blau
2018-04-22 20:47     ` [PATCH v2 6/6] contrib/git-jump/git-jump: use column number when grep-ing Taylor Blau
2018-04-22 21:49       ` Ævar Arnfjörð Bjarmason
2018-04-22 23:27         ` Taylor Blau
2018-04-22 23:28     ` [PATCH v2 0/6] Teach '--column-number' to 'git-grep(1)' Junio C Hamano
2018-04-22 23:34       ` Taylor Blau
2018-04-23 13:46         ` Junio C Hamano
2018-04-24  5:07   ` Taylor Blau [this message]
2018-04-24  5:07     ` [PATCH v3 1/7] Documentation/config.txt: camel-case lineNumber for consistency Taylor Blau
2018-04-24  5:07     ` [PATCH v3 2/7] grep.c: expose matched column in match_line() Taylor Blau
2018-04-24  5:07     ` [PATCH v3 3/7] grep.[ch]: extend grep_opt to allow showing matched column Taylor Blau
2018-04-24  5:07     ` [PATCH v3 4/7] grep.c: display column number of first match Taylor Blau
2018-04-24  5:42       ` Eric Sunshine
2018-04-24  5:07     ` [PATCH v3 5/7] builtin/grep.c: add '--column-number' option to 'git-grep(1)' Taylor Blau
2018-04-24  5:07     ` [PATCH v3 6/7] grep.c: add configuration variables to show matched option Taylor Blau
2018-04-24  5:07     ` [PATCH v3 7/7] contrib/git-jump/git-jump: jump to match column in addition to line Taylor Blau
2018-04-24  5:37       ` Eric Sunshine
2018-04-24 18:39         ` Taylor Blau
2018-05-05  2:42   ` [PATCH v4 0/7] Teach '--column' to 'git-grep(1)' Taylor Blau
2018-05-05  2:42     ` [PATCH v4 1/7] Documentation/config.txt: camel-case lineNumber for consistency Taylor Blau
2018-05-05  2:42     ` [PATCH v4 2/7] grep.c: expose matched column in match_line() Taylor Blau
2018-05-08  6:08       ` René Scharfe
2018-05-05  2:42     ` [PATCH v4 3/7] grep.[ch]: extend grep_opt to allow showing matched column Taylor Blau
2018-05-05  2:43     ` [PATCH v4 4/7] grep.c: display column number of first match Taylor Blau
2018-05-05  2:43     ` [PATCH v4 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)' Taylor Blau
2018-05-05  6:15       ` Duy Nguyen
2018-05-07 23:38         ` Taylor Blau
2018-05-06 17:43       ` Phillip Wood
2018-05-06 17:56       ` Ævar Arnfjörð Bjarmason
2018-05-07 23:40         ` Taylor Blau
2018-05-07 14:13       ` Junio C Hamano
2018-05-08  0:08         ` Taylor Blau
2018-05-05  2:43     ` [PATCH v4 6/7] grep.c: add configuration variables to show matched option Taylor Blau
2018-05-05  2:43     ` [PATCH v4 7/7] contrib/git-jump/git-jump: jump to match column in addition to line Taylor Blau
2018-05-06 14:43       ` Martin Ågren
2018-05-06 18:03         ` Ævar Arnfjörð Bjarmason
2018-05-07 23:35           ` Taylor Blau
2018-05-09  2:13   ` [PATCH v5 0/7] Teach '--column' to 'git-grep(1)' Taylor Blau
2018-05-09  2:13     ` [PATCH v5 1/7] Documentation/config.txt: camel-case lineNumber for consistency Taylor Blau
2018-05-09  2:13     ` [PATCH v5 2/7] grep.c: expose matched column in match_line() Taylor Blau
2018-05-09  2:13     ` [PATCH v5 3/7] grep.[ch]: extend grep_opt to allow showing matched column Taylor Blau
2018-05-09  2:13     ` [PATCH v5 4/7] grep.c: display column number of first match Taylor Blau
2018-05-09  2:13     ` [PATCH v5 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)' Taylor Blau
2018-05-09 10:41       ` Phillip Wood
2018-05-09 17:26         ` Martin Ågren
2018-05-09 23:52           ` Taylor Blau
2018-05-10  0:04             ` Junio C Hamano
2018-05-10  5:58               ` René Scharfe
2018-05-10  6:43                 ` Junio C Hamano
2018-05-12  3:27               ` Taylor Blau
2018-05-12  5:08                 ` Junio C Hamano
2018-05-12  5:19                   ` Taylor Blau
2018-05-12  6:07                     ` Junio C Hamano
2018-05-18  3:38                       ` Taylor Blau
2018-05-18  6:27                         ` Junio C Hamano
2018-05-18 21:50                           ` Taylor Blau
2018-05-19  4:44                             ` Taylor Blau
2018-05-09 23:49         ` Taylor Blau
2018-05-09 16:17       ` Duy Nguyen
2018-05-09 23:48         ` Taylor Blau
2018-05-09  2:13     ` [PATCH v5 6/7] grep.c: add configuration variables to show matched option Taylor Blau
2018-05-09  2:13     ` [PATCH v5 7/7] contrib/git-jump/git-jump: jump to match column in addition to line Taylor Blau
2018-05-12  3:10   ` [PATCH v6 0/7] Teach '--column' to 'git-grep(1)' Taylor Blau
2018-05-12  3:11     ` [PATCH v6 1/7] Documentation/config.txt: camel-case lineNumber for consistency Taylor Blau
2018-05-12  3:11     ` [PATCH v6 2/7] grep.c: expose matched column in match_line() Taylor Blau
2018-05-12  3:11     ` [PATCH v6 3/7] grep.[ch]: extend grep_opt to allow showing matched column Taylor Blau
2018-05-12  3:11     ` [PATCH v6 4/7] grep.c: display column number of first match Taylor Blau
2018-05-12  3:11     ` [PATCH v6 5/7] builtin/grep.c: add '--column' option to 'git-grep(1)' Taylor Blau
2018-05-12  3:11     ` [PATCH v6 6/7] grep.c: add configuration variables to show matched option Taylor Blau
2018-05-12  3:11     ` [PATCH v6 7/7] contrib/git-jump/git-jump: jump to match column in addition to line Taylor Blau
2018-04-21  3:45 ` [PATCH 2/6] grep.c: take column number as argument to show_line() Taylor Blau
2018-04-21  3:45 ` [PATCH 3/6] grep.[ch]: teach columnnum, color_columnno to grep_opt Taylor Blau
2018-04-21  8:32   ` Martin Ågren
2018-04-21  3:45 ` [PATCH 4/6] grep.c: display column number of first match Taylor Blau
2018-04-21  3:45 ` [PATCH 5/6] builtin/grep.c: show column numbers via --column-number Taylor Blau
2018-04-21  4:07   ` Junio C Hamano
2018-04-21  4:14     ` Junio C Hamano
2018-04-21  5:36       ` René Scharfe
2018-04-21  8:39   ` Martin Ågren
2018-04-21  3:45 ` [PATCH 6/6] contrib/git-jump/git-jump: use column number when grep-ing Taylor Blau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1524545768.git.me@ttaylorr.com \
    --to=me@ttaylorr.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=martin.agren@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).