From ad47ec66c1d15f855dccdfd690ab64dd32b3f94d Mon Sep 17 00:00:00 2001 From: Vadim Gelfer Date: Mon, 14 Aug 2006 15:51:35 -0700 Subject: [PATCH] extdiff: fix bugs. add test. --- hgext/extdiff.py | 31 ++++++++++++++++++++----------- tests/test-extdiff | 26 ++++++++++++++++++++++++++ tests/test-extdiff.out | 31 +++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) create mode 100755 tests/test-extdiff create mode 100644 tests/test-extdiff.out diff --git a/hgext/extdiff.py b/hgext/extdiff.py index f3db6db3e7..6383ebd859 100644 --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -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:], diff --git a/tests/test-extdiff b/tests/test-extdiff new file mode 100755 index 0000000000..1723d60eff --- /dev/null +++ b/tests/test-extdiff @@ -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 diff --git a/tests/test-extdiff.out b/tests/test-extdiff.out new file mode 100644 index 0000000000..5979f43e2d --- /dev/null +++ b/tests/test-extdiff.out @@ -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