# HG changeset patch
# User Anton Shestakov <a...@dwimlabs.net>
# Date 1523792494 -28800
#      Sun Apr 15 19:41:34 2018 +0800
# Node ID 2efab3bfa60156194390b82a537514445c12ff86
# Parent  b79993a8e173820205b21cb5c0821183bf68ed39
templates: adjust white space amount in the output of {whyunstable}

There used to be 2 spaces between divergent nodes (when not using custom
template for divergentnodes) because divergentnodes is a hybrid list, which
means it gets ' '.join()ed, but formatnode() already had a space. Now it
doesn't, which requires extra effort in writing custom templates for
whyunstable, but at least it looks correctly by default.

Test output needs to be sorted for stability.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -802,7 +802,7 @@ def showwhyunstable(context, mapping):
     ctx = context.resource(mapping, 'ctx')
 
     def formatnode(ctx):
-        return ' %s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
+        return '%s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
 
     entries = obsutil.whyunstable(repo, ctx)
 
@@ -815,7 +815,8 @@ def showwhyunstable(context, mapping):
             entry['divergentnodes'] = dnhybrid
 
 
-    tmpl = '{instability}:{divergentnodes} {reason} {node|short}'
+    tmpl = ('{instability}:{if(divergentnodes, " ")}{divergentnodes} '
+            '{reason} {node|short}')
     return templateutil.mappinglist(entries, tmpl=tmpl, sep='\n')
 
 def loadkeyword(ui, extname, registrarobj):
diff --git a/tests/test-obsolete-divergent.t b/tests/test-obsolete-divergent.t
--- a/tests/test-obsolete-divergent.t
+++ b/tests/test-obsolete-divergent.t
@@ -17,7 +17,7 @@ Enable obsolete
   > [phases]
   > publish=False
   > [templates]
-  > wuentryshort = '{instability}:{divergentnodes} {reason} {node|shortest}\n'
+  > wuentryshort = '{instability}:{if(divergentnodes, " ")}{divergentnodes} 
{reason} {node|shortest}\n'
   > whyunstableshort = '{whyunstable % wuentryshort}'
   > wuentryshorter = '{instability}:{divergentnodes % " {node|shortest} 
({phase})"} {reason} {node|shortest}\n'
   > whyunstableshorter = '{whyunstable % wuentryshorter}'
@@ -531,6 +531,16 @@ Check more complex obsolescence graft (w
   9:14608b260df8 A_8
   10:bed64f5d2f5a A_9
 
+  $ hg log -r bed64f5d2f5a -T '{whyunstable}\n' | sort
+  content-divergent: 4:01f36c5a8fda (draft) 8:7ae126973a96 (draft) 
9:14608b260df8 (draft) predecessor 007dc284c1f8
+  content-divergent: 8:7ae126973a96 (draft) 9:14608b260df8 (draft) predecessor 
e442cfc57690
+  $ hg log -r bed64f5d2f5a -T whyunstableshort | sort
+  content-divergent: 4:01f36c5a8fda (draft) 8:7ae126973a96 (draft) 
9:14608b260df8 (draft) predecessor 007d
+  content-divergent: 8:7ae126973a96 (draft) 9:14608b260df8 (draft) predecessor 
e442
+  $ hg log -r bed64f5d2f5a -T whyunstableshorter | sort
+  content-divergent: 01f3 (draft) 7ae1 (draft) 1460 (draft) predecessor 007d
+  content-divergent: 7ae1 (draft) 1460 (draft) predecessor e442
+
 fix the divergence
 
   $ mkcommit A_A; hg up 0
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to