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

[PATCH] Avoid bug in Solaris xpg4/sed as used in submodule

From
Ben Walton <bwalton@artsci.utoronto.ca>
Date
Apr 9, 2012, 01:36 UTC
Message-ID
<1333935414-10389-1-git-send-email-bwalton@artsci.utoronto.ca>

The sed provided by Solaris in /usr/xpg4/bin has a bug whereby an unanchored regex using * for zero or more repetitions sees two separate matches fed to the substitution engine in some cases.

This is evidenced by:

$ for sed in /usr/xpg4/bin/sed /usr/bin/sed /opt/csw/gnu/sed; do \ echo 'ab' | $sed -e 's|[a]*|X|g'; \ done XXbX XbX XbX

This bug was triggered during a git submodule clone operation as exercised in the setup stage of t5526-fetch-submodules when using the default SANE_TOOL_PATH for Solaris. It led to paths such as ..../.. being used in the submodule .git gitdir reference.

Using the expression 's|\([^/]*\(/*\)\)|..\2|g' provides the desired result with all three three tested sed implementations but is harder to read. Instead, use an additional -e script to clean up after the bug on Solaris. The second script will be a functional no-op on most sed implementations.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 git-submodule.sh |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index efc86ad..0adad22 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -167,10 +167,12 @@ module_clone()
 	a=${a%/}
 	b=${b%/}
 
-	rel=$(echo $b | sed -e 's|[^/]*|..|g')
+	# Note: The second -e is to work around a bug in Solairs'
+	# xpg4/sed.  It will be a no-op in a working implementation.
+	rel=$(echo $b | sed -e 's|[^/]*|..|g' -e 's|\.\{4\}|..|g')
 	echo "gitdir: $rel/$a" >"$path/.git"
 
-	rel=$(echo $a | sed -e 's|[^/]*|..|g')
+	rel=$(echo $a | sed -e 's|[^/]*|..|g' -e 's|\.\{4\}|..|g')
 	(clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
 }
 
-- 
1.7.9
Next: Andreas Schwab
Message 1 of 17 in “Avoid bug in Solaris xpg4/sed as used in submodule”
  1. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 9, 2012
  2. Andreas SchwabApr 9, 2012
  3. Ben WaltonApr 9, 2012
  4. Andreas SchwabApr 9, 2012
  5. Junio C HamanoApr 9, 2012
  6. Ben WaltonApr 9, 2012
  7. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 9, 2012
  8. Andreas SchwabApr 9, 2012
  9. Junio C HamanoApr 9, 2012
  10. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 10, 2012
  11. Junio C HamanoApr 10, 2012
  12. Ben WaltonApr 10, 2012
  13. Junio C HamanoApr 10, 2012
  14. Andreas SchwabApr 10, 2012
  15. Junio C HamanoApr 10, 2012
  16. Ben WaltonApr 13, 2012
  17. Avoid bug in Solaris xpg4/sed as used in submoduleBen Walton, Apr 13, 2012

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.