git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid bug in Solaris xpg4/sed as used in submodule
@ 2012-04-09  1:36 Ben Walton
  2012-04-09  6:40 ` Andreas Schwab
  0 siblings, 1 reply; 17+ messages in thread
From: Ben Walton @ 2012-04-09  1:36 UTC (permalink / raw)
  To: gitster; +Cc: git, Ben Walton

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-04-13  0:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-09  1:36 [PATCH] Avoid bug in Solaris xpg4/sed as used in submodule Ben Walton
2012-04-09  6:40 ` Andreas Schwab
2012-04-09 13:30   ` Ben Walton
2012-04-09 15:09     ` Andreas Schwab
2012-04-09 18:44       ` Junio C Hamano
2012-04-09 18:47       ` Ben Walton
2012-04-09 20:08         ` Ben Walton
2012-04-09 21:07           ` Andreas Schwab
2012-04-09 21:48             ` Junio C Hamano
2012-04-10  0:13               ` Ben Walton
2012-04-10  0:31                 ` Junio C Hamano
2012-04-10  0:40                   ` Ben Walton
2012-04-10  1:05                     ` Junio C Hamano
2012-04-10  8:31                       ` Andreas Schwab
2012-04-10 16:10                         ` Junio C Hamano
2012-04-13  0:46                           ` Ben Walton
2012-04-13  0:48                             ` Ben Walton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).