Patchwork log: add an extension hook-point in changeset_printer

login
register
mail settings
Submitter Boris Feld
Date June 28, 2017, 2:02 p.m.
Message ID <51dd67d33413b1219a9d.1498658549@FB>
Download mbox | patch
Permalink /patch/21799/
State Superseded
Headers show

Comments

Boris Feld - June 28, 2017, 2:02 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1498484784 -7200
#      Mon Jun 26 15:46:24 2017 +0200
# Node ID 51dd67d33413b1219a9dccf87bf8a0306cc9fb5d
# Parent  247bae545061374a683d8d9369a4869aa6ae4537
# EXP-Topic changesetprinterhook
log: add an extension hook-point in changeset_printer

Extensions sometimes wants to add other information in the default log output
format (when no templating is used).

Add an empty function named 'exthook' for easing the extension life.
Extensions will be able to wrap this function and collaborate to display
additional information.

Exthook is called after displaying troubles and just before displaying the
files, extra and description.
Yuya Nishihara - June 29, 2017, 2:05 p.m.
On Wed, 28 Jun 2017 16:02:29 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1498484784 -7200
> #      Mon Jun 26 15:46:24 2017 +0200
> # Node ID 51dd67d33413b1219a9dccf87bf8a0306cc9fb5d
> # Parent  247bae545061374a683d8d9369a4869aa6ae4537
> # EXP-Topic changesetprinterhook
> log: add an extension hook-point in changeset_printer

Seems fine. Can you add a test?

> diff -r 247bae545061 -r 51dd67d33413 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Tue Jun 27 23:50:22 2017 +0900
> +++ b/mercurial/cmdutil.py	Mon Jun 26 15:46:24 2017 +0200
> @@ -1381,6 +1381,7 @@
>              for name in ns.names(self.repo, changenode):
>                  self.ui.write(ns.logfmt % name,
>                                label='log.%s' % ns.colorname)
> +
>          if self.ui.debugflag:
>              # i18n: column positioning for "hg log"
>              self.ui.write(_("phase:       %s\n") % ctx.phasestr(),
> @@ -1411,6 +1412,8 @@
>              self.ui.write(_("trouble:     %s\n") % ', '.join(ctx.troubles()),
>                            label='log.trouble')
>  
> +        self.exthook(ctx)
> +
>          if self.ui.debugflag:
>              files = ctx.p1().status(ctx)[:3]
>              for key, value in zip([# i18n: column positioning for "hg log"
> @@ -1457,6 +1460,11 @@
>  
>          self.showpatch(ctx, matchfn)
>  
> +    def exthook(self, ctx):
> +        '''empty method used by extension as a hook point
> +        '''
> +        pass

I slightly prefer "_exthook" as this isn't a public function of
changeset_printer.
Boris Feld - June 29, 2017, 5:41 p.m.
On Thu, 2017-06-29 at 23:05 +0900, Yuya Nishihara wrote:
> On Wed, 28 Jun 2017 16:02:29 +0200, Boris Feld wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld@octobus.net>
> > # Date 1498484784 -7200
> > #      Mon Jun 26 15:46:24 2017 +0200
> > # Node ID 51dd67d33413b1219a9dccf87bf8a0306cc9fb5d
> > # Parent  247bae545061374a683d8d9369a4869aa6ae4537
> > # EXP-Topic changesetprinterhook
> > log: add an extension hook-point in changeset_printer
> 
> Seems fine. Can you add a test?

Yes of course, I just send the new patch few minutes ago.
> 
> > diff -r 247bae545061 -r 51dd67d33413 mercurial/cmdutil.py
> > --- a/mercurial/cmdutil.py	Tue Jun 27 23:50:22 2017 +0900
> > +++ b/mercurial/cmdutil.py	Mon Jun 26 15:46:24 2017 +0200
> > @@ -1381,6 +1381,7 @@
> >              for name in ns.names(self.repo, changenode):
> >                  self.ui.write(ns.logfmt % name,
> >                                label='log.%s' % ns.colorname)
> > +
> >          if self.ui.debugflag:
> >              # i18n: column positioning for "hg log"
> >              self.ui.write(_("phase:       %s\n") % ctx.phasestr(),
> > @@ -1411,6 +1412,8 @@
> >              self.ui.write(_("trouble:     %s\n") % ',
> > '.join(ctx.troubles()),
> >                            label='log.trouble')
> >  
> > +        self.exthook(ctx)
> > +
> >          if self.ui.debugflag:
> >              files = ctx.p1().status(ctx)[:3]
> >              for key, value in zip([# i18n: column positioning for
> > "hg log"
> > @@ -1457,6 +1460,11 @@
> >  
> >          self.showpatch(ctx, matchfn)
> >  
> > +    def exthook(self, ctx):
> > +        '''empty method used by extension as a hook point
> > +        '''
> > +        pass
> 
> I slightly prefer "_exthook" as this isn't a public function of
> changeset_printer.

I renamed exthook to _exthook in the V2 serie.

Patch

diff -r 247bae545061 -r 51dd67d33413 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Tue Jun 27 23:50:22 2017 +0900
+++ b/mercurial/cmdutil.py	Mon Jun 26 15:46:24 2017 +0200
@@ -1381,6 +1381,7 @@ 
             for name in ns.names(self.repo, changenode):
                 self.ui.write(ns.logfmt % name,
                               label='log.%s' % ns.colorname)
+
         if self.ui.debugflag:
             # i18n: column positioning for "hg log"
             self.ui.write(_("phase:       %s\n") % ctx.phasestr(),
@@ -1411,6 +1412,8 @@ 
             self.ui.write(_("trouble:     %s\n") % ', '.join(ctx.troubles()),
                           label='log.trouble')
 
+        self.exthook(ctx)
+
         if self.ui.debugflag:
             files = ctx.p1().status(ctx)[:3]
             for key, value in zip([# i18n: column positioning for "hg log"
@@ -1457,6 +1460,11 @@ 
 
         self.showpatch(ctx, matchfn)
 
+    def exthook(self, ctx):
+        '''empty method used by extension as a hook point
+        '''
+        pass
+
     def showpatch(self, ctx, matchfn):
         if not matchfn:
             matchfn = self.matchfn