All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 12/12] grep: support column output with --columns
Date: Sun,  7 Mar 2010 19:09:45 +0700	[thread overview]
Message-ID: <1267963785-473-13-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1267963785-473-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-grep.txt |   10 ++++++++++
 builtin/grep.c             |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 4b32322..7bd6a4f 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -18,6 +18,7 @@ SYNOPSIS
 	   [-c | --count] [--all-match] [-q | --quiet]
 	   [--max-depth <depth>]
 	   [--color[=<when>] | --no-color]
+	   [--columns | --no-columns]
 	   [-A <post-context>] [-B <pre-context>] [-C <context>]
 	   [-f <file>] [-e] <pattern>
 	   [--and|--or|--not|(|)|-e <pattern>...]
@@ -123,6 +124,15 @@ OPTIONS
 	gives the default to color output.
 	Same as `--color=never`.
 
+--columns::
+	Show matched files in columns. This option is only applicable when
+	used with --name-only or --files-without-match.
+
+--no-columns::
+	Show matched files in a single list.  This option is used to
+	override core.columns if set. This option is only applicable
+	when used with --name-only or --files-without-match.
+
 -[ABC] <context>::
 	Show `context` trailing (`A` -- after), or leading (`B`
 	-- before), or both (`C` -- context) lines, and place a
diff --git a/builtin/grep.c b/builtin/grep.c
index b8a1d5c..48c8c57 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -15,6 +15,7 @@
 #include "grep.h"
 #include "quote.h"
 #include "dir.h"
+#include "column.h"
 
 #ifndef NO_PTHREADS
 #include "thread-utils.h"
@@ -759,6 +760,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	int cached = 0;
 	int seen_dashdash = 0;
 	int external_grep_allowed__ignored;
+	int column_output = 0;
 	struct grep_opt opt;
 	struct object_array list = { 0, 0, NULL };
 	const char **paths = NULL;
@@ -849,6 +851,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			    "allow calling of grep(1) (ignored by this build)"),
 		{ OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage",
 		  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback },
+		OPT_BOOLEAN(0, "columns", &column_output, "show match files in columns"),
 		OPT_END()
 	};
 
@@ -876,6 +879,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	git_config(grep_config, &opt);
 	if (opt.color == -1)
 		opt.color = git_use_color_default;
+	column_output = core_column_output;
 
 	/*
 	 * If there is no -- then the paths must exist in the working
@@ -967,6 +971,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		paths[1] = NULL;
 	}
 
+	if (opt.name_only && column_output)
+		start_columnizer(NULL);
+
 	if (!use_index) {
 		if (cached)
 			die("--cached cannot be used with --no-index.");
@@ -1002,5 +1009,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		free_grep_patterns(&opt);
 	}
 
+	if (opt.name_only && column_output)
+		stop_columnizer();
 	return !hit;
 }
-- 
1.7.0.1.370.gd3c5

  parent reply	other threads:[~2010-03-07 12:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-07 12:09 [PATCH 00/12] Support columinized output in tag/branch/ls-files/grep Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 01/12] Move term_columns() to pager.c Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 02/12] setup_pager(): save terminal width before redirecting stdout Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 03/12] Add columnizer Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 04/12] help: use columnizer Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 05/12] Add builtin command "column" Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 06/12] Add helpers to redirect stdout to "git column" Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 07/12] add core.columns Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 08/12] tag: support column output with --columns Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 09/12] branch: " Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 10/12] ls-files: " Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` [PATCH 11/12] grep: do not return early in cmd_grep() if there is no error Nguyễn Thái Ngọc Duy
2010-03-07 12:09 ` Nguyễn Thái Ngọc Duy [this message]
2010-03-08 14:08 ` [PATCH 00/12] Support columinized output in tag/branch/ls-files/grep René Scharfe
2010-03-08 14:32   ` Nguyen Thai Ngoc Duy
2010-03-09 16:49     ` René Scharfe
2010-03-10  0:27       ` Nguyen Thai Ngoc Duy
2010-03-10  7:26         ` Johannes Sixt
2010-03-10 12:12           ` Nguyen Thai Ngoc Duy
2010-03-11 21:13         ` René Scharfe
2010-03-12  4:22           ` Nguyen Thai Ngoc Duy
2010-03-08 23:08   ` Junio C Hamano
2010-03-09  2:06     ` Nguyen Thai Ngoc Duy
2010-03-09  2:14       ` Junio C Hamano

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=1267963785-473-13-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.