[PATCH 05 of 35] extdiff: declare command using decorator
Gregory Szorc
gregory.szorc at gmail.com
Mon May 5 05:51:10 UTC 2014
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1399265641 25200
# Sun May 04 21:54:01 2014 -0700
# Branch stable
# Node ID 38da2ec6633d42f35c021ebad66e14d318b63176
# Parent e091bbd5a746962946723485c099310dfa9fece0
extdiff: declare command using decorator
diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -58,19 +58,21 @@ sections for diff tool arguments, when n
You can use -I/-X and list of file or directory names like normal
:hg:`diff` command. The extdiff extension makes snapshots of only
needed files, so running the external diff program will actually be
pretty fast (at least faster than having to compare the entire tree).
'''
from mercurial.i18n import _
from mercurial.node import short, nullid
-from mercurial import scmutil, scmutil, util, commands, encoding
+from mercurial import cmdutil, scmutil, scmutil, util, commands, encoding
import os, shlex, shutil, tempfile, re
+cmdtable = {}
+command = cmdutil.command(cmdtable)
testedwith = 'internal'
def snapshot(ui, repo, files, node, tmproot):
'''snapshot files as of some revision
if not using snapshot, -I/-X does not work and recursive diff
in tools like kdiff3 and meld displays too many files.'''
dirname = os.path.basename(repo.root)
if dirname == "":
@@ -233,16 +235,25 @@ def dodiff(ui, repo, diffcmd, diffopts,
'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn))
util.copyfile(copy_fn, working_fn)
return 1
finally:
ui.note(_('cleaning up temp directory\n'))
shutil.rmtree(tmproot)
+ at command('extdiff',
+ [('p', 'program', '',
+ _('comparison program to run'), _('CMD')),
+ ('o', 'option', [],
+ _('pass option to comparison program'), _('OPT')),
+ ('r', 'rev', [], _('revision'), _('REV')),
+ ('c', 'change', '', _('change made by revision'), _('REV')),
+ ] + commands.walkopts,
+ _('hg extdiff [OPT]... [FILE]...'))
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, with
default options "-Npru".
To select a different program, use the -p/--program option. The
@@ -257,31 +268,16 @@ def extdiff(ui, repo, *pats, **opts):
to its parent.'''
program = opts.get('program')
option = opts.get('option')
if not program:
program = 'diff'
option = option or ['-Npru']
return dodiff(ui, repo, program, option, pats, opts)
-cmdtable = {
- "extdiff":
- (extdiff,
- [('p', 'program', '',
- _('comparison program to run'), _('CMD')),
- ('o', 'option', [],
- _('pass option to comparison program'), _('OPT')),
- ('r', 'rev', [],
- _('revision'), _('REV')),
- ('c', 'change', '',
- _('change made by revision'), _('REV')),
- ] + commands.walkopts,
- _('hg extdiff [OPT]... [FILE]...')),
- }
-
def uisetup(ui):
for cmd, path in ui.configitems('extdiff'):
if cmd.startswith('cmd.'):
cmd = cmd[4:]
if not path:
path = cmd
diffopts = ui.config('extdiff', 'opts.' + cmd, '')
diffopts = diffopts and [diffopts] or []
More information about the Mercurial-devel
mailing list