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

Re: [PATCH 1/6] git-p4 tests: refactor and cleanup

From
PWPete Wyckoff <pw@padd.com>
Date
Oct 16, 2011, 14:35 UTC
Message-ID
<20111016143533.GA22144@arf.padd.com>
In-Reply-To
<201110161154.11898.stefano.lattarini@gmail.com>
stefano.lattarini@gmail.com wrote on Sun, 16 Oct 2011 11:54 +0200:
Show 25 quoted lines
> OK, I have to partially correct myself here ...
> 
> On Sunday 16 October 2011, Stefano Lattarini wrote:
> >
> > This won't work with older versions of the Almquist shell (without
> > prepending `testid' and `git_p4_test_start' with a `$', that is):
> > 
> >   $ ash-0.5.2 -c 'a=4; b=2; echo $(( 1 + (a - b) ))'
> >   ash-0.5.2: arith: syntax error: " 1 + (a - b) "
> > 
> OTOH, this behaviour seems in contrast with the POSIX standard, which
> says that:
> 
>   ``If the shell variable x contains a value that forms a valid integer
>     constant, then the arithmetic expansions "$((x))" and "$(($x))" shall
>     return the same value.''
> 
> Reference:
>  <http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04>
> 
> So, since the git testsuite explicitly requires a POSIX shell, there is
> probably nothing to fix here.
> 
> Sorry for the noise,
>   Stefano

No, this is a good catch. The use of $x inside arithmetic expansions is indeed called out in the CodingGuidlines. Thanks for the careful read.

I'm going to resend the series, since it's not in next yet. Here's the patch for this bit, fyi.

		-- Pete
-------------------8<-------------------
From 53d5ad0761cda36da97bf1498ab1dc1a80a52772 Mon Sep 17 00:00:00 2001
From: Pete Wyckoff <pw@padd.com>
Date: Sun, 16 Oct 2011 09:59:05 -0400
Subject: [PATCH] git-p4 tests: use explicit $ for variables in $(( .. ))
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 t/lib-git-p4.sh   |    2 +-
 t/t9800-git-p4.sh |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index 412adec..a870f9a 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -22,7 +22,7 @@ GITP4="$GIT_BUILD_DIR/contrib/fast-import/git-p4"
 # same tests and has chosen the same ports.
 testid=${this_test#t}
 git_p4_test_start=9800
-P4DPORT=$((10669 + (testid - git_p4_test_start)))
+P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
 
 export P4PORT=localhost:$P4DPORT
 export P4CLIENT=client
diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index 296aee9..8fbed66 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -293,7 +293,7 @@ test_expect_success 'detect renames' '
 		git diff-tree -r -M HEAD &&
 		level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
 		test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
-		git config git-p4.detectRenames $((level + 2)) &&
+		git config git-p4.detectRenames $(($level + 2)) &&
 		"$GITP4" submit &&
 		p4 filelog //depot/file6 &&
 		p4 filelog //depot/file6 | test_must_fail grep -q "branch from" &&
@@ -305,7 +305,7 @@ test_expect_success 'detect renames' '
 		git diff-tree -r -M HEAD &&
 		level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
 		test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
-		git config git-p4.detectRenames $((level - 2)) &&
+		git config git-p4.detectRenames $(($level - 2)) &&
 		"$GITP4" submit &&
 		p4 filelog //depot/file7 &&
 		p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
@@ -376,7 +376,7 @@ test_expect_success 'detect copies' '
 		test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
 		src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
 		test "$src" = file10 &&
-		git config git-p4.detectCopies $((level + 2)) &&
+		git config git-p4.detectCopies $(($level + 2)) &&
 		"$GITP4" submit &&
 		p4 filelog //depot/file12 &&
 		p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
@@ -390,7 +390,7 @@ test_expect_success 'detect copies' '
 		test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
 		src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
 		test "$src" = file10 &&
-		git config git-p4.detectCopies $((level - 2)) &&
+		git config git-p4.detectCopies $(($level - 2)) &&
 		"$GITP4" submit &&
 		p4 filelog //depot/file13 &&
 		p4 filelog //depot/file13 | grep -q "branch from //depot/file"
-- 
1.7.7
Previous: Stefano LattariniNext: Pete Wyckoff
Message 5 of 13 in “git-p4 tests, filetypes, shell metacharacters”
  1. 0/6 git-p4 tests, filetypes, shell metacharactersPete Wyckoff, Oct 15, 2011
  2. 1/6 git-p4 tests: refactor and cleanupPete Wyckoff, Oct 15, 2011
  3. Stefano LattariniOct 16, 2011
  4. Stefano LattariniOct 16, 2011
  5. Pete WyckoffOct 16, 2011
  6. 2/6 git-p4: handle utf16 filetype properlyPete Wyckoff, Oct 15, 2011
  7. Stefano LattariniOct 16, 2011
  8. Pete WyckoffOct 16, 2011
  9. 3/6 git-p4: recognize all p4 filetypesPete Wyckoff, Oct 15, 2011
  10. 4/6 git-p4: stop ignoring apple filetypePete Wyckoff, Oct 15, 2011
  11. 5/6 git-p4: keyword flattening fixesPete Wyckoff, Oct 15, 2011
  12. 6/6 git-p4: handle files with shell metacharactersPete Wyckoff, Oct 15, 2011
  13. Luke DiamandOct 15, 2011

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.