Show More
@@ -109,7 +109,7 b' def snapshot(ui, repo, files, node, tmpr' | |||
|
109 | 109 | os.lstat(dest).st_mtime)) |
|
110 | 110 | return dirname, fns_and_mtime |
|
111 | 111 | |
|
112 |
def dodiff(ui, repo, |
|
|
112 | def dodiff(ui, repo, args, pats, opts): | |
|
113 | 113 | '''Do the actual diff: |
|
114 | 114 | |
|
115 | 115 | - copy to a temp structure if diffing 2 internal revisions |
@@ -120,7 +120,6 b' def dodiff(ui, repo, diffcmd, diffopts, ' | |||
|
120 | 120 | |
|
121 | 121 | revs = opts.get('rev') |
|
122 | 122 | change = opts.get('change') |
|
123 | args = ' '.join(map(util.shellquote, diffopts)) | |
|
124 | 123 | do3way = '$parent2' in args |
|
125 | 124 | |
|
126 | 125 | if revs and change: |
@@ -222,8 +221,7 b' def dodiff(ui, repo, diffcmd, diffopts, ' | |||
|
222 | 221 | regex = '\$(parent2|parent1?|child|plabel1|plabel2|clabel|root)' |
|
223 | 222 | if not do3way and not re.search(regex, args): |
|
224 | 223 | args += ' $parent1 $child' |
|
225 |
|
|
|
226 | cmdline = util.shellquote(diffcmd) + ' ' + args | |
|
224 | cmdline = re.sub(regex, quote, args) | |
|
227 | 225 | |
|
228 | 226 | ui.debug('running %r in %s\n' % (cmdline, tmproot)) |
|
229 | 227 | ui.system(cmdline, cwd=tmproot) |
@@ -271,7 +269,8 b' def extdiff(ui, repo, *pats, **opts):' | |||
|
271 | 269 | if not program: |
|
272 | 270 | program = 'diff' |
|
273 | 271 | option = option or ['-Npru'] |
|
274 | return dodiff(ui, repo, program, option, pats, opts) | |
|
272 | cmdline = ' '.join(map(util.shellquote, [program] + option)) | |
|
273 | return dodiff(ui, repo, cmdline, pats, opts) | |
|
275 | 274 | |
|
276 | 275 | def uisetup(ui): |
|
277 | 276 | for cmd, path in ui.configitems('extdiff'): |
@@ -281,29 +280,37 b' def uisetup(ui):' | |||
|
281 | 280 | path = util.findexe(cmd) |
|
282 | 281 | if path is None: |
|
283 | 282 | path = filemerge.findexternaltool(ui, cmd) or cmd |
|
284 |
diffopts = |
|
|
283 | diffopts = ui.config('extdiff', 'opts.' + cmd, '') | |
|
284 | cmdline = util.shellquote(path) | |
|
285 | if diffopts: | |
|
286 | cmdline += ' ' + diffopts | |
|
285 | 287 | elif cmd.startswith('opts.'): |
|
286 | 288 | continue |
|
287 | 289 | else: |
|
288 | # command = path opts | |
|
289 | 290 | if path: |
|
290 | diffopts = shlex.split(path) | |
|
291 | path = diffopts.pop(0) | |
|
291 | # case "cmd = path opts" | |
|
292 | cmdline = path | |
|
293 | diffopts = len(shlex.split(cmdline)) > 1 | |
|
292 | 294 | else: |
|
293 | path, diffopts = util.findexe(cmd), [] | |
|
295 | # case "cmd =" | |
|
296 | path = util.findexe(cmd) | |
|
294 | 297 | if path is None: |
|
295 | 298 | path = filemerge.findexternaltool(ui, cmd) or cmd |
|
299 | cmdline = util.shellquote(path) | |
|
300 | diffopts = False | |
|
296 | 301 | # look for diff arguments in [diff-tools] then [merge-tools] |
|
297 |
if diffopts |
|
|
302 | if not diffopts: | |
|
298 | 303 | args = ui.config('diff-tools', cmd+'.diffargs') or \ |
|
299 | 304 | ui.config('merge-tools', cmd+'.diffargs') |
|
300 | 305 | if args: |
|
301 |
|
|
|
302 |
def save(cmd |
|
|
306 | cmdline += ' ' + args | |
|
307 | def save(cmdline): | |
|
303 | 308 | '''use closure to save diff command to use''' |
|
304 | 309 | def mydiff(ui, repo, *pats, **opts): |
|
305 | return dodiff(ui, repo, path, diffopts + opts['option'], | |
|
306 |
|
|
|
310 | options = ' '.join(map(util.shellquote, opts['option'])) | |
|
311 | if options: | |
|
312 | options = ' ' + options | |
|
313 | return dodiff(ui, repo, cmdline + options, pats, opts) | |
|
307 | 314 | doc = _('''\ |
|
308 | 315 | use %(path)s to diff repository (or selected files) |
|
309 | 316 | |
@@ -325,6 +332,6 b' use %(path)s to diff repository (or sele' | |||
|
325 | 332 | # right encoding) prevents that. |
|
326 | 333 | mydiff.__doc__ = doc.decode(encoding.encoding) |
|
327 | 334 | return mydiff |
|
328 |
cmdtable[cmd] = (save(cmd |
|
|
335 | cmdtable[cmd] = (save(cmdline), | |
|
329 | 336 | cmdtable['extdiff'][1][1:], |
|
330 | 337 | _('hg %s [OPTION]... [FILE]...') % cmd) |
@@ -94,6 +94,72 b' Check diff are made from the first paren' | |||
|
94 | 94 | diffing */extdiff.*/a.2a13a4d2da36/a a.46c0e4daeb72/a (glob) |
|
95 | 95 | diff-like tools yield a non-zero exit code |
|
96 | 96 | |
|
97 | issue4463: usage of command line configuration without additional quoting | |
|
98 | ||
|
99 | $ cat <<EOF >> $HGRCPATH | |
|
100 | > [extdiff] | |
|
101 | > cmd.4463a = echo | |
|
102 | > opts.4463a = a-naked 'single quoted' "double quoted" | |
|
103 | > 4463b = echo b-naked 'single quoted' "double quoted" | |
|
104 | > echo = | |
|
105 | > EOF | |
|
106 | $ hg update -q -C 0 | |
|
107 | $ echo a >> a | |
|
108 | #if windows | |
|
109 | $ hg --debug 4463a | grep '^running' | |
|
110 | running '"echo" a-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
111 | $ hg --debug 4463b | grep '^running' | |
|
112 | running 'echo b-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
113 | $ hg --debug echo | grep '^running' | |
|
114 | running '"*echo*" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
115 | #else | |
|
116 | $ hg --debug 4463a | grep '^running' | |
|
117 | running '\'echo\' a-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) | |
|
118 | $ hg --debug 4463b | grep '^running' | |
|
119 | running 'echo b-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) | |
|
120 | $ hg --debug echo | grep '^running' | |
|
121 | running "'*echo*' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) | |
|
122 | #endif | |
|
123 | ||
|
124 | (getting options from other than extdiff section) | |
|
125 | ||
|
126 | $ cat <<EOF >> $HGRCPATH | |
|
127 | > [extdiff] | |
|
128 | > # using diff-tools diffargs | |
|
129 | > 4463b2 = echo | |
|
130 | > # using merge-tools diffargs | |
|
131 | > 4463b3 = echo | |
|
132 | > # no diffargs | |
|
133 | > 4463b4 = echo | |
|
134 | > [diff-tools] | |
|
135 | > 4463b2.diffargs = b2-naked 'single quoted' "double quoted" | |
|
136 | > [merge-tools] | |
|
137 | > 4463b3.diffargs = b3-naked 'single quoted' "double quoted" | |
|
138 | > EOF | |
|
139 | #if windows | |
|
140 | $ hg --debug 4463b2 | grep '^running' | |
|
141 | running 'echo b2-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
142 | $ hg --debug 4463b3 | grep '^running' | |
|
143 | running 'echo b3-naked \'single quoted\' "double quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
144 | $ hg --debug 4463b4 | grep '^running' | |
|
145 | running 'echo "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
146 | $ hg --debug 4463b4 --option 'being quoted' | grep '^running' | |
|
147 | running 'echo "being quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
148 | $ hg --debug extdiff -p echo --option 'being quoted' | grep '^running' | |
|
149 | running '"echo" "being quoted" "*\\a" "*\\a"' in */extdiff.* (glob) | |
|
150 | #else | |
|
151 | $ hg --debug 4463b2 | grep '^running' | |
|
152 | running 'echo b2-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) | |
|
153 | $ hg --debug 4463b3 | grep '^running' | |
|
154 | running 'echo b3-naked \'single quoted\' "double quoted" \'*/a\' \'$TESTTMP/a/a\'' in */extdiff.* (glob) | |
|
155 | $ hg --debug 4463b4 | grep '^running' | |
|
156 | running "echo '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) | |
|
157 | $ hg --debug 4463b4 --option 'being quoted' | grep '^running' | |
|
158 | running "echo 'being quoted' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) | |
|
159 | $ hg --debug extdiff -p echo --option 'being quoted' | grep '^running' | |
|
160 | running "'echo' 'being quoted' '*/a' '$TESTTMP/a/a'" in */extdiff.* (glob) | |
|
161 | #endif | |
|
162 | ||
|
97 | 163 | #if execbit |
|
98 | 164 | |
|
99 | 165 | Test extdiff of multiple files in tmp dir: |
@@ -207,7 +273,7 b' Fallback to merge-tools.tool.executable|' | |||
|
207 | 273 | making snapshot of 2 files from working directory |
|
208 | 274 | a |
|
209 | 275 | b |
|
210 |
running "'$TESTTMP/a/dir/tool.sh' |
|
|
276 | running "'$TESTTMP/a/dir/tool.sh' 'a.*' 'a'" in */extdiff.* (glob) | |
|
211 | 277 | ** custom diff ** |
|
212 | 278 | cleaning up temp directory |
|
213 | 279 | [1] |
General Comments 0
You need to be logged in to leave comments.
Login now