{"thread":{"id":"43497","subject":"[PATCH] grep: do not skip unmerged entries when grepping in the working tree.","startedAt":"2006-11-26T14:53:58Z","lastAt":"2006-11-26T21:30:01Z","messageCount":3,"participants":["Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298659","messageId":"ekc9q7$36e$1@sea.gmane.org","threadId":"43497","inReplyTo":null,"subject":"git-grep misses an instance of a string (after conflict)","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2006-11-26T14:53:58Z","receivedAt":"2006-11-26T14:53:58Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"I've roughly had the following sequence of operations on a particular file\nin my project:\n\n1. git-cherry-pick a commit, which resulted in a conflict in in that file\n2. edit the file to insert a particular string (which wasn't there before)\n3. then:\n\n$ git-grep getSibling -- kdbg/exprwnd.h    # this file had a conflict\n$ grep getSibling -- kdbg/exprwnd.h       \n    { return static_cast<VarTree*>(getSibling()); }\n$ git-update-index kdbg/exprwnd.h\n$ git-grep getSibling -- kdbg/exprwnd.h       \nkdbg/exprwnd.h:    { return static_cast<VarTree*>(getSibling()); }\n\nAs you can see, the first git-grep doesn't find the string, but after the\nupdate-index, it does find it.\n\nThis is unexpected behavior, in particular since the manual page talks about\ngit-grep to search the working tree. I understand that the conflict may\nhave influenced the behavior, but the manual page is not in line with the\nbehavior. Am I missing something?\n\n-- Hannes\n\n"},{"id":"295133","messageId":"7vvel2rl05.fsf@assigned-by-dhcp.cox.net","threadId":"43497","inReplyTo":"ekc9q7$36e$1@sea.gmane.org","subject":"[PATCH] grep: do not skip unmerged entries when grepping in the working tree.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-26T20:49:46Z","receivedAt":"2006-11-26T20:49:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We used to skip unmerged entries, which made sense for grepping\nin the cached copies, but not for grepping in the files on the\nworking tree.\n\nNoticed by Johannes Sixt.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n  Johannes Sixt <johannes.sixt@telecom.at> writes:\n\n  > $ git-grep getSibling -- kdbg/exprwnd.h    # this file had a conflict\n  > $ grep getSibling -- kdbg/exprwnd.h       \n  >     { return static_cast<VarTree*>(getSibling()); }\n  > $ git-update-index kdbg/exprwnd.h\n  > $ git-grep getSibling -- kdbg/exprwnd.h       \n  > kdbg/exprwnd.h:    { return static_cast<VarTree*>(getSibling()); }\n\n  This is because unmerged entries were ignored.\n\n builtin-grep.c |   25 +++++++++++++++++++++----\n 1 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex ad7dc00..9873e3d 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -268,7 +268,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)\n \tfor (i = 0; i < active_nr; i++) {\n \t\tstruct cache_entry *ce = active_cache[i];\n \t\tchar *name;\n-\t\tif (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode)))\n+\t\tif (!S_ISREG(ntohl(ce->ce_mode)))\n \t\t\tcontinue;\n \t\tif (!pathspec_matches(paths, ce->name))\n \t\t\tcontinue;\n@@ -280,12 +280,19 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)\n \t\t\tmemcpy(name + 2, ce->name, len + 1);\n \t\t}\n \t\targv[argc++] = name;\n-\t\tif (argc < MAXARGS)\n+\t\tif (argc < MAXARGS && !ce_stage(ce))\n \t\t\tcontinue;\n \t\tstatus = exec_grep(argc, argv);\n \t\tif (0 < status)\n \t\t\thit = 1;\n \t\targc = nr;\n+\t\tif (ce_stage(ce)) {\n+\t\t\tdo {\n+\t\t\t\ti++;\n+\t\t\t} while (i < active_nr &&\n+\t\t\t\t !strcmp(ce->name, active_cache[i]->name));\n+\t\t\ti--; /* compensate for loop control */\n+\t\t}\n \t}\n \tif (argc > nr) {\n \t\tstatus = exec_grep(argc, argv);\n@@ -316,14 +323,24 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)\n \n \tfor (nr = 0; nr < active_nr; nr++) {\n \t\tstruct cache_entry *ce = active_cache[nr];\n-\t\tif (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode)))\n+\t\tif (!S_ISREG(ntohl(ce->ce_mode)))\n \t\t\tcontinue;\n \t\tif (!pathspec_matches(paths, ce->name))\n \t\t\tcontinue;\n-\t\tif (cached)\n+\t\tif (cached) {\n+\t\t\tif (ce_stage(ce))\n+\t\t\t\tcontinue;\n \t\t\thit |= grep_sha1(opt, ce->sha1, ce->name, 0);\n+\t\t}\n \t\telse\n \t\t\thit |= grep_file(opt, ce->name);\n+\t\tif (ce_stage(ce)) {\n+\t\t\tdo {\n+\t\t\t\tnr++;\n+\t\t\t} while (nr < active_nr &&\n+\t\t\t\t !strcmp(ce->name, active_cache[nr]->name));\n+\t\t\tnr--; /* compensate for loop control */\n+\t\t}\n \t}\n \tfree_grep_patterns(opt);\n \treturn hit;\n-- \n1.4.4.1.ge3fb\n\n"},{"id":"297906","messageId":"200611262230.01948.johannes.sixt@telecom.at","threadId":"43497","inReplyTo":"7vvel2rl05.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] grep: do not skip unmerged entries when grepping in the working tree.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2006-11-26T21:30:01Z","receivedAt":"2006-11-26T21:30:01Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Sunday 26 November 2006 21:49, Junio C Hamano wrote:\n> We used to skip unmerged entries, which made sense for grepping\n> in the cached copies, but not for grepping in the files on the\n> working tree.\n>\n> Noticed by Johannes Sixt.\n>\n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nThis fixes my problem. Thanks!\n\n"}]}