[RFC 2/2] grep: use '/' delimiter for paths
- From
- Stefan 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