Patchwork D803: extdiff: allow pager to be used

login
register
mail settings
Submitter phabricator
Date Sept. 25, 2017, 10:34 p.m.
Message ID <d08828beea06e5607c27627a27a1ce71@localhost.localdomain>
Download mbox | patch
Permalink /patch/24143/
State Not Applicable
Headers show

Comments

phabricator - Sept. 25, 2017, 10:34 p.m.
quark updated this revision to Diff 2070.
quark edited the summary of this revision.
quark retitled this revision from "extdiff: use pager" to "extdiff: allow pager to be used".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D803?vs=2046&id=2070

REVISION DETAIL
  https://phab.mercurial-scm.org/D803

AFFECTED FILES
  hgext/extdiff.py
  tests/test-extdiff.t

CHANGE DETAILS




To: quark, #hg-reviewers, yuja
Cc: yuja, indygreg, mercurial-devel

Patch

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 <<EOF
+  > import sys
+  > for line in sys.stdin:
+  >     sys.stdout.write('paged! %s' % line)
+  > sys.stdout.flush()
+  > EOF
+
+  $ cat >> $HGRCPATH <<EOF
+  > [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
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,12 @@ 
         cmdline = re.sub(regex, quote, cmdline)
 
         ui.debug('running %r in %s\n' % (cmdline, tmproot))
+
+        # Unlike opt-out behavior, extdiff pager is opt-in, ex. users need to
+        # explicitly enable pager for certain commands. This is because we have
+        # no idea whether the external program uses curses or GUI.
+        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 +342,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 +359,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 +408,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]