Skip to content

Commit 57d4346

Browse files
pcloudsgitster
authored andcommitted
grep: grep cache entries if they are "assume unchanged"
"Assume unchanged" bit means "please pretend that I have never touched this file", so if user removes the file, we should not care. This patch teaches "git grep" to use cache version in such situations. External grep case has not been fixed yet. But given that on the platform that CE_VALID bit may be used like Windows, external grep is not available anyway, I would wait for people to raise their hands before touching it. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e70b9a8 commit 57d4346

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin-grep.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
404404
continue;
405405
if (!pathspec_matches(paths, ce->name))
406406
continue;
407-
if (cached) {
407+
/*
408+
* If CE_VALID is on, we assume worktree file and its cache entry
409+
* are identical, even if worktree file has been modified, so use
410+
* cache version instead
411+
*/
412+
if (cached || (ce->ce_flags & CE_VALID)) {
408413
if (ce_stage(ce))
409414
continue;
410415
hit |= grep_sha1(opt, ce->sha1, ce->name, 0);

t/t7002-grep.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ test_expect_success 'log grep (6)' '
161161
git log --author=-0700 --pretty=tformat:%s >actual &&
162162
>expect &&
163163
test_cmp expect actual
164+
'
164165

166+
test_expect_success 'grep with CE_VALID file' '
167+
git update-index --assume-unchanged t/t &&
168+
rm t/t &&
169+
test "$(git grep --no-ext-grep t)" = "t/t:test" &&
170+
git update-index --no-assume-unchanged t/t &&
171+
git checkout t/t
165172
'
166173

167174
test_done

0 commit comments

Comments
 (0)