Re: [PATCH 01/18] rebase -i: Make the condition for an "if" more transparent

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

 



On 01/14/2010 06:42 PM, Junio C Hamano wrote:
Eric Blake<ebb9@xxxxxxx>  writes:

Michael Haggerty<mhagger<at>  alum.mit.edu>  writes:

  	current_sha1=$(git rev-parse --verify HEAD)
-	if test "$no_ff$current_sha1" = "$parent_sha1"; then
+	if test -z "$no_ff" -a "$current_sha1" = "$parent_sha1"

'test cond1 -a cond2' is not portable.  Use 'test cond1&&  test cond2'.

I avoid "test -a/-o" myself without even thinking (I am from old-school),
but at the same time I thought the progress in the world made such caution
obsolescent.

Not so.  Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI" ("Strictly Conforming POSIX Applications and
Strictly Conforming XSI Applications shall not use obsolescent features").

The reason for this is that the precedence rules were never well specified, and this made many sane-looking uses of "test -a/-o" problematic.

For example, if $x is "=", these work according to POSIX (it's not portable, but in practice it's okay):

  $ test -z "$x"
  $ test -z "$x" && test a = b

but this doesn't

  $ test -z "$x" -a a = b
  bash: test: too many arguments

because it groups "test -n = -a" and is left with "a = b".

Similarly, if $x is "-f", these

  $ test "$x"
  $ test "$x" || test c = d

correctly adds an implicit "-n", but this fails:

  $ test "$x" -o c = d
  bash: test: too many arguments

If anybody cleans up git's usage of test -a/-o, feel free to cut'n'paste the above into the commit messages.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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]