Mercurial > hg-stable
changeset 29733:479076db51be
extdiff: refactor closure of saved diff command as a top-level class
This allows us to collect __doc__ for translation.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 27 Jul 2016 21:40:42 +0900 |
parents | 041fecbb588a |
children | 14c3afcb1c26 |
files | hgext/extdiff.py |
diffstat | 1 files changed, 27 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/extdiff.py Wed Jul 27 21:53:14 2016 +0900 +++ b/hgext/extdiff.py Wed Jul 27 21:40:42 2016 +0900 @@ -324,6 +324,32 @@ cmdline = ' '.join(map(util.shellquote, [program] + option)) return dodiff(ui, repo, cmdline, pats, opts) +class savedcmd(object): + """use %(path)s to diff repository (or selected files) + + Show differences between revisions for the specified files, using + the %(path)s 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. + """ + + def __init__(self, path, cmdline): + # We can't pass non-ASCII through docstrings (and path is + # in an unknown encoding anyway) + docpath = path.encode("string-escape") + self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)} + self._cmdline = cmdline + + def __call__(self, ui, repo, *pats, **opts): + options = ' '.join(map(util.shellquote, opts['option'])) + if options: + options = ' ' + options + return dodiff(ui, repo, self._cmdline + options, pats, opts) + def uisetup(ui): for cmd, path in ui.configitems('extdiff'): path = util.expandpath(path) @@ -357,28 +383,5 @@ ui.config('merge-tools', cmd+'.diffargs') if args: cmdline += ' ' + args - def save(cmdline): - '''use closure to save diff command to use''' - def mydiff(ui, repo, *pats, **opts): - options = ' '.join(map(util.shellquote, opts['option'])) - if options: - options = ' ' + options - return dodiff(ui, repo, cmdline + options, pats, opts) - # We can't pass non-ASCII through docstrings (and path is - # in an unknown encoding anyway) - docpath = path.encode("string-escape") - mydiff.__doc__ = '''\ -use %(path)s to diff repository (or selected files) - - Show differences between revisions for the specified files, using - the %(path)s 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.\ -''' % {'path': util.uirepr(docpath)} - return mydiff command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, - inferrepo=True)(save(cmdline)) + inferrepo=True)(savedcmd(path, cmdline))