Skip to content

Commit 9905382

Browse files
stefanhaRHgitster
authored andcommitted
grep: use '/' delimiter for paths
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) Signed-off-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 257ad08 commit 9905382

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

builtin/grep.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,9 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
814814

815815
/* Add a delimiter if there isn't one already */
816816
if (name[len - 1] != '/' && name[len - 1] != ':') {
817-
strbuf_addch(&base, ':');
817+
/* rev: or rev:path/ */
818+
char delim = obj->type == OBJ_COMMIT ? ':' : '/';
819+
strbuf_addch(&base, delim);
818820
}
819821
}
820822
init_tree_desc(&tree, data, size);

t/t7810-grep.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,11 @@ test_expect_success 'grep outputs valid <rev>:<path> for HEAD:t/' '
14451445
test_cmp expected actual
14461446
'
14471447

1448+
test_expect_success 'grep outputs valid <rev>:<path> for HEAD:t' '
1449+
git grep vvv HEAD:t >actual &&
1450+
test_cmp expected actual
1451+
'
1452+
14481453
cat >expected <<EOF
14491454
HEAD:t/a/v:vvv
14501455
HEAD:t/v:vvv

0 commit comments

Comments
 (0)