git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 10/10] git-submodule.sh: don't use the -a or -b option with the test command

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 15, 2014, 15:58 UTC
Message-ID
<20140515155821.GA27279@google.com>
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

Previous: Elia PintoNext: Junio C Hamano
Message 13 of 14 in “check_bindir: don't use the -a or -b option with the test command”
  1. 01/10 check_bindir: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  2. 02/10 contrib/examples/git-clone.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  3. 03/10 contrib/examples/git-commit.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  4. 04/10 contrib/examples/git-merge.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  5. 05/10 contrib/examples/git-repack.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  6. 06/10 contrib/examples/git-resolve.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  7. 07/10 git-bisect.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  8. 08/10 git-mergetool.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  9. David AguilarMay 16, 2014
  10. 09/10 git-rebase--interactive.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  11. 10/10 git-submodule.sh: don't use the -a or -b option with the test commandElia Pinto, May 15, 2014
  12. Elia PintoMay 15, 2014
  13. Jonathan NiederMay 15, 2014
  14. Junio C HamanoMay 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.