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

[RFC 2/2] grep: use '/' delimiter for paths

From
SHStefan Hajnoczi <stefanha@redhat.com>
Date
Jan 19, 2017, 15:03 UTC
Message-ID
<20170119150347.3484-3-stefanha@redhat.com>
In-Reply-To
<20170119150347.3484-1-stefanha@redhat.com>

If the tree contains a sub-directory then git-grep(1) output contains a colon character instead of a path separator:

  $ git grep malloc v2.9.3:t
  v2.9.3:t:test-lib.sh:	setup_malloc_check () {
  $ git show v2.9.3:t:test-lib.sh
  fatal: Path 't:test-lib.sh' does not exist in 'v2.9.3'
This patch attempts to use the correct delimiter:
  $ git grep malloc v2.9.3:t
  v2.9.3:t/test-lib.sh:	setup_malloc_check () {
  $ git show v2.9.3:t/test-lib.sh
  (success)

This patch does not cope with @{1979-02-26 18:30:00} syntax and treats it as a path because it contains colons.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 builtin/grep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 3643d8a..06f8b47 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -493,7 +493,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
 
 			/* Add a delimiter if there isn't one already */
 			if (name[len - 1] != '/' && name[len - 1] != ':') {
-				strbuf_addch(&base, ':');
+				/* rev: or rev:path/ */
+				strbuf_addch(&base, strchr(name, ':') ? '/' : ':');
 			}
 		}
 		init_tree_desc(&tree, data, size);
-- 
2.9.3
Previous: Stefan HajnocziNext: Junio C Hamano
Message 2 of 21 in “[RFC 0/2] grep: make output consistent with revision syntax”
  1. Stefan HajnocziJan 19, 2017
  2. 2/2 grep: use '/' delimiter for pathsStefan Hajnoczi, Jan 19, 2017
  3. Junio C HamanoJan 19, 2017
  4. Stefan HajnocziJan 20, 2017
  5. Jeff KingJan 20, 2017
  6. Junio C HamanoJan 20, 2017
  7. Stefan HajnocziJan 23, 2017
  8. Phil HordJan 24, 2017
  9. Brandon WilliamsJan 19, 2017
  10. Stefan HajnocziJan 20, 2017
  11. 1/2 grep: only add delimiter if there isn't one alreadyStefan Hajnoczi, Jan 19, 2017
  12. Junio C HamanoJan 19, 2017
  13. Stefan HajnocziJan 20, 2017
  14. Junio C HamanoJan 20, 2017
  15. Stefan HajnocziJan 23, 2017
  16. Jakub NarębskiJan 24, 2017
  17. Philip OakleyJan 24, 2017
  18. Jeff KingJan 19, 2017
  19. Brandon WilliamsJan 19, 2017
  20. Stefan HajnocziJan 20, 2017
  21. Jeff KingJan 20, 2017

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.