diff hgext/extdiff.py @ 23969:01e5b7323a48 stable

extdiff: reintroduce backward compatibility with manual quoting of parameters 72a89cf86fcd broke things ... and the following cleanups didn't fix all issues. It didn't work with the diffargs shipped in mergetools.rc with explicit quoting. Parameters would end up with being quoted twice - especially if they really needed quoting. To work around that, look for explicit quotes around the variables that will be substituted with proper quoting. Also accept an additional prefix so we can handle both --foo='$parent' and '--foo=$parent' It will however still fail if the user intentionally place the variable inside a quoted string, as in 'parent $parent is on the left' There is currently no good way to handle that, short of knowing exactly which quoting mechanism will be used.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 28 Jan 2015 02:28:39 +0100
parents 9476cb62298e
children fa4642439aa0
line wrap: on
line diff
--- a/hgext/extdiff.py	Wed Jan 28 02:28:38 2015 +0100
+++ b/hgext/extdiff.py	Wed Jan 28 02:28:39 2015 +0100
@@ -212,13 +212,15 @@
                    'clabel': label2, 'child': dir2,
                    'root': repo.root}
         def quote(match):
-            key = match.group()[1:]
+            pre = match.group(2)
+            key = match.group(3)
             if not do3way and key == 'parent2':
-                return ''
-            return util.shellquote(replace[key])
+                return pre
+            return pre + util.shellquote(replace[key])
 
         # Match parent2 first, so 'parent1?' will match both parent1 and parent
-        regex = '\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)'
+        regex = (r'''(['"]?)([^\s'"$]*)'''
+                 r'\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1')
         if not do3way and not re.search(regex, cmdline):
             cmdline += ' $parent1 $child'
         cmdline = re.sub(regex, quote, cmdline)