obsfate: improve obsfate output stable
authorBoris Feld <boris.feld@octobus.net>
Sat, 17 Jun 2017 01:02:37 +0200
branchstable
changeset 2629 9c0f6b85c28f
parent 2628 8cdb9fb29cde
child 2630 8503ba8b82e3
child 2658 ae822f28b617
obsfate: improve obsfate output Improve obsfate output: * Remove newline and replace it by '; ' * Improve the hybrid object for making join(obsfate, '|') working.
README
hgext3rd/evolve/templatekw.py
tests/test-evolve-templates.t
--- a/README	Mon Jun 19 18:37:28 2017 +0200
+++ b/README	Sat Jun 17 01:02:37 2017 +0200
@@ -121,6 +121,11 @@
 Changelog
 =========
 
+6.4.1 - in progress
+-------------------
+
+ - obsfate: improve support for advanced template reformating
+
 6.4.0 -- 2017-06-16
 -------------------
 
--- a/hgext3rd/evolve/templatekw.py	Mon Jun 19 18:37:28 2017 +0200
+++ b/hgext3rd/evolve/templatekw.py	Sat Jun 17 01:02:37 2017 +0200
@@ -126,7 +126,6 @@
     datetempleq = ' (at {min_date|isodate})'
     datetemplnoteq = ' (between {min_date|isodate} and {max_date|isodate})'
     datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq)
-    newline = '\n'
 
     optionalusertempl = usertempl
     username = _getusername(ui)
@@ -136,9 +135,9 @@
 
     # Assemble them
     return {
-        'obsfate_quiet': verbtempl + succtempl + newline,
-        'obsfate': verbtempl + optionalusertempl + succtempl + newline,
-        'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline
+        'obsfate_quiet': verbtempl + succtempl,
+        'obsfate': verbtempl + optionalusertempl + succtempl,
+        'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl,
     }
 
 @eh.templatekw("obsfate")
@@ -198,7 +197,29 @@
     else:
         name = "obsfate"
 
-    return templatekw.showlist(name, values, args, separator=' + ')
+    # Format a single value
+    def fmt(d):
+        nargs = args.copy()
+        nargs.update(d[name])
+        return args['templ'](name, **nargs)
+
+    # Generate a good enough string representation using templater
+    gen = []
+    for d in values:
+        chunk = fmt({name: d})
+        chunkstr = []
+
+        # Empty the generator
+        try:
+            while True:
+                chunkstr.append(chunk.next())
+        except StopIteration:
+            pass
+
+        gen.append("".join(chunkstr))
+    gen = "; ".join(gen)
+
+    return templatekw._hybrid(gen, values, lambda x: {name: x}, fmt)
 
 # copy from mercurial.obsolete with a small change to stop at first known changeset.
 
--- a/tests/test-evolve-templates.t	Mon Jun 19 18:37:28 2017 +0200
+++ b/tests/test-evolve-templates.t	Sat Jun 17 01:02:37 2017 +0200
@@ -17,8 +17,8 @@
   >     {if(precursors, "\n  semi-colon: {join(precursors, "; ")}")}\
   >     {if(successors, "\n  Successors: {successors}")}\
   >     {if(successors, "\n  semi-colon: {join(successors, "; ")}")}\
-  >     {if(obsfate, "\n  Fate: {obsfate}")}\n'
-  > fatelog = log -G -T '{node|short}\n{if(obsfate, "  Obsfate: {obsfate}\n")}'
+  >     {if(obsfate, "\n  Fate: {join(obsfate, "\n  Fate: ")}\n")}\n'
+  > fatelog = log -G -T '{node|short}\n{if(obsfate, "  Obsfate: {join(obsfate, "; ")}\n\n")}'
   > fatelogjson = log -G -T '{node|short} {obsfate|json}\n'
   > EOF
 
@@ -660,7 +660,7 @@
   |/     Successors: [fdf9bde5129a], [019fadeab383]
   |      semi-colon: [fdf9bde5129a]; [019fadeab383]
   |      Fate: rewritten as fdf9bde5129a
-  |    rewritten as 019fadeab383
+  |      Fate: rewritten as 019fadeab383
   |
   o  ea207398892e
   
@@ -670,8 +670,7 @@
   | o  fdf9bde5129a
   |/
   | @  471f378eab4c
-  |/     Obsfate: rewritten as fdf9bde5129a
-  |    rewritten as 019fadeab383
+  |/     Obsfate: rewritten as fdf9bde5129a; rewritten as 019fadeab383
   |
   o  ea207398892e
   
@@ -714,7 +713,7 @@
   |/     Successors: [fdf9bde5129a], [65b757b745b9]
   |      semi-colon: [fdf9bde5129a]; [65b757b745b9]
   |      Fate: rewritten as fdf9bde5129a
-  |    rewritten as 65b757b745b9
+  |      Fate: rewritten as 65b757b745b9
   |
   o  ea207398892e
   
@@ -727,8 +726,7 @@
   | @  fdf9bde5129a
   |/
   | x  471f378eab4c
-  |/     Obsfate: rewritten as fdf9bde5129a
-  |    rewritten as 65b757b745b9
+  |/     Obsfate: rewritten as fdf9bde5129a; rewritten as 65b757b745b9
   |
   o  ea207398892e