git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] grep: --full-tree
@ 2009-11-24  8:56 Junio C Hamano
  2009-11-25 13:16 ` Michael J Gruber
                   ` (2 more replies)
  0 siblings, 3 replies; 68+ messages in thread
From: Junio C Hamano @ 2009-11-24  8:56 UTC (permalink / raw)
  To: git

While working inside a deep subdirectory, it sometimes is necessary to
find a string you see in a file you are working on from the files in the
entire project.  This is especially true when you are dipping your toe
into an unfamiliar project.

By default, "git grep" limits its search space to the current directory
and below (i.e. as if "-r ." is specified), and it is rather cumbersome to
repeat ../ as many times as necessary.  This new option tells "git grep"
not to limit the search space to the current directory.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * In http://article.gmane.org/gmane.comp.version-control.git/111717, I
   once argued in the opposite way, but I think it is Ok to aim for making
   the default --full-tree in the longer run (cf. $gmane/127885).  This is
   the first step in that direction.

   I am not sure if there can be a sane way to flip the default without
   hurting existing scripts and users.  Backward compatibility always is
   a pain.

 builtin-grep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 761799d..5787f35 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -693,6 +693,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 {
 	int hit = 0;
 	int cached = 0;
+	int full_tree = 0;
 	int external_grep_allowed = 1;
 	int seen_dashdash = 0;
 	struct grep_opt opt;
@@ -732,6 +733,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		OPT_BIT('H', NULL, &opt.pathname, "show filenames", 1),
 		OPT_NEGBIT(0, "full-name", &opt.relative,
 			"show filenames relative to top directory", 1),
+		OPT_BIT(0, "full-tree", &full_tree,
+			"search from the top of the tree", 1),
 		OPT_BOOLEAN('l', "files-with-matches", &opt.name_only,
 			"show only filenames instead of matching lines"),
 		OPT_BOOLEAN(0, "name-only", &opt.name_only,
@@ -862,7 +865,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 
 	if (i < argc)
 		paths = get_pathspec(prefix, argv + i);
-	else if (prefix) {
+	else if (prefix && !full_tree) {
 		paths = xcalloc(2, sizeof(const char *));
 		paths[0] = prefix;
 		paths[1] = NULL;
-- 
1.6.6.rc0.47.g1fdffa.dirty

^ permalink raw reply related	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2009-11-29 19:51 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-24  8:56 [PATCH] grep: --full-tree Junio C Hamano
2009-11-25 13:16 ` Michael J Gruber
2009-11-25 19:32   ` Junio C Hamano
2009-11-25 14:56 ` Sverre Rabbelier
2009-11-25 19:32   ` Junio C Hamano
2009-11-25 20:19     ` Sverre Rabbelier
2009-11-25 20:23       ` Junio C Hamano
2009-11-25 20:46         ` Sverre Rabbelier
2009-11-25 23:31           ` Johannes Schindelin
2009-11-25 23:29             ` Sverre Rabbelier
2009-11-25 20:52     ` Jeff King
2009-11-25 20:39 ` Jeff King
2009-11-25 20:52   ` Junio C Hamano
2009-11-25 21:00     ` Jeff King
2009-11-25 21:33       ` Junio C Hamano
2009-11-25 21:49         ` Jeff King
2009-11-25 22:12           ` James Pickens
2009-11-25 22:20             ` Jeff King
2009-11-26 17:56               ` James Pickens
2009-11-27  6:20                 ` Jeff King
2009-11-27  8:18                   ` Junio C Hamano
2009-11-27  9:31                   ` Johannes Schindelin
2009-11-27  9:59                     ` Jeff King
2009-11-27 10:53                       ` Johannes Schindelin
2009-11-27 16:27                         ` Uri Okrent
2009-11-27 18:29                           ` Junio C Hamano
2009-11-27 18:47                             ` Uri Okrent
2009-11-27 20:53                               ` Jeff King
2009-11-29 19:50                                 ` Uri Okrent
2009-11-29 11:48                             ` Felipe Contreras
2009-11-27 18:02                         ` Jeff King
2009-11-27 20:07                           ` Johannes Schindelin
2009-11-27 21:05                             ` Jeff King
2009-11-29 10:28                               ` Johannes Schindelin
2009-11-29 18:32                                 ` Jeff King
2009-11-29 19:49                                   ` Junio C Hamano
2009-11-29 12:13                             ` Felipe Contreras
2009-11-27 18:29                       ` Junio C Hamano
2009-11-27 20:50                         ` Jeff King
2009-11-29 10:21                           ` Johannes Schindelin
2009-11-29 18:24                             ` Jeff King
2009-11-27 10:37                     ` Matthieu Moy
2009-11-27 10:56                       ` Johannes Schindelin
2009-11-25 22:26             ` Wincent Colaiuta
2009-11-26  0:00               ` Junio C Hamano
2009-11-26  0:16                 ` A Large Angry SCM
2009-11-26  0:20                   ` Junio C Hamano
2009-11-26  0:30                     ` A Large Angry SCM
2009-11-26  0:36                       ` Junio C Hamano
2009-11-26 18:14                 ` James Pickens
2009-11-25 22:19           ` Junio C Hamano
2009-11-25 22:26             ` Jeff King
2009-11-25 22:41               ` A Large Angry SCM
2009-11-25 22:53                 ` Jeff King
2009-11-25 23:07                   ` A Large Angry SCM
2009-11-25 23:22                     ` Jeff King
2009-11-29 11:38                       ` Felipe Contreras
2009-11-29 19:45                         ` Uri Okrent
2009-11-26  0:02               ` Junio C Hamano
2009-11-27  6:22                 ` Jeff King
2009-11-25 22:15         ` A Large Angry SCM
2009-11-25 22:21           ` Junio C Hamano
2009-11-25 22:31             ` A Large Angry SCM
2009-11-25 22:43               ` A Large Angry SCM
2009-11-25 23:34         ` Johannes Schindelin
2009-11-25 23:41           ` Junio C Hamano
2009-11-26  0:04             ` Johannes Schindelin
2009-11-26  0:13               ` Junio C Hamano

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).