* Odd "git diff" breakage
@ 2014-03-31 18:05 Linus Torvalds
2014-03-31 18:30 ` Junio C Hamano
2014-03-31 18:47 ` [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: Linus Torvalds @ 2014-03-31 18:05 UTC (permalink / raw)
To: Git Mailing List, Junio C Hamano
I hit this oddity when not remembering the right syntax for --color-words..
Try this (outside of a git repository):
touch a b
git diff -u --color=words a b
and watch it scroll (infinitely) printing out
error: option `color' expects "always", "auto", or "never"
forever.
I haven't tried to root-cause it, since I'm supposed to be merging stuff..
Linus
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Odd "git diff" breakage 2014-03-31 18:05 Odd "git diff" breakage Linus Torvalds @ 2014-03-31 18:30 ` Junio C Hamano 2014-03-31 18:35 ` Linus Torvalds 2014-03-31 18:38 ` Junio C Hamano 2014-03-31 18:47 ` [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() Junio C Hamano 1 sibling, 2 replies; 6+ messages in thread From: Junio C Hamano @ 2014-03-31 18:30 UTC (permalink / raw) To: Linus Torvalds; +Cc: Git Mailing List Linus Torvalds <torvalds@linux-foundation.org> writes: > I hit this oddity when not remembering the right syntax for --color-words.. > > Try this (outside of a git repository): > > touch a b > git diff -u --color=words a b > > and watch it scroll (infinitely) printing out > > error: option `color' expects "always", "auto", or "never" > > forever. > > I haven't tried to root-cause it, since I'm supposed to be merging stuff.. > > Linus Hmph, interesting. "outside a repository" is the key, it seems. And I can see it all the way down to 1.7.3 (at least). ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Odd "git diff" breakage 2014-03-31 18:30 ` Junio C Hamano @ 2014-03-31 18:35 ` Linus Torvalds 2014-03-31 18:38 ` Junio C Hamano 1 sibling, 0 replies; 6+ messages in thread From: Linus Torvalds @ 2014-03-31 18:35 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List On Mon, Mar 31, 2014 at 11:30 AM, Junio C Hamano <gitster@pobox.com> wrote: > > Hmph, interesting. "outside a repository" is the key, it seems. Well, you can do it inside a repository too, but then you need to use the "--no-index" flag to get the "diff two files" behavior. It will result in the same infinite error messages. Linus ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Odd "git diff" breakage 2014-03-31 18:30 ` Junio C Hamano 2014-03-31 18:35 ` Linus Torvalds @ 2014-03-31 18:38 ` Junio C Hamano 1 sibling, 0 replies; 6+ messages in thread From: Junio C Hamano @ 2014-03-31 18:38 UTC (permalink / raw) To: Linus Torvalds; +Cc: Git Mailing List Junio C Hamano <gitster@pobox.com> writes: > Linus Torvalds <torvalds@linux-foundation.org> writes: > >> I hit this oddity when not remembering the right syntax for --color-words.. >> >> Try this (outside of a git repository): >> >> touch a b >> git diff -u --color=words a b >> >> and watch it scroll (infinitely) printing out >> >> error: option `color' expects "always", "auto", or "never" >> >> forever. >> >> I haven't tried to root-cause it, since I'm supposed to be merging stuff.. >> >> Linus > > Hmph, interesting. "outside a repository" is the key, it seems. > And I can see it all the way down to 1.7.3 (at least). diff_opt_parse() returns the number of options parsed, or often returns error() which is defined to return -1. Yes, return value of 0 is "I don't understand that option", which should cause the caller to say that, but negative return should not be forgotten. diff-no-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-no-index.c b/diff-no-index.c index c554691..265709b 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -198,7 +198,7 @@ void diff_no_index(struct rev_info *revs, i++; else { j = diff_opt_parse(&revs->diffopt, argv + i, argc - i); - if (!j) + if (j <= 0) die("invalid diff option/value: %s", argv[i]); i += j; } ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() 2014-03-31 18:05 Odd "git diff" breakage Linus Torvalds 2014-03-31 18:30 ` Junio C Hamano @ 2014-03-31 18:47 ` Junio C Hamano 2014-03-31 19:14 ` Linus Torvalds 1 sibling, 1 reply; 6+ messages in thread From: Junio C Hamano @ 2014-03-31 18:47 UTC (permalink / raw) To: Linus Torvalds; +Cc: Git Mailing List diff_opt_parse() returns the number of options parsed, or often returns error() which is defined to return -1. Yes, return value of 0 is "I did not process that option at all", which should cause the caller to say that, but negative return should not be forgotten. This bug the caused it to infinitely show the same error message because the returned value was used to decrement the loop control variable, e.g. $ git diff --no-index --color=words a b error: option `color' expects "always", "auto", or "never" error: option `color' expects "always", "auto", or "never" ... Instead, make it act like so: $ git diff --no-index --color=words a b error: option `color' expects "always", "auto", or "never" fatal: invalid diff option/value: --color=words Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com> --- * The other callchain to this function comes from rev-list.c, and the caller does handle it correctly. diff-no-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-no-index.c b/diff-no-index.c index 00a8eef..ecf9293 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -244,7 +244,7 @@ void diff_no_index(struct rev_info *revs, i++; else { j = diff_opt_parse(&revs->diffopt, argv + i, argc - i); - if (!j) + if (j <= 0) die("invalid diff option/value: %s", argv[i]); i += j; } -- 1.9.1-513-gce53123 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() 2014-03-31 18:47 ` [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() Junio C Hamano @ 2014-03-31 19:14 ` Linus Torvalds 0 siblings, 0 replies; 6+ messages in thread From: Linus Torvalds @ 2014-03-31 19:14 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List On Mon, Mar 31, 2014 at 11:47 AM, Junio C Hamano <gitster@pobox.com> wrote: > > Instead, make it act like so: > > $ git diff --no-index --color=words a b > error: option `color' expects "always", "auto", or "never" > fatal: invalid diff option/value: --color=words Thanks, Linus ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-31 19:14 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-03-31 18:05 Odd "git diff" breakage Linus Torvalds 2014-03-31 18:30 ` Junio C Hamano 2014-03-31 18:35 ` Linus Torvalds 2014-03-31 18:38 ` Junio C Hamano 2014-03-31 18:47 ` [PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse() Junio C Hamano 2014-03-31 19:14 ` Linus Torvalds
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox