Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Junio,

On Fri, Nov 08, 2019 at 09:49:02PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@xxxxxxxxx> writes:
>
> >> >  		local r1 r2
> >> >  		r1=$(git rev-parse --verify "$1") &&
> >> >  		r2=$(git rev-parse --verify "$2") &&
> >>
> >> If either of the calls fail, the assignment itself would fail, and
> >> the &&-cascade would stop without executing the if statment below.
> >>
> >> I see the "!" feature, but where is the promised "fix" for
> >> segfaulting rev-parse?
> >>
> >> Puzzled.
> >
> > I suppose your puzzlement comes from my badly worded commit message
> > above. I meant to say that in the _hypothetical_ case that
> > `git rev-parse` segfaults, it wouldn't be caught because we're
> > blanket-ignoring failures if we do `! test_cmp_rev`.
> >
> > But I suppose I focused too much on segfaults. I guess I didn't realise
> > that the problem is more general than that; any failure of
> > `git rev-parse` should be reported.
>
> But if that is the case, shouldn't the part that runs two rev-parse
> read more like this?
>
> 	r1=$(git rev-parse --verify "$1") ||
> 		error "'$1' does not name a valid object"
> 	r2=$(git rev-parse --verify "$2") ||
> 		error "'$2' does not name a valid object"
> 	if ! test "$r1" $op "$r2"
> 	then
> 		... they do not compare the same ...
> 	fi

With your suggestion, we actually introduce subtle undesired behaviour.
The `error` calls don't actually exit the function early. To make it
work, we need to add && to the end of the `error` calls.

I'm wondering why we want to do this, though. rev-parse should already
output an error message on stderr in the case where the rev-parse fails.
I guess the error message of "fatal: Needed a single revision" could
probably be improved but that feels like an improvement that should be
targeted to rev-parse.

>
> Offhand I do not know if the current callers depend on being able to
> pass a string that is not an object name in either $1 or $2 and a
> valid object name in the other one, and relying on the helper
> function to say "$1 and $2 are different!"  If such callers exist, a
> defensive change like the above that requires the caller to always
> pass valid object names would need to be accompanied with changes to
> these callers, too.  Overall, I think that would give us a better
> end result, but it might be a bit more work.

This patch changes all instances of `! test_cmp_rev` to
`test_cmp_rev !`. Since nothing failed after applying the patch, I
believe that all callers already pass in valid object names.

Thanks,

Denton

>
> Thanks.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux