diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -8,7 +8,7 @@ from i18n import _ import encoding import os, sys, errno, stat, getpass, pwd, grp, socket, tempfile, unicodedata -import fcntl +import fcntl, re posixfile = open normpath = os.path.normpath @@ -315,9 +315,16 @@ if sys.platform == 'cygwin': def checklink(path): return False +_needsshellquote = None def shellquote(s): if os.sys.platform == 'OpenVMS': return '"%s"' % s + global _needsshellquote + if _needsshellquote is None: + _needsshellquote = re.compile(r'[^a-zA-Z0-9._/-]').search + if not _needsshellquote(s): + # "s" shouldn't have to be quoted + return s else: return "'%s'" % s.replace("'", "'\\''") diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t --- a/tests/test-extdiff.t +++ b/tests/test-extdiff.t @@ -114,11 +114,11 @@ issue4463: usage of command line configu running '*echo* *\\a *\\a' in */extdiff.* (glob) #else $ hg --debug 4463a | grep '^running' - running '\'echo\' a-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) + running 'echo a-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) $ hg --debug 4463b | grep '^running' - running 'echo b-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) + running 'echo b-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) $ hg --debug echo | grep '^running' - running "'*echo*' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) + running '*echo */a $TESTTMP/a/a' in */extdiff.* (glob) #endif (getting options from other than extdiff section) @@ -149,15 +149,15 @@ issue4463: usage of command line configu running 'echo echo-naked "being quoted" *\\a *\\a' in */extdiff.* (glob) #else $ hg --debug 4463b2 | grep '^running' - running 'echo b2-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) + running 'echo b2-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) $ hg --debug 4463b3 | grep '^running' - running 'echo b3-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) + running 'echo b3-naked \'single quoted\' "double quoted" */a $TESTTMP/a/a' in */extdiff.* (glob) $ hg --debug 4463b4 | grep '^running' - running "echo '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) - $ hg --debug 4463b4 --option 'being quoted' | grep '^running' - running "echo 'being quoted' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) - $ hg --debug extdiff -p echo --option 'being quoted' | grep '^running' - running "'echo' 'being quoted' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) + running 'echo */a $TESTTMP/a/a' in */extdiff.* (glob) + $ hg --debug 4463b4 --option b4-naked --option 'being quoted' | grep '^running' + running "echo b4-naked 'being quoted' */a $TESTTMP/a/a" in */extdiff.* (glob) + $ hg --debug extdiff -p echo --option echo-naked --option 'being quoted' | grep '^running' + running "echo echo-naked 'being quoted' */a $TESTTMP/a/a" in */extdiff.* (glob) #endif #if execbit @@ -273,7 +273,7 @@ Fallback to merge-tools.tool.executable| making snapshot of 2 files from working directory a b - running "'$TESTTMP/a/dir/tool.sh' 'a.*' 'a'" in */extdiff.* (glob) + running '$TESTTMP/a/dir/tool.sh a.* a' in */extdiff.* (glob) ** custom diff ** cleaning up temp directory [1]