git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths
@ 2007-12-06  0:13 Junio C Hamano
  2007-12-06  7:29 ` Johannes Sixt
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2007-12-06  0:13 UTC (permalink / raw)
  To: git

When the index is unmerged, e.g.

	$ git ls-files -u
        100644 faf413748eb6ccb15161a212156c5e348302b1b6 1	setup.c
        100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2	setup.c
        100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3	setup.c

running "git grep" for work tree files repeats hits for each unmerged
stage.

	$ git grep -n -e setup_work_tree -- '*.[ch]'
        setup.c:209:void setup_work_tree(void)
        setup.c:209:void setup_work_tree(void)
        setup.c:209:void setup_work_tree(void)

This should fix it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 builtin-grep.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index bbf747f..f1ff8dc 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -343,12 +343,12 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 			memcpy(name + 2, ce->name, len + 1);
 		}
 		argv[argc++] = name;
-		if (argc < MAXARGS)
-			continue;
-		status = flush_grep(opt, argc, nr, argv, &kept);
-		if (0 < status)
-			hit = 1;
-		argc = nr + kept;
+		if (MAXARGS <= argc) {
+			status = flush_grep(opt, argc, nr, argv, &kept);
+			if (0 < status)
+				hit = 1;
+			argc = nr + kept;
+		}
 		if (ce_stage(ce)) {
 			do {
 				i++;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths
  2007-12-06  0:13 [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths Junio C Hamano
@ 2007-12-06  7:29 ` Johannes Sixt
  2007-12-06  8:08   ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2007-12-06  7:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano schrieb:
> When the index is unmerged, e.g.
> 
> 	$ git ls-files -u
>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1	setup.c
>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2	setup.c
>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3	setup.c
> 
> running "git grep" for work tree files repeats hits for each unmerged
> stage.
> 
> 	$ git grep -n -e setup_work_tree -- '*.[ch]'
>         setup.c:209:void setup_work_tree(void)
>         setup.c:209:void setup_work_tree(void)
>         setup.c:209:void setup_work_tree(void)
> 
> This should fix it.

Does this change the behavior of grep --cached? IOW, listing the same hit
more than once when --cached is given is a feature, IMHO.

-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths
  2007-12-06  7:29 ` Johannes Sixt
@ 2007-12-06  8:08   ` Junio C Hamano
  2007-12-06  8:24     ` Johannes Sixt
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2007-12-06  8:08 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

Johannes Sixt <j.sixt@viscovery.net> writes:

> Junio C Hamano schrieb:
>> When the index is unmerged, e.g.
>> 
>> 	$ git ls-files -u
>>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1	setup.c
>>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2	setup.c
>>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3	setup.c
>> 
>> running "git grep" for work tree files repeats hits for each unmerged
>> stage.
>> 
>> 	$ git grep -n -e setup_work_tree -- '*.[ch]'
>>         setup.c:209:void setup_work_tree(void)
>>         setup.c:209:void setup_work_tree(void)
>>         setup.c:209:void setup_work_tree(void)
>> 
>> This should fix it.
>
> Does this change the behavior of grep --cached? IOW, listing the same hit
> more than once when --cached is given is a feature, IMHO.

Yeah, --cached should grep for each stage.  It doesn't?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths
  2007-12-06  8:08   ` Junio C Hamano
@ 2007-12-06  8:24     ` Johannes Sixt
  2007-12-06  8:59       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2007-12-06  8:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano schrieb:
> Johannes Sixt <j.sixt@viscovery.net> writes:
> 
>> Junio C Hamano schrieb:
>>> When the index is unmerged, e.g.
>>>
>>> 	$ git ls-files -u
>>>         100644 faf413748eb6ccb15161a212156c5e348302b1b6 1	setup.c
>>>         100644 145eca50f41d811c4c8fcb21ed2604e6b2971aba 2	setup.c
>>>         100644 cb9558c49b6027bf225ba2a6154c4d2a52bcdbe2 3	setup.c
>>>
>>> running "git grep" for work tree files repeats hits for each unmerged
>>> stage.
>>>
>>> 	$ git grep -n -e setup_work_tree -- '*.[ch]'
>>>         setup.c:209:void setup_work_tree(void)
>>>         setup.c:209:void setup_work_tree(void)
>>>         setup.c:209:void setup_work_tree(void)
>>>
>>> This should fix it.
>> Does this change the behavior of grep --cached? IOW, listing the same hit
>> more than once when --cached is given is a feature, IMHO.
> 
> Yeah, --cached should grep for each stage.  It doesn't?

No, it doesn't. Neither before nor after this change. (I actually thought it
 would without this change, but I obviously was wrong.)

-- Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths
  2007-12-06  8:24     ` Johannes Sixt
@ 2007-12-06  8:59       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2007-12-06  8:59 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

Johannes Sixt <j.sixt@viscovery.net> writes:

> No, it doesn't. Neither before nor after this change. (I actually thought it
>  would without this change, but I obviously was wrong.)

Sorry, my mistake.  "git grep" traditionally skips unmerged paths.

It might make sense to grep in stage #2 if a path is unmerged, just like
we use stage #2 in diff-files.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-06  9:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-06  0:13 [BUG/PATCH] git grep shows the same hit repeatedly for unmerged paths Junio C Hamano
2007-12-06  7:29 ` Johannes Sixt
2007-12-06  8:08   ` Junio C Hamano
2007-12-06  8:24     ` Johannes Sixt
2007-12-06  8:59       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).