D803: extdiff: allow pager to be used

quark (Jun Wu) phabricator at mercurial-scm.org
Mon Sep 25 18:37:33 EDT 2017


quark updated this revision to Diff 2071.

REPOSITORY
  rHG Mercurial

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

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

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

CHANGE DETAILS

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,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]



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


More information about the Mercurial-devel mailing list