{"thread":{"id":"16880","subject":"[PATCH 2/2] grep: grep cache entries if they are \"assume unchanged\"","startedAt":"2008-12-27T08:21:03Z","lastAt":"2008-12-28T06:53:37Z","messageCount":4,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"98776","messageId":"1230366064-1306-1-git-send-email-pclouds@gmail.com","threadId":"16880","inReplyTo":null,"subject":"[PATCH 2/2] grep: grep cache entries if they are \"assume unchanged\"","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-12-27T08:21:03Z","receivedAt":"2008-12-27T08:21:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"Assume unchanged\" bit means \"please pretend that I have never touched\nthis file\", so  if user removes the file, we should not care.\n\nThis patch teaches \"git grep\" to use cache version in such\nsituations. External grep case has not been fixed yet. But given that\non the platform that CE_VALID bit may be used like Windows, external\ngrep is not available anyway, I would wait for people to raise their\nhands before touching it.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n I will do git-grep fixes for sparse checkout later because it will require\n nd/narrow. This series does not, so it can be applied separatedly.\n\n builtin-grep.c  |    7 ++++++-\n t/t7002-grep.sh |    7 +++++++\n 2 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 3c97c2c..bebf15c 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -404,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)\n \t\t\tcontinue;\n \t\tif (!pathspec_matches(paths, ce->name))\n \t\t\tcontinue;\n-\t\tif (cached) {\n+\t\t/*\n+\t\t * If CE_VALID is on, we assume worktree file and its cache entry\n+\t\t * are identical, even if worktree file has been modified, so use\n+\t\t * cache version instead\n+\t\t */\n+\t\tif (cached || (ce->ce_flags & CE_VALID)) {\n \t\t\tif (ce_stage(ce))\n \t\t\t\tcontinue;\n \t\t\thit |= grep_sha1(opt, ce->sha1, ce->name, 0);\ndiff --git a/t/t7002-grep.sh b/t/t7002-grep.sh\nindex 18fe6f2..e12b5dc 100755\n--- a/t/t7002-grep.sh\n+++ b/t/t7002-grep.sh\n@@ -161,7 +161,14 @@ test_expect_success 'log grep (6)' '\n \tgit log --author=-0700  --pretty=tformat:%s >actual &&\n \t>expect &&\n \ttest_cmp expect actual\n+'\n \n+test_expect_success 'grep with CE_VALID file' '\n+\tgit update-index --assume-unchanged t/t &&\n+\trm t/t &&\n+\ttest \"$(git grep --no-ext-grep t)\" = \"t/t:test\" &&\n+\tgit update-index --no-assume-unchanged t/t &&\n+\tgit checkout t/t\n '\n \n test_done\n-- \n1.6.0.4.1116.g25b13\n"},{"id":"98777","messageId":"1230366064-1306-2-git-send-email-pclouds@gmail.com","threadId":"16880","inReplyTo":"1230366064-1306-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 1/2] grep: support --no-ext-grep to test builtin grep","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-12-27T08:21:04Z","receivedAt":"2008-12-27T08:21:04Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n used by the next patch\n\n builtin-grep.c |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 624f86e..3c97c2c 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -20,6 +20,8 @@\n #endif\n #endif\n \n+static int builtin_grep;\n+\n /*\n  * git grep pathspecs are somewhat different from diff-tree pathspecs;\n  * pathname wildcards are allowed.\n@@ -389,7 +391,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)\n \t * we grep through the checked-out files. It tends to\n \t * be a lot more optimized\n \t */\n-\tif (!cached) {\n+\tif (!cached && !builtin_grep) {\n \t\thit = external_grep(opt, paths, cached);\n \t\tif (hit >= 0)\n \t\t\treturn hit;\n@@ -545,6 +547,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\tcached = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(\"--no-ext-grep\", arg)) {\n+\t\t\tbuiltin_grep = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(\"-a\", arg) ||\n \t\t    !strcmp(\"--text\", arg)) {\n \t\t\topt.binary = GREP_BINARY_TEXT;\n-- \n1.6.0.4.1116.g25b13\n"},{"id":"98817","messageId":"7vy6y1b5ts.fsf@gitster.siamese.dyndns.org","threadId":"16880","inReplyTo":"1230366064-1306-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/2] grep: grep cache entries if they are \"assume unchanged\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-27T22:39:59Z","receivedAt":"2008-12-27T22:39:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> ... External grep case has not been fixed yet. But given that\n> on the platform that CE_VALID bit may be used like Windows, external\n> grep is not available anyway, I would wait for people to raise their\n> hands before touching it.\n\nMy gut feeling is that it would suffice to always use the internal grep if\nthere is any index entry with CE_VALID set.  Having the bit is an unusual\ncase.\n\nAlso I am guessing that your above statement that users on Windows would\nbe the ones who want CE_VALID implies that CE_VALID is for platforms where\nfile operations are slow.  If that is really the case, the internal grep\nmight even have performance advantage over external grep.\n\nNo, I haven't benched the internal grep recently.\n"},{"id":"98831","messageId":"7vocywaiz2.fsf@gitster.siamese.dyndns.org","threadId":"16880","inReplyTo":"1230366064-1306-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/2] grep: grep cache entries if they are \"assume unchanged\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-28T06:53:37Z","receivedAt":"2008-12-28T06:53:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}