git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 1/2] grep: --full-tree

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Mar 1, 2011, 09:53 UTC
Message-ID
<f179d6fa62001ada34a4236327eda985e09416b1.1298972832.git.git@drmicha.warpmail.net>
In-Reply-To
<AANLkTi=xrnxUtkayyW1Merh49N6uHy5p-GMrYe6+p==t@mail.gmail.com>
From: Junio C Hamano <gitster@pobox.com>

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>
---
 builtin/grep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 5afee2f..d005528 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -728,6 +728,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 {
 	int hit = 0;
 	int cached = 0;
+	int full_tree = 0;
 	int seen_dashdash = 0;
 	int external_grep_allowed__ignored;
 	const char *show_in_pager = NULL, *default_pager = "dummy";
@@ -773,6 +774,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,
@@ -957,7 +960,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.7.4.1.257.gb09fa
Previous: Michael J GruberNext: Michael J Gruber
Message 13 of 46 in “git-grep to operate across who repository and not just CWD?”
  1. David ChantersFeb 28, 2011
  2. Michael J GruberFeb 28, 2011
  3. Jay SoffianFeb 28, 2011
  4. Junio C HamanoFeb 28, 2011
  5. Junio C HamanoFeb 28, 2011
  6. Phil HordFeb 28, 2011
  7. Michael J GruberMar 1, 2011
  8. Nguyen Thai Ngoc DuyMar 1, 2011
  9. Michael J GruberMar 1, 2011
  10. Nguyen Thai Ngoc DuyMar 1, 2011
  11. Nguyen Thai Ngoc DuyMar 1, 2011
  12. 0/2 grep --full-treeMichael J Gruber, Mar 1, 2011
  13. 1/2 grep: --full-treeMichael J Gruber, Mar 1, 2011
  14. 2/2 grep: make --full-tree work with pathspecsMichael J Gruber, Mar 1, 2011
  15. Junio C HamanoMar 1, 2011
  16. setup.c: denote repo wide pathspecs by ':'Michael J Gruber, Mar 1, 2011
  17. Nguyen Thai Ngoc DuyMar 1, 2011
  18. Michael J GruberMar 1, 2011
  19. Nguyen Thai Ngoc DuyMar 1, 2011
  20. Michael J GruberMar 1, 2011
  21. Nguyen Thai Ngoc DuyMar 1, 2011
  22. Junio C HamanoMar 1, 2011
  23. Michael J GruberMar 1, 2011
  24. Junio C HamanoMar 1, 2011
  25. Sverre RabbelierMar 2, 2011
  26. Nguyen Thai Ngoc DuyMar 2, 2011
  27. Michael J GruberMar 2, 2011
  28. Junio C HamanoMar 2, 2011
  29. Michael J GruberMar 2, 2011
  30. Miles BaderMar 3, 2011
  31. Junio C HamanoMar 3, 2011
  32. Phil HordMar 3, 2011
  33. Michael J GruberMar 3, 2011
  34. Phil HordMar 1, 2011
  35. James PickensMar 1, 2011
  36. Nguyen Thai Ngoc DuyMar 2, 2011
  37. Phil HordMar 3, 2011
  38. Michael J GruberMar 3, 2011
  39. Michael J GruberMar 1, 2011
  40. Phil HordMar 1, 2011
  41. pathspec: reserve some letters after a colon pathspecNguyễn Thái Ngọc Duy, Mar 23, 2011
  42. Junio C HamanoMar 23, 2011
  43. Michael J GruberMar 24, 2011
  44. Nguyen Thai Ngoc DuyMar 24, 2011
  45. Junio C HamanoMar 24, 2011
  46. Junio C HamanoMar 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.