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

Re: [PATCH 01/19] check_bindir: convert test -a/-o to && and ||

From
Junio C Hamano <gitster@pobox.com>
Date
May 20, 2014, 18:54 UTC
Message-ID
<xmqq38g4z3fd.fsf@gitster.dls.corp.google.com>
In-Reply-To
<xmqqsio4z5e5.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> As I already said, I think "better known" is much less of an issue
> than that "-a/-o" is "more error prone", and that is the reason why
> we may want to do this rewrite.
>
> I do not know offhand how busy the tree would be when we can apply
> these patches post-release without them getting rebased, but the
> zero-th step before this series may want to be a patch like this.
... and this time with a proposed log message.
-- >8 --
Subject: [PATCH] CodingGuidelines: avoid "test <cond> -a/-o <cond>"

The construct is error-prone; "test" being built-in in most modern shells, the reason to avoid "test <cond> && test <cond>" spawning one extra process by using a single "test <cond> -a <cond>" no longer exists.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/CodingGuidelines | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 3d08671..4d90c77 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -151,6 +151,19 @@ For shell scripts specifically (not exhaustive):
    interface translatable. See "Marking strings for translation" in
    po/README.
 
+ - We do not write our "test" command with "-a" and "-o" and use "&&"
+   or "||" to concatenate multiple "test" commands instead, because
+   the use of "-a/-o" is often error-prone.  E.g.
+
+     test -n "$x" -a "$a" = "$b"
+
+   is buggy and breaks when $x is "=", but
+
+     test -n "$x" && test "$a" = "$b"
+
+   does not have such a problem.
+
+
 For C programs:
 
  - We use tabs to indent, and interpret tabs as taking up to
-- 
2.0.0-rc3-438-g36dae77
Previous: Junio C HamanoNext: Elia Pinto
Message 4 of 27 in “convert test -a/-o to && and || patch series”
  1. 00/19 convert test -a/-o to && and || patch seriesElia Pinto, May 20, 2014
  2. 01/19 check_bindir: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  3. Junio C HamanoMay 20, 2014
  4. Junio C HamanoMay 20, 2014
  5. 02/19 contrib/examples/git-clone.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  6. 03/19 contrib/examples/git-commit.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  7. 04/19 contrib/examples/git-merge.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  8. 05/19 contrib/examples/git-repack.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  9. 06/19 contrib/examples/git-resolve.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  10. 07/19 git-bisect.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  11. 08/19 git-mergetool.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  12. 09/19 git-rebase--interactive.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  13. 10/19 git-submodule.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  14. Matthieu MoyMay 20, 2014
  15. Johannes SixtMay 20, 2014
  16. 11/19 t/t0025-crlf-auto.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  17. 12/19 t/t0026-eol-config.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  18. 13/19 t/t4102-apply-rename.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  19. 14/19 t/t5000-tar-tree.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  20. 15/19 t/t5403-post-checkout-hook.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  21. 16/19 t/t5537-fetch-shallow.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  22. 17/19 t/t5538-push-shallow.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  23. 18/19 t/t9814-git-p4-rename.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  24. 19/19 t/test-lib-functions.sh: convert test -a/-o to && and ||Elia Pinto, May 20, 2014
  25. Matthieu MoyMay 20, 2014
  26. Junio C HamanoMay 20, 2014
  27. Jonathan NiederMay 20, 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.