git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 10/10] git-submodule.sh: don't use the -a or -b option with the test command
Date: Thu, 15 May 2014 08:58:22 -0700	[thread overview]
Message-ID: <20140515155821.GA27279@google.com> (raw)
In-Reply-To: <1400163457-28285-10-git-send-email-gitter.spiros@gmail.com>

Elia Pinto wrote:

> Even though POSIX.1 lists -a/-o as options to "test", they are
> marked "Obsolescent XSI". Scripts using these expressions
> should be converted  as follow:
[... many lines snipped ...]

This is a very long description, and it doesn't leave me excited by
the change.

Is there some potential bug this prevents, or is it just a style
fix?  If the latter, do we have a way of checking for new examples
of the same thing to avoid having to repeat the same patch again in
the future?

Are there any platforms that were broken which this fixes?  Even
posh seems to understand -a and -o.

Nowadays Documentation/CodingGuidelines says

 - Fixing style violations while working on a real change as a
   preparatory clean-up step is good, but otherwise avoid useless code
   churn for the sake of conforming to the style.

   "Once it _is_ in the tree, it's not really worth the patch noise to
   go and fix it up."
   Cf. http://article.gmane.org/gmane.linux.kernel/943020

which I think goes too far (some patterns really are error prone
or distracting and it can be worth fixing them tree-wide), but it
makes a reasonable case that an idiom not being preferred in the
style guide is not *on its own* enough reason to change it.

Perhaps something like the following would work?

	tree-wide: convert test -a/-o to && and ||

	The interaction with unary operators and operator precedence
	for && and || are better known than -a and -o, and for that
	reason we prefer them.  Replace all existing instances in git
	of -a and -o to save readers from the burden of thinking
	about such things.

	Add a check-non-portable-shell.pl to avoid more instances of
	test -a and -o arising in the future.

[...]
> -			test $status = D -o $status = T && echo "$sm_path" && continue
> +			 ( test $status = D || test $status = T ) && echo "$sm_path" && continue

There's no need for a subshell for this.  Better to use a block:

			{
				test "$status" = D ||
				test "$status" = T
			} &&
			echo "$sm_path" &&
			continue

or an if statement:

			if test "$status" = D || test "$status" = T
			then
				echo "$sm_path"
				continue
			fi

or case:

			case $status in
			D|T)
				echo "$sm_path"
				continue
				;;
			esac

Hope that helps,
Jonathan

  parent reply	other threads:[~2014-05-15 15:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-15 14:17 [PATCH 01/10] check_bindir: don't use the -a or -b option with the test command Elia Pinto
2014-05-15 14:17 ` [PATCH 02/10] contrib/examples/git-clone.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 03/10] contrib/examples/git-commit.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 04/10] contrib/examples/git-merge.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 05/10] contrib/examples/git-repack.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 06/10] contrib/examples/git-resolve.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 07/10] git-bisect.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 08/10] git-mergetool.sh: " Elia Pinto
2014-05-16  8:24   ` David Aguilar
2014-05-15 14:17 ` [PATCH 09/10] git-rebase--interactive.sh: " Elia Pinto
2014-05-15 14:17 ` [PATCH 10/10] git-submodule.sh: " Elia Pinto
2014-05-15 14:19   ` Elia Pinto
2014-05-15 15:58   ` Jonathan Nieder [this message]
2014-05-16 19:09     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140515155821.GA27279@google.com \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitter.spiros@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).