Re: [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 13, 2019, 01:57 UTC
- Message-ID
- <xmqqmud0czch.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <0532847787dfd48fbe4b41a4a7d2783748f3bd7f.1573595985.git.liu.denton@gmail.com>
Denton Liu <liu.denton@gmail.com> writes:
Show 13 quoted lines
> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.
> test_cmp_rev () {
> + local op wrong_result
> + op='='
> + wrong_result='different'
> + if test $# -ge 1 && test "x$1" = 'x!'
> + then
> + op='!='
> + wrong_result='the same'
> + shift
> + fiI'd prefer
local op wrong_result
if test $# -ge 1 && test "x$1" = 'x!' then op='!=' wrong_result='the same' shift else op='=' wrong_result='different' fi
that clarifies that the variants with and without '!' are equals, as opposed to the form with '!' is an afterthought exception.
On the other hand, if we want to insist that the form without '!' is the norm, then
local op='=' wrong_result='different'
if test $# -ge 1 && test "x$1" = 'x!' then op='!=' wrong_result='the same' shift fi
would be shorter (yes, I made sure we already use assignment to a variable on the same line where it is declared "local"; we used to avoid "local" that is outside POSIX so I want to make sure our use is safe).
I'll queue the patches as-is, but if enough people agree with me (on either variants), I'd locally amend to make it so (i.e. no need to resend only for this change).
Thanks.