mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
extdiff: fix bugs. add test.
This commit is contained in:
parent
bc3e797936
commit
ad47ec66c1
@ -35,7 +35,7 @@ from mercurial.i18n import gettext as _
|
||||
from mercurial.node import *
|
||||
demandload(globals(), 'mercurial:commands,cmdutil,util os shutil tempfile')
|
||||
|
||||
def dodiff(ui, repo, diffcmd, pats, opts):
|
||||
def dodiff(ui, repo, diffcmd, diffopts, pats, opts):
|
||||
def snapshot_node(files, node):
|
||||
'''snapshot files as of some revision'''
|
||||
changes = repo.changelog.read(node)
|
||||
@ -92,10 +92,12 @@ def dodiff(ui, repo, diffcmd, pats, opts):
|
||||
dir2 = snapshot_node(modified + added, node2)
|
||||
else:
|
||||
dir2 = snapshot_wdir(modified + added)
|
||||
util.system('%s %s %s %s' %
|
||||
(util.shellquote(diffcmd), ' '.join(opts['option']),
|
||||
util.shellquote(dir1), util.shellquote(dir2)),
|
||||
cwd=tmproot)
|
||||
cmdline = ('%s %s %s %s' %
|
||||
(util.shellquote(diffcmd),
|
||||
' '.join(map(util.shellquote, diffopts)),
|
||||
util.shellquote(dir1), util.shellquote(dir2)))
|
||||
ui.debug('running %r in %s\n' % (cmdline, tmproot))
|
||||
util.system(cmdline, cwd=tmproot)
|
||||
return 1
|
||||
finally:
|
||||
ui.note(_('cleaning up temp directory\n'))
|
||||
@ -105,7 +107,9 @@ def extdiff(ui, repo, *pats, **opts):
|
||||
'''use external program to diff repository (or selected files)
|
||||
|
||||
Show differences between revisions for the specified files, using
|
||||
an external program. The default program used is "diff -Npru".
|
||||
an external program. The default program used is diff, with
|
||||
default options "-Npru".
|
||||
|
||||
To select a different program, use the -p option. The program
|
||||
will be passed the names of two directories to compare. To pass
|
||||
additional options to the program, use the -o option. These will
|
||||
@ -116,7 +120,8 @@ def extdiff(ui, repo, *pats, **opts):
|
||||
specified then that revision is compared to the working
|
||||
directory, and, when no revisions are specified, the
|
||||
working directory files are compared to its parent.'''
|
||||
return dodiff(ui, repo, opts['program'] or 'diff -Npru', pats, opts)
|
||||
return dodiff(ui, repo, opts['program'] or 'diff',
|
||||
opts['option'] or ['-Npru'], pats, opts)
|
||||
|
||||
cmdtable = {
|
||||
"extdiff":
|
||||
@ -134,20 +139,24 @@ def uisetup(ui):
|
||||
if not cmd.startswith('cmd.'): continue
|
||||
cmd = cmd[4:]
|
||||
if not path: path = cmd
|
||||
diffopts = ui.config('extdiff', 'opts.' + cmd, '')
|
||||
diffopts = diffopts and [diffopts] or []
|
||||
def save(cmd, path):
|
||||
'''use closure to save diff command to use'''
|
||||
def mydiff(ui, repo, *pats, **opts):
|
||||
return dodiff(ui, repo, path, pats, opts)
|
||||
mydiff.__doc__ = '''use %s to diff repository (or selected files)
|
||||
return dodiff(ui, repo, path, diffopts, pats, opts)
|
||||
mydiff.__doc__ = '''use %(path)r to diff repository (or selected files)
|
||||
|
||||
Show differences between revisions for the specified
|
||||
files, using the %s program.
|
||||
files, using the %(path)r program.
|
||||
|
||||
When two revision arguments are given, then changes are
|
||||
shown between those revisions. If only one revision is
|
||||
specified then that revision is compared to the working
|
||||
directory, and, when no revisions are specified, the
|
||||
working directory files are compared to its parent.''' % (cmd, cmd)
|
||||
working directory files are compared to its parent.''' % {
|
||||
'path': path,
|
||||
}
|
||||
return mydiff
|
||||
cmdtable[cmd] = (save(cmd, path),
|
||||
cmdtable['extdiff'][1][1:],
|
||||
|
26
tests/test-extdiff
Executable file
26
tests/test-extdiff
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
HGRCPATH=$HGTMP/.hgrc; export HGRCPATH
|
||||
echo "[extensions]" >> $HGTMP/.hgrc
|
||||
echo "extdiff=" >> $HGTMP/.hgrc
|
||||
|
||||
hg init a
|
||||
cd a
|
||||
echo a > a
|
||||
hg add
|
||||
hg extdiff -o -Nr
|
||||
|
||||
echo "[extdiff]" >> $HGTMP/.hgrc
|
||||
echo "cmd.falabala=echo" >> $HGTMP/.hgrc
|
||||
echo "opts.falabala=diffing" >> $HGTMP/.hgrc
|
||||
|
||||
hg falabala
|
||||
|
||||
hg help falabala
|
||||
|
||||
hg ci -d '0 0' -mtest1
|
||||
|
||||
echo b >> a
|
||||
hg ci -d '1 0' -mtest2
|
||||
|
||||
hg falabala -r 0:1
|
31
tests/test-extdiff.out
Normal file
31
tests/test-extdiff.out
Normal file
@ -0,0 +1,31 @@
|
||||
adding a
|
||||
making snapshot of 0 files from rev 000000000000
|
||||
making snapshot of 1 files from working dir
|
||||
diff -Nr a.000000000000/a a/a
|
||||
0a1
|
||||
> a
|
||||
making snapshot of 0 files from rev 000000000000
|
||||
making snapshot of 1 files from working dir
|
||||
diffing a.000000000000 a
|
||||
hg falabala [OPT]... [FILE]...
|
||||
|
||||
use 'echo' to diff repository (or selected files)
|
||||
|
||||
Show differences between revisions for the specified
|
||||
files, using the 'echo' program.
|
||||
|
||||
When two revision arguments are given, then changes are
|
||||
shown between those revisions. If only one revision is
|
||||
specified then that revision is compared to the working
|
||||
directory, and, when no revisions are specified, the
|
||||
working directory files are compared to its parent.
|
||||
|
||||
options:
|
||||
|
||||
-o --option pass option to comparison program
|
||||
-r --rev revision
|
||||
-I --include include names matching the given patterns
|
||||
-X --exclude exclude names matching the given patterns
|
||||
making snapshot of 1 files from rev e27a2475d60a
|
||||
making snapshot of 1 files from rev 5e49ec8d3f05
|
||||
diffing a.e27a2475d60a a.5e49ec8d3f05
|
Loading…
Reference in New Issue
Block a user