{"thread":{"id":"11151","subject":"[BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","startedAt":"2007-12-06T00:13:08Z","lastAt":"2007-12-06T08:59:43Z","messageCount":5,"participants":["Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"62075","messageId":"7vsl2gk7e3.fsf@gitster.siamese.dyndns.org","threadId":"11151","inReplyTo":null,"subject":"[BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-06T00:13:08Z","receivedAt":"2007-12-06T00:13:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When the index is unmerged, e.g.\n\n\t$ git ls-files -u\n        100644 faf413748eb6ccb15161a212156c5e348302b1b6 1\tsetup.c\n        100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2\tsetup.c\n        100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3\tsetup.c\n\nrunning \"git grep\" for work tree files repeats hits for each unmerged\nstage.\n\n\t$ git grep -n -e setup_work_tree -- '*.[ch]'\n        setup.c:209:void setup_work_tree(void)\n        setup.c:209:void setup_work_tree(void)\n        setup.c:209:void setup_work_tree(void)\n\nThis should fix it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n builtin-grep.c |   12 ++++++------\n 1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex bbf747f..f1ff8dc 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -343,12 +343,12 @@ 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\t\tcontinue;\n-\t\tstatus = flush_grep(opt, argc, nr, argv, &kept);\n-\t\tif (0 < status)\n-\t\t\thit = 1;\n-\t\targc = nr + kept;\n+\t\tif (MAXARGS <= argc) {\n+\t\t\tstatus = flush_grep(opt, argc, nr, argv, &kept);\n+\t\t\tif (0 < status)\n+\t\t\t\thit = 1;\n+\t\t\targc = nr + kept;\n+\t\t}\n \t\tif (ce_stage(ce)) {\n \t\t\tdo {\n \t\t\t\ti++;\n"},{"id":"62125","messageId":"4757A4DD.901@viscovery.net","threadId":"11151","inReplyTo":"7vsl2gk7e3.fsf@gitster.siamese.dyndns.org","subject":"Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-12-06T07:29:33Z","receivedAt":"2007-12-06T07:29:33Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Junio C Hamano schrieb:\n> When the index is unmerged, e.g.\n> \n> \t$ git ls-files -u\n>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1\tsetup.c\n>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2\tsetup.c\n>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3\tsetup.c\n> \n> running \"git grep\" for work tree files repeats hits for each unmerged\n> stage.\n> \n> \t$ git grep -n -e setup_work_tree -- '*.[ch]'\n>         setup.c:209:void setup_work_tree(void)\n>         setup.c:209:void setup_work_tree(void)\n>         setup.c:209:void setup_work_tree(void)\n> \n> This should fix it.\n\nDoes this change the behavior of grep --cached? IOW, listing the same hit\nmore than once when --cached is given is a feature, IMHO.\n\n-- Hannes\n"},{"id":"62129","messageId":"7v3auggs8x.fsf@gitster.siamese.dyndns.org","threadId":"11151","inReplyTo":"4757A4DD.901@viscovery.net","subject":"Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-06T08:08:30Z","receivedAt":"2007-12-06T08:08:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Junio C Hamano schrieb:\n>> When the index is unmerged, e.g.\n>> \n>> \t$ git ls-files -u\n>>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1\tsetup.c\n>>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2\tsetup.c\n>>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3\tsetup.c\n>> \n>> running \"git grep\" for work tree files repeats hits for each unmerged\n>> stage.\n>> \n>> \t$ git grep -n -e setup_work_tree -- '*.[ch]'\n>>         setup.c:209:void setup_work_tree(void)\n>>         setup.c:209:void setup_work_tree(void)\n>>         setup.c:209:void setup_work_tree(void)\n>> \n>> This should fix it.\n>\n> Does this change the behavior of grep --cached? IOW, listing the same hit\n> more than once when --cached is given is a feature, IMHO.\n\nYeah, --cached should grep for each stage.  It doesn't?\n"},{"id":"62131","messageId":"4757B1B9.2050606@viscovery.net","threadId":"11151","inReplyTo":"7v3auggs8x.fsf@gitster.siamese.dyndns.org","subject":"Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-12-06T08:24:25Z","receivedAt":"2007-12-06T08:24:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Junio C Hamano schrieb:\n> Johannes Sixt <j.sixt@viscovery.net> writes:\n> \n>> Junio C Hamano schrieb:\n>>> When the index is unmerged, e.g.\n>>>\n>>> \t$ git ls-files -u\n>>>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1\tsetup.c\n>>>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2\tsetup.c\n>>>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3\tsetup.c\n>>>\n>>> running \"git grep\" for work tree files repeats hits for each unmerged\n>>> stage.\n>>>\n>>> \t$ git grep -n -e setup_work_tree -- '*.[ch]'\n>>>         setup.c:209:void setup_work_tree(void)\n>>>         setup.c:209:void setup_work_tree(void)\n>>>         setup.c:209:void setup_work_tree(void)\n>>>\n>>> This should fix it.\n>> Does this change the behavior of grep --cached? IOW, listing the same hit\n>> more than once when --cached is given is a feature, IMHO.\n> \n> Yeah, --cached should grep for each stage.  It doesn't?\n\nNo, it doesn't. Neither before nor after this change. (I actually thought it\n would without this change, but I obviously was wrong.)\n\n-- Hannes\n"},{"id":"62132","messageId":"7vtzmwfbb4.fsf@gitster.siamese.dyndns.org","threadId":"11151","inReplyTo":"4757B1B9.2050606@viscovery.net","subject":"Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-06T08:59:43Z","receivedAt":"2007-12-06T08:59:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> No, it doesn't. Neither before nor after this change. (I actually thought it\n>  would without this change, but I obviously was wrong.)\n\nSorry, my mistake.  \"git grep\" traditionally skips unmerged paths.\n\nIt might make sense to grep in stage #2 if a path is unmerged, just like\nwe use stage #2 in diff-files.\n"}]}