templates: adjust white space amount in the output of {whyunstable}
authorAnton Shestakov <av6@dwimlabs.net>
Sun, 15 Apr 2018 19:41:34 +0800
changeset 37707 24fee31fda05
parent 37706 04b89360913c
child 37708 8e8541610d85
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.
mercurial/templatekw.py
tests/test-obsolete-divergent.t
--- a/mercurial/templatekw.py	Sun Apr 15 19:28:01 2018 +0800
+++ b/mercurial/templatekw.py	Sun Apr 15 19:41:34 2018 +0800
@@ -802,7 +802,7 @@
     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)
 
@@ -814,7 +814,8 @@
                                lambda x: formatnode(repo[x]))
             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):
--- a/tests/test-obsolete-divergent.t	Sun Apr 15 19:28:01 2018 +0800
+++ b/tests/test-obsolete-divergent.t	Sun Apr 15 19:41:34 2018 +0800
@@ -17,7 +17,7 @@
   > [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 @@
   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