comparison 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
comparison
equal deleted inserted replaced
23968:6564ec382560 23969:01e5b7323a48
210 replace = {'parent': dir1a, 'parent1': dir1a, 'parent2': dir1b, 210 replace = {'parent': dir1a, 'parent1': dir1a, 'parent2': dir1b,
211 'plabel1': label1a, 'plabel2': label1b, 211 'plabel1': label1a, 'plabel2': label1b,
212 'clabel': label2, 'child': dir2, 212 'clabel': label2, 'child': dir2,
213 'root': repo.root} 213 'root': repo.root}
214 def quote(match): 214 def quote(match):
215 key = match.group()[1:] 215 pre = match.group(2)
216 key = match.group(3)
216 if not do3way and key == 'parent2': 217 if not do3way and key == 'parent2':
217 return '' 218 return pre
218 return util.shellquote(replace[key]) 219 return pre + util.shellquote(replace[key])
219 220
220 # Match parent2 first, so 'parent1?' will match both parent1 and parent 221 # Match parent2 first, so 'parent1?' will match both parent1 and parent
221 regex = '\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)' 222 regex = (r'''(['"]?)([^\s'"$]*)'''
223 r'\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)\1')
222 if not do3way and not re.search(regex, cmdline): 224 if not do3way and not re.search(regex, cmdline):
223 cmdline += ' $parent1 $child' 225 cmdline += ' $parent1 $child'
224 cmdline = re.sub(regex, quote, cmdline) 226 cmdline = re.sub(regex, quote, cmdline)
225 227
226 ui.debug('running %r in %s\n' % (cmdline, tmproot)) 228 ui.debug('running %r in %s\n' % (cmdline, tmproot))