Patchwork [5,of,8] pager: use super class's _runpager if possible

login
register
mail settings
Submitter Jun Wu
Date Jan. 9, 2017, 11:12 p.m.
Message ID <24ebef0f19843c6b1b8f.1484003545@x1c>
Download mbox | patch
Permalink /patch/18157/
State Accepted
Headers show

Comments

Jun Wu - Jan. 9, 2017, 11:12 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1484002766 -28800
#      Tue Jan 10 06:59:26 2017 +0800
# Node ID 24ebef0f19843c6b1b8fbf32d99a7e8dba2fb734
# Parent  483eabc8ccbbdfabed7f0f0abd74fb131adcd3c3
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 24ebef0f1984
pager: use super class's _runpager if possible

The ui class is currently pagerui(chgui(ui)), so chgui's _runpager will be
overrided by pagerui. Detect it and use chgui's _runpager, in pager.py.

In the future, when pager is moved to core, pagerui will no longer exist and
ui.py has _runpager implemented directly, and we can just call ui._runpager
without any check.
Jun Wu - Jan. 9, 2017, 11:30 p.m.
Excerpts from Jun Wu's message of 2017-01-10 07:12:25 +0800:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1484002766 -28800
> #      Tue Jan 10 06:59:26 2017 +0800
> # Node ID 24ebef0f19843c6b1b8fbf32d99a7e8dba2fb734
> # Parent  483eabc8ccbbdfabed7f0f0abd74fb131adcd3c3
> # Available At https://bitbucket.org/quark-zju/hg-draft 
> #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 24ebef0f1984
> pager: use super class's _runpager if possible
> 
> The ui class is currently pagerui(chgui(ui)), so chgui's _runpager will be
> overrided by pagerui. Detect it and use chgui's _runpager, in pager.py.
> 
> In the future, when pager is moved to core, pagerui will no longer exist and
> ui.py has _runpager implemented directly, and we can just call ui._runpager
> without any check.
> 
> diff --git a/hgext/pager.py b/hgext/pager.py
> --- a/hgext/pager.py
> +++ b/hgext/pager.py
> @@ -121,5 +121,6 @@ def uisetup(ui):
>      class pagerui(ui.__class__):
>          def _runpager(self, pagercmd):
> -            _runpager(self, pagercmd)
> +            runpager = getattr(super(pagerui, self), '_runpager', _runpager)

I realized that this is wrong (super(...) is not a class but an instance).
Fortunately it seems that this patch could be just dropped without affecting
correctness because how chg works currently.

> +            runpager(self, pagercmd)
>  
>      ui.__class__ = pagerui
Yuya Nishihara - Jan. 10, 2017, 2:44 p.m.
On Tue, 10 Jan 2017 07:30:22 +0800, Jun Wu wrote:
> Excerpts from Jun Wu's message of 2017-01-10 07:12:25 +0800:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1484002766 -28800
> > #      Tue Jan 10 06:59:26 2017 +0800
> > # Node ID 24ebef0f19843c6b1b8fbf32d99a7e8dba2fb734
> > # Parent  483eabc8ccbbdfabed7f0f0abd74fb131adcd3c3
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 24ebef0f1984
> > pager: use super class's _runpager if possible
> > 
> > The ui class is currently pagerui(chgui(ui)), so chgui's _runpager will be
> > overrided by pagerui. Detect it and use chgui's _runpager, in pager.py.
> > 
> > In the future, when pager is moved to core, pagerui will no longer exist and
> > ui.py has _runpager implemented directly, and we can just call ui._runpager
> > without any check.
> > 
> > diff --git a/hgext/pager.py b/hgext/pager.py
> > --- a/hgext/pager.py
> > +++ b/hgext/pager.py
> > @@ -121,5 +121,6 @@ def uisetup(ui):
> >      class pagerui(ui.__class__):
> >          def _runpager(self, pagercmd):
> > -            _runpager(self, pagercmd)
> > +            runpager = getattr(super(pagerui, self), '_runpager', _runpager)
> 
> I realized that this is wrong (super(...) is not a class but an instance).
> Fortunately it seems that this patch could be just dropped without affecting
> correctness because how chg works currently.

Dropped this. Maybe we can simply skip the pagerui wrapping if ui has
_runpager.

Patch

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -121,5 +121,6 @@  def uisetup(ui):
     class pagerui(ui.__class__):
         def _runpager(self, pagercmd):
-            _runpager(self, pagercmd)
+            runpager = getattr(super(pagerui, self), '_runpager', _runpager)
+            runpager(self, pagercmd)
 
     ui.__class__ = pagerui