mq: copy pager attributes back to qrepo.ui stable
authorYuya Nishihara <yuya@tcha.org>
Sat, 21 Oct 2017 13:42:43 +0900
branchstable
changeset 34918 274811627808
parent 34917 ee9243715c59
child 34919 1856de4d1297
mq: copy pager attributes back to qrepo.ui If the legacy pager extension is enabled, a pager is started through repo.ui at dispatch._runcommand(). After that, mqcommand() creates a qrepo with a fresh repo.baseui, at which point pager information was lost and another pager would be spawned by the modern pager interface. This is a minimal workaround for the problem.
hgext/mq.py
tests/test-pager-legacy.t
--- a/hgext/mq.py	Sat Oct 21 13:13:20 2017 +0900
+++ b/hgext/mq.py	Sat Oct 21 13:42:43 2017 +0900
@@ -1963,6 +1963,14 @@
 
     def qrepo(self, create=False):
         ui = self.baseui.copy()
+        # copy back attributes set by ui.pager()
+        if self.ui.pageractive and not ui.pageractive:
+            ui.pageractive = self.ui.pageractive
+            # internal config: ui.formatted
+            ui.setconfig('ui', 'formatted',
+                         self.ui.config('ui', 'formatted'), 'mqpager')
+            ui.setconfig('ui', 'interactive',
+                         self.ui.config('ui', 'interactive'), 'mqpager')
         if create or os.path.isdir(self.join(".hg")):
             return hg.repository(ui, path=self.path, create=create)
 
--- a/tests/test-pager-legacy.t	Sat Oct 21 13:13:20 2017 +0900
+++ b/tests/test-pager-legacy.t	Sat Oct 21 13:42:43 2017 +0900
@@ -194,6 +194,36 @@
   $ hg --config pager.attend-echoa=yes echoa
   paged! 'a\n'
 
+Pager attributes should be copied to mq repo. Otherwise pager would be started
+twice and color mode would be lost.
+
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > mq =
+  > EOF
+  $ hg init --mq
+  $ hg qnew foo.patch
+  $ hg qpop
+  popping foo.patch
+  patch queue now empty
+  $ hg ci --mq -m 'commit patches'
+  $ hg log --mq --debug
+  starting pager for command 'extension-via-attend-log'
+  paged! '\x1b[0;33mchangeset:   0:6cc2ded15503e368aaf76b6cc3d12f320c9e3b87\x1b[0m\n'
+  paged! 'tag:         tip\n'
+  paged! 'phase:       draft\n'
+  paged! 'parent:      -1:0000000000000000000000000000000000000000\n'
+  paged! 'parent:      -1:0000000000000000000000000000000000000000\n'
+  paged! 'manifest:    0:4980de1ae1b612014d5bcfa9507da84ce8891daa\n'
+  paged! 'user:        test\n'
+  paged! 'date:        Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! 'files+:      .hgignore foo.patch series\n'
+  paged! 'extra:       branch=default\n'
+  paged! 'description:\n'
+  paged! 'commit patches\n'
+  paged! '\n'
+  paged! '\n'
+
 Pager works with hg aliases including environment variables.
 
   $ cat >> $HGRCPATH <<'EOF'