Patchwork [4,of,5,V4] templates: display evolution "troubles" in command line style

login
register
mail settings
Submitter Denis Laxalde
Date Jan. 3, 2017, 12:54 p.m.
Message ID <92c6feb3e65561158474.1483448078@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/18087/
State Changes Requested
Headers show

Comments

Denis Laxalde - Jan. 3, 2017, 12:54 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1478597306 -3600
#      Tue Nov 08 10:28:26 2016 +0100
# Node ID 92c6feb3e6556115847482dd82b9f40cf6696556
# Parent  412f8e24f48c8f7006f826a3eeb41f9521c53e4f
# EXP-Topic evolve-ui
templates: display evolution "troubles" in command line style

Add a "trouble" template keyword to fetch evolution troubles, test it in
test-obsolete.t.
Pierre-Yves David - Jan. 4, 2017, 4:23 p.m.
On 01/03/2017 01:54 PM, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1478597306 -3600
> #      Tue Nov 08 10:28:26 2016 +0100
> # Node ID 92c6feb3e6556115847482dd82b9f40cf6696556
> # Parent  412f8e24f48c8f7006f826a3eeb41f9521c53e4f
> # EXP-Topic evolve-ui
> templates: display evolution "troubles" in command line style
>
> Add a "trouble" template keyword to fetch evolution troubles, test it in
> test-obsolete.t.

The main issue with that changesets is that it make the word "troubles" 
leaks into the public space through our documentation. That would 
install some backward compatibility promise on it.

Can you check if marking it "(experimental)" is enough to make it 
disappear from default help ?

Ideally we would have it displayed in the default help (still flagg as 
experimental) if evolution was enabled, but I'm pretty sure we don't 
have such capability now. So a simple (experimental flag would do).

(Also, the introduction of the new template keyword and the change to 
the default style seems to be independent (and already tested 
independently), I would recommend splitting them).

> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -594,5 +594,10 @@ def termwidth(repo, ctx, templ, **args):
>      """Integer. The width of the current terminal."""
>      return repo.ui.termwidth()
>
> +@templatekeyword('trouble')
> +def showtroubles(**args):
> +    """List of evolution troubles of this changeset."""
> +    return showlist('trouble', args['ctx'].troubles(), **args)
> +
>  # tell hggettext to extract docstrings from these functions:
>  i18nfunctions = keywords.values()
> diff --git a/mercurial/templates/map-cmdline.default b/mercurial/templates/map-cmdline.default
> --- a/mercurial/templates/map-cmdline.default
> +++ b/mercurial/templates/map-cmdline.default
> @@ -1,9 +1,9 @@
>  # Base templates. Due to name clashes with existing keywords, we have
>  # to replace some keywords with 'lkeyword', for 'labelled keyword'
> -changeset = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{summary}\n'
> +changeset = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltrouble}{summary}\n'
>  changeset_quiet = '{lnode}'
> -changeset_verbose = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{lfiles}{lfile_copies_switch}{description}\n'
> -changeset_debug = '{fullcset}{branches}{bookmarks}{tags}{lphase}{parents}{manifest}{user}{ldate}{lfile_mods}{lfile_adds}{lfile_dels}{lfile_copies_switch}{extras}{description}\n'
> +changeset_verbose = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltrouble}{lfiles}{lfile_copies_switch}{description}\n'
> +changeset_debug = '{fullcset}{branches}{bookmarks}{tags}{lphase}{parents}{manifest}{user}{ldate}{ltrouble}{lfile_mods}{lfile_adds}{lfile_dels}{lfile_copies_switch}{extras}{description}\n'
>
>  # File templates
>  lfiles = '{if(files,
> @@ -28,7 +28,8 @@ lfile_copies_switch = '{if(file_copies_s
>                                                 % ' {name} ({source})'}\n"))}'
>
>  # General templates
> -_cset_labels = 'log.changeset changeset.{phase}'
> +_trouble_label = 'trouble.{trouble}'
> +_cset_labels = 'log.changeset changeset.{phase}{if(troubles, " changeset.troubled {troubles%_trouble_label}")}'
>  cset = '{label("{_cset_labels}",
>                 "changeset:   {rev}:{node|short}")}\n'
>
> @@ -65,6 +66,9 @@ summary = '{if(desc|strip, "{label('log.
>  ldate = '{label("log.date",
>                  "date:        {date|date}")}\n'
>
> +ltrouble = '{if(trouble, "{label('ui.note log.trouble',
> +                                 'trouble:     {trouble}')}\n")}'
> +
>  extra = '{label("ui.debug log.extra",
>                  "extra:       {key}={value|stringescape}")}\n'
>
> diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
> --- a/tests/test-obsolete.t
> +++ b/tests/test-obsolete.t
> @@ -3,7 +3,7 @@
>    > # public changeset are not obsolete
>    > publish=false
>    > [ui]
> -  > logtemplate="{rev}:{node|short} ({phase}) [{tags} {bookmarks}] {desc|firstline}\n"
> +  > logtemplate="{rev}:{node|short} ({phase}{if(trouble, ' {trouble}')}) [{tags} {bookmarks}] {desc|firstline}\n"
>    > EOF
>    $ mkcommit() {
>    >    echo "$1" > "$1"
> @@ -203,7 +203,7 @@ Check that public changeset are not acco
>
>    $ hg --hidden phase --public 2
>    $ hg log -G
> -  @  5:5601fb93a350 (draft) [tip ] add new_3_c
> +  @  5:5601fb93a350 (draft bumped) [tip ] add new_3_c
>    |
>    | o  2:245bde4270cd (public) [ ] add original_c
>    |/
> @@ -220,7 +220,7 @@ note that the bumped changeset (5:5601fb
>  the public changeset
>
>    $ hg log --hidden -r 'bumped()'
> -  5:5601fb93a350 (draft) [tip ] add new_3_c
> +  5:5601fb93a350 (draft bumped) [tip ] add new_3_c
>
>  And that we can't push bumped changeset
>
> @@ -485,7 +485,7 @@ detect outgoing obsolete and unstable
>    phases: 3 draft
>    unstable: 1 changesets
>    $ hg log -G -r '::unstable()'
> -  @  5:cda648ca50f5 (draft) [tip ] add original_e
> +  @  5:cda648ca50f5 (draft unstable) [tip ] add original_e
>    |
>    x  4:94b33453f93b (draft) [ ] add original_d
>    |
> @@ -527,7 +527,7 @@ Don't try to push extinct changeset
>    2:245bde4270cd (public) [ ] add original_c
>    3:6f9641995072 (draft) [ ] add n3w_3_c
>    4:94b33453f93b (draft) [ ] add original_d
> -  5:cda648ca50f5 (draft) [tip ] add original_e
> +  5:cda648ca50f5 (draft unstable) [tip ] add original_e
>    $ hg push ../tmpf -f # -f because be push unstable too
>    pushing to ../tmpf
>    searching for changes
> @@ -548,7 +548,7 @@ no warning displayed
>  Do not warn about new head when the new head is a successors of a remote one
>
>    $ hg log -G
> -  @  5:cda648ca50f5 (draft) [tip ] add original_e
> +  @  5:cda648ca50f5 (draft unstable) [tip ] add original_e
>    |
>    x  4:94b33453f93b (draft) [ ] add original_d
>    |
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - Jan. 5, 2017, 3:16 p.m.
On Wed, 4 Jan 2017 17:23:52 +0100, Pierre-Yves David wrote:
> On 01/03/2017 01:54 PM, Denis Laxalde wrote:
> > # HG changeset patch
> > # User Denis Laxalde <denis.laxalde@logilab.fr>
> > # Date 1478597306 -3600
> > #      Tue Nov 08 10:28:26 2016 +0100
> > # Node ID 92c6feb3e6556115847482dd82b9f40cf6696556
> > # Parent  412f8e24f48c8f7006f826a3eeb41f9521c53e4f
> > # EXP-Topic evolve-ui
> > templates: display evolution "troubles" in command line style

> > +@templatekeyword('trouble')

Perhaps this should be 'troubles' ?

> > +def showtroubles(**args):
> > +    """List of evolution troubles of this changeset."""
> > +    return showlist('trouble', args['ctx'].troubles(), **args)

> > +_trouble_label = 'trouble.{trouble}'
> > +_cset_labels = 'log.changeset changeset.{phase}{if(troubles, " changeset.troubled {troubles%_trouble_label}")}'

Here 'troubles' keyword is used, and mapped to each singular 'trouble' element.
Pierre-Yves David - Jan. 5, 2017, 7:50 p.m.
On 01/05/2017 04:16 PM, Yuya Nishihara wrote:
> On Wed, 4 Jan 2017 17:23:52 +0100, Pierre-Yves David wrote:
>> On 01/03/2017 01:54 PM, Denis Laxalde wrote:
>>> # HG changeset patch
>>> # User Denis Laxalde <denis.laxalde@logilab.fr>
>>> # Date 1478597306 -3600
>>> #      Tue Nov 08 10:28:26 2016 +0100
>>> # Node ID 92c6feb3e6556115847482dd82b9f40cf6696556
>>> # Parent  412f8e24f48c8f7006f826a3eeb41f9521c53e4f
>>> # EXP-Topic evolve-ui
>>> templates: display evolution "troubles" in command line style
>
>>> +@templatekeyword('trouble')
>
> Perhaps this should be 'troubles' ?

Good catch, we use "bookmark: " in the output but "{bookmarks}" in the 
template. We should do the same for troubles.

>>> +def showtroubles(**args):
>>> +    """List of evolution troubles of this changeset."""
>>> +    return showlist('trouble', args['ctx'].troubles(), **args)
>
>>> +_trouble_label = 'trouble.{trouble}'
>>> +_cset_labels = 'log.changeset changeset.{phase}{if(troubles, " changeset.troubled {troubles%_trouble_label}")}'
>
> Here 'troubles' keyword is used, and mapped to each singular 'trouble' element.

Cheers,

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -594,5 +594,10 @@  def termwidth(repo, ctx, templ, **args):
     """Integer. The width of the current terminal."""
     return repo.ui.termwidth()
 
+@templatekeyword('trouble')
+def showtroubles(**args):
+    """List of evolution troubles of this changeset."""
+    return showlist('trouble', args['ctx'].troubles(), **args)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = keywords.values()
diff --git a/mercurial/templates/map-cmdline.default b/mercurial/templates/map-cmdline.default
--- a/mercurial/templates/map-cmdline.default
+++ b/mercurial/templates/map-cmdline.default
@@ -1,9 +1,9 @@ 
 # Base templates. Due to name clashes with existing keywords, we have
 # to replace some keywords with 'lkeyword', for 'labelled keyword'
-changeset = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{summary}\n'
+changeset = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltrouble}{summary}\n'
 changeset_quiet = '{lnode}'
-changeset_verbose = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{lfiles}{lfile_copies_switch}{description}\n'
-changeset_debug = '{fullcset}{branches}{bookmarks}{tags}{lphase}{parents}{manifest}{user}{ldate}{lfile_mods}{lfile_adds}{lfile_dels}{lfile_copies_switch}{extras}{description}\n'
+changeset_verbose = '{cset}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltrouble}{lfiles}{lfile_copies_switch}{description}\n'
+changeset_debug = '{fullcset}{branches}{bookmarks}{tags}{lphase}{parents}{manifest}{user}{ldate}{ltrouble}{lfile_mods}{lfile_adds}{lfile_dels}{lfile_copies_switch}{extras}{description}\n'
 
 # File templates
 lfiles = '{if(files,
@@ -28,7 +28,8 @@  lfile_copies_switch = '{if(file_copies_s
                                                % ' {name} ({source})'}\n"))}'
 
 # General templates
