# HG changeset patch # User Yuya Nishihara # Date 1469623242 -32400 # Node ID 479076db51be9ad5275dc2b257939cc26cab7cd3 # Parent 041fecbb588afd26f1826ecc76dd52639134bdc0 extdiff: refactor closure of saved diff command as a top-level class This allows us to collect __doc__ for translation. diff -r 041fecbb588a -r 479076db51be hgext/extdiff.py --- 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))