Patchwork [STABLE] mq: copy pager attributes back to qrepo.ui

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 21, 2017, 5:16 a.m.
Message ID <aff8579c731276bed3d2.1508563010@mimosa>
Download mbox | patch
Permalink /patch/25265/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 21, 2017, 5:16 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1508560963 -32400
#      Sat Oct 21 13:42:43 2017 +0900
# Branch stable
# Node ID aff8579c731276bed3d2afe416dc4988042e89c9
# Parent  dc05c59e3f1714c4faceb4c1eed66a5afe0ec000
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.
Augie Fackler - Oct. 22, 2017, 7:26 p.m.
> On Oct 21, 2017, at 1:16 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1508560963 -32400
> #      Sat Oct 21 13:42:43 2017 +0900
> # Branch stable
> # Node ID aff8579c731276bed3d2afe416dc4988042e89c9
> # Parent  dc05c59e3f1714c4faceb4c1eed66a5afe0ec000
> mq: copy pager attributes back to qrepo.ui

queued, thanks

> 
> 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.
> 
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -1963,6 +1963,14 @@ class queue(object):
> 
>     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)
> 
> diff --git a/tests/test-pager-legacy.t b/tests/test-pager-legacy.t
> --- a/tests/test-pager-legacy.t
> +++ b/tests/test-pager-legacy.t
> @@ -194,6 +194,36 @@ Pager works with shell aliases.
>   $ 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'
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1963,6 +1963,14 @@  class queue(object):
 
     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)
 
diff --git a/tests/test-pager-legacy.t b/tests/test-pager-legacy.t
--- a/tests/test-pager-legacy.t
+++ b/tests/test-pager-legacy.t
@@ -194,6 +194,36 @@  Pager works with shell aliases.
   $ 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'