-_cset_labels = 'log.changeset changeset.{phase}'
+_trouble_label = 'trouble.{trouble}'
+_cset_labels = 'log.changeset changeset.{phase}{if(troubles, " changeset.troubled {troubles%_trouble_label}")}'
 cset = '{label("{_cset_labels}",
                "changeset:   {rev}:{node|short}")}\n'
 
@@ -65,6 +66,9 @@  summary = '{if(desc|strip, "{label('log.
 ldate = '{label("log.date",
                 "date:        {date|date}")}\n'
 
+ltrouble = '{if(trouble, "{label('ui.note log.trouble',
+                                 'trouble:     {trouble}')}\n")}'
+
 extra = '{label("ui.debug log.extra",
                 "extra:       {key}={value|stringescape}")}\n'
 
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -3,7 +3,7 @@ 
   > # public changeset are not obsolete
   > publish=false
   > [ui]
-  > logtemplate="{rev}:{node|short} ({phase}) [{tags} {bookmarks}] {desc|firstline}\n"
+  > logtemplate="{rev}:{node|short} ({phase}{if(trouble, ' {trouble}')}) [{tags} {bookmarks}] {desc|firstline}\n"
   > EOF
   $ mkcommit() {
   >    echo "$1" > "$1"
@@ -203,7 +203,7 @@  Check that public changeset are not acco
 
   $ hg --hidden phase --public 2
   $ hg log -G
-  @  5:5601fb93a350 (draft) [tip ] add new_3_c
+  @  5:5601fb93a350 (draft bumped) [tip ] add new_3_c
   |
   | o  2:245bde4270cd (public) [ ] add original_c
   |/
@@ -220,7 +220,7 @@  note that the bumped changeset (5:5601fb
 the public changeset
 
   $ hg log --hidden -r 'bumped()'
-  5:5601fb93a350 (draft) [tip ] add new_3_c
+  5:5601fb93a350 (draft bumped) [tip ] add new_3_c
 
 And that we can't push bumped changeset
 
@@ -485,7 +485,7 @@  detect outgoing obsolete and unstable
   phases: 3 draft
   unstable: 1 changesets
   $ hg log -G -r '::unstable()'
-  @  5:cda648ca50f5 (draft) [tip ] add original_e
+  @  5:cda648ca50f5 (draft unstable) [tip ] add original_e
   |
   x  4:94b33453f93b (draft) [ ] add original_d
   |
@@ -527,7 +527,7 @@  Don't try to push extinct changeset
   2:245bde4270cd (public) [ ] add original_c
   3:6f9641995072 (draft) [ ] add n3w_3_c
   4:94b33453f93b (draft) [ ] add original_d
-  5:cda648ca50f5 (draft) [tip ] add original_e
+  5:cda648ca50f5 (draft unstable) [tip ] add original_e
   $ hg push ../tmpf -f # -f because be push unstable too
   pushing to ../tmpf
   searching for changes
@@ -548,7 +548,7 @@  no warning displayed
 Do not warn about new head when the new head is a successors of a remote one
 
   $ hg log -G
-  @  5:cda648ca50f5 (draft) [tip ] add original_e
+  @  5:cda648ca50f5 (draft unstable) [tip ] add original_e
   |
   x  4:94b33453f93b (draft) [ ] add original_d
   |