diff --git a/hgext/extdiff.py b/hgext/extdiff.py --- a/hgext/extdiff.py +++ b/hgext/extdiff.py @@ -58,6 +58,12 @@ :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). + +Pager is disabled by default. To enable pager for an extdiff command, set:: + + [pager] + attend-cdiff = true + ''' from __future__ import absolute_import @@ -127,7 +133,7 @@ fnsandstat.append((dest, repo.wjoin(fn), os.lstat(dest))) return dirname, fnsandstat -def dodiff(ui, repo, cmdline, pats, opts): +def dodiff(ui, repo, cmdname, cmdline, pats, opts): '''Do the actual diff: - copy to a temp structure if diffing 2 internal revisions @@ -272,6 +278,13 @@ cmdline = re.sub(regex, quote, cmdline) ui.debug('running %r in %s\n' % (cmdline, tmproot)) + + # Unlike the default opt-out behavior, extdiff pager is opt-in. i.e. + # users need to explicitly enable pager for extdiff commands. This is + # because pager should not be used if the external program uses curses + # or GUI, which we cannot tell here. + if ui.configbool('pager', 'attend-%s' % cmdname): + ui.pager(cmdname) ui.system(cmdline, cwd=tmproot, blockedtag='extdiff') for copy_fn, working_fn, st in fnsandstat: @@ -330,7 +343,7 @@ program = 'diff' option = option or ['-Npru'] cmdline = ' '.join(map(util.shellquote, [program] + option)) - return dodiff(ui, repo, cmdline, pats, opts) + return dodiff(ui, repo, 'extdiff', cmdline, pats, opts) class savedcmd(object): """use external program to diff repository (or selected files) @@ -347,18 +360,20 @@ to its parent. """ - def __init__(self, path, cmdline): + def __init__(self, path, cmdline, cmdname): # We can't pass non-ASCII through docstrings (and path is # in an unknown encoding anyway) docpath = util.escapestr(path) self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)} self._cmdline = cmdline + self._cmdname = cmdname 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) + return dodiff(ui, repo, self._cmdname, self._cmdline + options, pats, + opts) def uisetup(ui): for cmd, path in ui.configitems('extdiff'): @@ -394,7 +409,7 @@ if args: cmdline += ' ' + args command(cmd, extdiffopts[:], _('hg %s [OPTION]... [FILE]...') % cmd, - inferrepo=True)(savedcmd(path, cmdline)) + inferrepo=True)(savedcmd(path, cmdline, cmd)) # tell hggettext to extract docstrings from these functions: i18nfunctions = [savedcmd] diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t --- a/tests/test-extdiff.t +++ b/tests/test-extdiff.t @@ -1,5 +1,16 @@ - $ echo "[extensions]" >> $HGRCPATH - $ echo "extdiff=" >> $HGRCPATH + $ cat >> $TESTTMP/fakepager.py < import sys + > for line in sys.stdin: + > sys.stdout.write('paged! %s' % line) + > sys.stdout.flush() + > EOF + + $ cat >> $HGRCPATH < [pager] + > pager=$PYTHON $TESTTMP/fakepager.py + > [extensions] + > extdiff= + > EOF $ hg init a $ cd a @@ -109,6 +120,15 @@ diffing */extdiff.*/a.2a13a4d2da36/a a.46c0e4daeb72/a (glob) (no-windows !) diff-like tools yield a non-zero exit code +Pager can be used if explicitly specified: + + $ hg falabala -c 1 --config ui.formatted=yes --config pager.attend-falabala=1 + paged! * (glob) + [1] + $ hg extdiff -p echo -r 0 --config ui.formatted=yes --config pager.attend-extdiff=1 + paged! * (glob) + [1] + issue3153: ensure using extdiff with removed subrepos doesn't crash: $ hg init suba