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

[PATCH] t7422: fix extra printf argument, eliminate loops

From
SNSubhaditya Nath <sn03.general@gmail.com>
Date
Apr 9, 2025, 19:11 UTC
Message-ID
<20250409191139.29644-2-sn03.general@gmail.com>
In-Reply-To
<20250409191139.29644-1-sn03.general@gmail.com>
The POSIX man page of printf(1) mentions -
> If the format operand contains no conversion specifications and
> argument operands are present, the results are unspecified.

In practice, this means some printf implementations throw an error when provided with extra operands, thereby causing the test to fail erroneously. This commit fixes that issue.

This commit also eliminates the for-loops surrounding said printf statements in favour of the built-in functionality of printf to consume all arguments by reusing the format operand as-often-as-necessary.

This behaviour is mentioned in the POSIX man page of printf(1) under the section titled "EXTENDED DESCRIPTION" like so -

    8. For each conversion specification that consumes an argument, the
       next argument operand shall be evaluated and converted to the
       appropriate type for the conversion as specified below.
    9. The format operand shall be reused as often as necessary to
       satisfy the argument operands.  [...]
Signed-off-by: Subhaditya Nath <sn03.general@gmail.com>
---
 t/t7422-submodule-output.sh | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh
index 023a5cbdc4..94a14f1c31 100755
--- a/t/t7422-submodule-output.sh
+++ b/t/t7422-submodule-output.sh
@@ -178,19 +178,13 @@ test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE'
 		test_commit initial &&
 
 		COMMIT=$(git rev-parse HEAD) &&
-		for i in $(test_seq 2000)
-		do
-			printf "[submodule \"sm-$i\"]\npath = recursive-submodule-path-$i\n" "$i" ||
-			return 1
-		done >gitmodules &&
+		printf "[submodule \"sm-%d\"]\npath = recursive-submodule-path-%d\n" \
+			$(test_seq 2000 | sed p) >gitmodules &&
 		BLOB=$(git hash-object -w --stdin <gitmodules) &&
 
 		printf "100644 blob $BLOB\t.gitmodules\n" >tree &&
-		for i in $(test_seq 2000)
-		do
-			printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" "$i" ||
-			return 1
-		done >>tree &&
+		printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" \
+			$(test_seq 2000) >>tree &&
 		TREE=$(git mktree <tree) &&
 
 		COMMIT=$(git commit-tree "$TREE") &&
-- 
2.48.1
Previous: Subhaditya NathNext: Junio C Hamano
Message 9 of 10 in “t7422: remove extraneous argument to printf”
  1. t7422: remove extraneous argument to printfSubhaditya Nath, Apr 3, 2025
  2. Eric SunshineApr 3, 2025
  3. Junio C HamanoApr 9, 2025
  4. Subhaditya NathApr 9, 2025
  5. Subhaditya NathApr 9, 2025
  6. Eric SunshineApr 9, 2025
  7. Junio C HamanoApr 9, 2025
  8. t7422: fix extra printf argument, eliminate loopsSubhaditya Nath, Apr 9, 2025
  9. t7422: fix extra printf argument, eliminate loopsSubhaditya Nath, Apr 9, 2025
  10. Junio C HamanoApr 10, 2025

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.