Mercurial > hg
comparison hgext/extdiff.py @ 29721: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 | 67b180c0e263 |
children | 14c3afcb1c26 |
comparison
equal
deleted
inserted
replaced
29720:041fecbb588a | 29721:479076db51be |
---|---|
321 if not program: | 321 if not program: |
322 program = 'diff' | 322 program = 'diff' |
323 option = option or ['-Npru'] | 323 option = option or ['-Npru'] |
324 cmdline = ' '.join(map(util.shellquote, [program] + option)) | 324 cmdline = ' '.join(map(util.shellquote, [program] + option)) |
325 return dodiff(ui, repo, cmdline, pats, opts) | 325 return dodiff(ui, repo, cmdline, pats, opts) |
326 | |
327 class savedcmd(object): | |
328 """use %(path)s to diff repository (or selected files) | |
329 | |
330 Show differences between revisions for the specified files, using | |
331 the %(path)s program. | |
332 | |
333 When two revision arguments are given, then changes are shown | |
334 between those revisions. If only one revision is specified then | |
335 that revision is compared to the working directory, and, when no | |
336 revisions are specified, the working directory files are compared | |
337 to its parent. | |
338 """ | |
339 | |
340 def __init__(self, path, cmdline): | |
341 # We can't pass non-ASCII through docstrings (and path is | |
342 # in an unknown encoding anyway) | |
343 docpath = path.encode("string-escape") | |
344 self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)} | |
345 self._cmdline = cmdline | |
346 | |
347 def __call__(self, ui, repo, *pats, **opts): | |
348 options = ' '.join(map(util.shellquote, opts['option'])) | |
349 if options: | |
350 options = ' ' + options | |
351 return dodiff(ui, repo, self._cmdline + options, pats, opts) | |
326 | 352 |
327 def uisetup(ui): | 353 def uisetup(ui): |
328 for cmd, path in ui.configitems('extdiff'): | 354 for cmd, path in ui.configitems('extdiff'): |
329 path = util.expandpath(path) | 355 path = util.expandpath(path) |
330 if cmd.startswith('cmd.'): | 356 if cmd.startswith('cmd.'): |
355 if not diffopts: | 381 if not diffopts: |
356 args = ui.config('diff-tools', cmd+'.diffargs') or \ | 382 args = ui.config('diff-tools', cmd+'.diffargs') or \ |
357 ui.config('merge-tools', cmd+'.diffargs') | 383 ui.config('merge-tools', cmd+'.diffargs') |
358 if args: | 384 if args: |
359 cmdline += ' ' + args | 385 cmdline += ' ' + args |
360 def save(cmdline): | |
361 '''use closure to save diff command to use''' | |
362 def mydiff(ui, repo, *pats, **opts): | |
363 options = ' '.join(map(util.shellquote, opts['option'])) | |
364 if options: | |
365 options = ' ' + options | |
366 return dodiff(ui, repo, cmdline + options, pats, opts) | |
367 # We can't pass non-ASCII through docstrings (and path is | |
368 # in an unknown encoding anyway) | |
369 docpath = path.encode("string-escape") | |
370 mydiff.__doc__ = '''\ | |
371 use %(path)s to diff repository (or selected files) | |
372 | |
373 Show differences between revisions for the specified files, using | |
374 the %(path)s program. | |
375 | |
376 When two revision arguments are given, then changes are shown | |
377 between those revisions. If only one revision is specified then | |
378 that revision is compared to the working directory, and, when no | |
379 revisions are specified, the working directory files are compared | |
380 to its parent.\ | |
381 ''' % {'path': util.uirepr(docpath)} | |
382 return mydiff | |
383 command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, | 386 command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, |
384 inferrepo=True)(save(cmdline)) | 387 inferrepo=True)(savedcmd(path, cmdline)) |