Patchwork [4,of,5] templates-default: do not show description or summary if empty

login
register
mail settings
Submitter Yuya Nishihara
Date April 7, 2015, 2:07 p.m.
Message ID <64dbe8bab8efdde40c24.1428415662@mimosa>
Download mbox | patch
Permalink /patch/8533/
State Accepted
Headers show

Comments

Yuya Nishihara - April 7, 2015, 2:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1427461973 -32400
#      Fri Mar 27 22:12:53 2015 +0900
# Node ID 64dbe8bab8efdde40c241b658b606ef8cee849a1
# Parent  a019d816cc08bf16135e1e22c32eae56fc2d32da
templates-default: do not show description or summary if empty

changeset_printer shows description only if ctx.description().strip() is not
empty. The default template should do the same way.
Pierre-Yves David - April 7, 2015, 6:34 p.m.
On 04/07/2015 07:07 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1427461973 -32400
> #      Fri Mar 27 22:12:53 2015 +0900
> # Node ID 64dbe8bab8efdde40c241b658b606ef8cee849a1
> # Parent  a019d816cc08bf16135e1e22c32eae56fc2d32da
> templates-default: do not show description or summary if empty

This very one is pushed to the clowncopter.

Patch

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
@@ -58,8 +58,8 @@  bookmark = '{label("log.bookmark",
 user = '{label("log.user",
                "user:        {author}")}\n'
 
-summary = '{label("log.summary",
-                  "summary:     {desc|firstline}")}\n'
+summary = '{if(desc|strip, "{label('log.summary',
+                                   'summary:     {desc|firstline}')}\n")}'
 
 ldate = '{label("log.date",
                 "date:        {date|date}")}\n'
@@ -67,7 +67,7 @@  ldate = '{label("log.date",
 extra = '{label("ui.debug log.extra",
                 "extra:       {key}={value|stringescape}")}\n'
 
-description = '{label("ui.note log.description",
-                       "description:")}
-               {label("ui.note log.description",
-                       "{desc|strip}")}\n\n'
+description = '{if(desc|strip, "{label('ui.note log.description',
+                                       'description:')}
+                                {label('ui.note log.description',
+                                       '{desc|strip}')}\n\n")}'
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -108,6 +108,10 @@  Template should precede style option
 
 Default style is like normal output:
 
+  $ echo c >> c
+  $ hg add c
+  $ hg commit -qm ' '
+
   $ hg log > log.out
   $ hg log --style default > style.out
   $ cmp log.out style.out || diff -u log.out style.out
@@ -147,6 +151,8 @@  Default style should also preserve color
 
   $ mv $HGRCPATH-bak $HGRCPATH
 
+  $ hg --config extensions.strip= strip -q .
+
 Revision with no copies (used to print a traceback):
 
   $ hg tip -v --template '\n'