obsfate: by default only display the username if differ from the current one
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 16 Jun 2017 18:38:04 +0200
changeset 2612 fd35b428edfc
parent 2611 45f5dbb24684
child 2613 3d432af2f6cd
child 2622 6e5f5de46c50
obsfate: by default only display the username if differ from the current one This will will keep the output simple in the simple case.
hgext3rd/evolve/templatekw.py
tests/test-evolve-templates.t
--- a/hgext3rd/evolve/templatekw.py	Fri Jun 16 18:03:32 2017 +0200
+++ b/hgext3rd/evolve/templatekw.py	Fri Jun 16 18:38:04 2017 +0200
@@ -9,6 +9,7 @@
 """
 
 from . import (
+    error,
     exthelper,
     obshistory
 )
@@ -108,7 +109,14 @@
     return templatekw._hybrid(iter(gen), data, lambda x: {'successorset': x},
                               lambda d: d["successorset"])
 
-def obsfatedefaulttempl():
+def _getusername(ui):
+    """the default username in the config or None"""
+    try:
+        return ui.username()
+    except error.Abort: # no easy way to avoid ui raising Abort here :-/
+        return None
+
+def obsfatedefaulttempl(ui):
     """ Returns a dict with the default templates for obs fate
     """
     # Prepare templates
@@ -120,10 +128,16 @@
     datetempl = '{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq)
     newline = '\n'
 
+    optionalusertempl = usertempl
+    username = _getusername(ui)
+    if username is not None:
+        optionalusertempl = ('{ifeq(join(users, "\0"), "%s", "", "%s")}'
+                             % (username, usertempl))
+
     # Assemble them
     return {
         'obsfate_quiet': verbtempl + succtempl + newline,
-        'obsfate': verbtempl + usertempl + succtempl + newline,
+        'obsfate': verbtempl + optionalusertempl + succtempl + newline,
         'obsfate_verbose': verbtempl + usertempl + succtempl + datetempl + newline
     }
 
@@ -173,7 +187,7 @@
         values.append(raw)
 
     # Insert default obsfate templates
-    args['templ'].cache.update(obsfatedefaulttempl())
+    args['templ'].cache.update(obsfatedefaulttempl(repo.ui))
 
     if repo.ui.quiet:
         name = "obsfate_quiet"
--- a/tests/test-evolve-templates.t	Fri Jun 16 18:03:32 2017 +0200
+++ b/tests/test-evolve-templates.t	Fri Jun 16 18:38:04 2017 +0200
@@ -346,7 +346,7 @@
   | @  471597cad322
   |/     Successors: [337fec4d2edc, f257fde29c7a]
   |      semi-colon: [337fec4d2edc, f257fde29c7a]
-  |      Fate: split by test as 337fec4d2edc, f257fde29c7a
+  |      Fate: split as 337fec4d2edc, f257fde29c7a
   |
   o  ea207398892e
   
@@ -356,7 +356,7 @@
   o  337fec4d2edc
   |
   | @  471597cad322
-  |/     Obsfate: split by test as 337fec4d2edc, f257fde29c7a
+  |/     Obsfate: split as 337fec4d2edc, f257fde29c7a
   |
   o  ea207398892e
   
@@ -385,7 +385,7 @@
   | x  471597cad322
   |/     Successors: [337fec4d2edc, f257fde29c7a]
   |      semi-colon: [337fec4d2edc, f257fde29c7a]
-  |      Fate: split by test as 337fec4d2edc, f257fde29c7a
+  |      Fate: split as 337fec4d2edc, f257fde29c7a
   |
   o  ea207398892e
   
@@ -395,7 +395,7 @@
   o  337fec4d2edc
   |
   | x  471597cad322
-  |/     Obsfate: split by test as 337fec4d2edc, f257fde29c7a
+  |/     Obsfate: split as 337fec4d2edc, f257fde29c7a
   |
   o  ea207398892e
   
@@ -480,7 +480,7 @@
   | @  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -488,7 +488,7 @@
   o  eb5a0daa2192
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -506,12 +506,12 @@
   | @  0dec01379d3b
   | |    Successors: [eb5a0daa2192]
   | |    semi-colon: [eb5a0daa2192]
-  | |    Fate: rewritten by test as eb5a0daa2192
+  | |    Fate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -519,10 +519,10 @@
   o  eb5a0daa2192
   |
   | @  0dec01379d3b
-  | |    Obsfate: rewritten by test as eb5a0daa2192
+  | |    Obsfate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -546,12 +546,12 @@
   | x  0dec01379d3b
   | |    Successors: [eb5a0daa2192]
   | |    semi-colon: [eb5a0daa2192]
-  | |    Fate: rewritten by test as eb5a0daa2192
+  | |    Fate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -559,10 +559,10 @@
   @  eb5a0daa2192
   |
   | x  0dec01379d3b
-  | |    Obsfate: rewritten by test as eb5a0daa2192
+  | |    Obsfate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -659,8 +659,8 @@
   | @  471f378eab4c
   |/     Successors: [fdf9bde5129a], [019fadeab383]
   |      semi-colon: [fdf9bde5129a]; [019fadeab383]
-  |      Fate: rewritten by test as fdf9bde5129a
-  |    rewritten by test as 019fadeab383
+  |      Fate: rewritten as fdf9bde5129a
+  |    rewritten as 019fadeab383
   |
   o  ea207398892e
   
@@ -670,8 +670,8 @@
   | o  fdf9bde5129a
   |/
   | @  471f378eab4c
-  |/     Obsfate: rewritten by test as fdf9bde5129a
-  |    rewritten by test as 019fadeab383
+  |/     Obsfate: rewritten as fdf9bde5129a
+  |    rewritten as 019fadeab383
   |
   o  ea207398892e
   
@@ -705,7 +705,7 @@
   |      semi-colon: 471f378eab4c
   |      Successors: [019fadeab383]
   |      semi-colon: [019fadeab383]
-  |      Fate: rewritten by test as 019fadeab383
+  |      Fate: rewritten as 019fadeab383
   |
   | @  fdf9bde5129a
   |/     Precursors: 471f378eab4c
@@ -713,8 +713,8 @@
   | x  471f378eab4c
   |/     Successors: [fdf9bde5129a], [65b757b745b9]
   |      semi-colon: [fdf9bde5129a]; [65b757b745b9]
-  |      Fate: rewritten by test as fdf9bde5129a
-  |    rewritten by test as 65b757b745b9
+  |      Fate: rewritten as fdf9bde5129a
+  |    rewritten as 65b757b745b9
   |
   o  ea207398892e
   
@@ -722,13 +722,13 @@
   o  019fadeab383
   |
   | x  65b757b745b9
-  |/     Obsfate: rewritten by test as 019fadeab383
+  |/     Obsfate: rewritten as 019fadeab383
   |
   | @  fdf9bde5129a
   |/
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as fdf9bde5129a
-  |    rewritten by test as 65b757b745b9
+  |/     Obsfate: rewritten as fdf9bde5129a
+  |    rewritten as 65b757b745b9
   |
   o  ea207398892e
   
@@ -826,7 +826,7 @@
   | @  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -834,7 +834,7 @@
   o  eb5a0daa2192
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -849,12 +849,12 @@
   | @  0dec01379d3b
   | |    Successors: [eb5a0daa2192]
   | |    semi-colon: [eb5a0daa2192]
-  | |    Fate: rewritten by test as eb5a0daa2192
+  | |    Fate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -862,10 +862,10 @@
   o  eb5a0daa2192
   |
   | @  0dec01379d3b
-  | |    Obsfate: rewritten by test as eb5a0daa2192
+  | |    Obsfate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -881,12 +881,12 @@
   | @  b7ea6d14e664
   | |    Successors: [eb5a0daa2192]
   | |    semi-colon: [eb5a0daa2192]
-  | |    Fate: rewritten by test as eb5a0daa2192
+  | |    Fate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -894,10 +894,10 @@
   o  eb5a0daa2192
   |
   | @  b7ea6d14e664
-  | |    Obsfate: rewritten by test as eb5a0daa2192
+  | |    Obsfate: rewritten as eb5a0daa2192
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -918,17 +918,17 @@
   | |    semi-colon: 0dec01379d3b
   | |    Successors: [eb5a0daa2192]
   | |    semi-colon: [eb5a0daa2192]
-  | |    Fate: rewritten by test as eb5a0daa2192
+  | |    Fate: rewritten as eb5a0daa2192
   | |
   | | x  0dec01379d3b
   | |/     Successors: [b7ea6d14e664]
   | |      semi-colon: [b7ea6d14e664]
-  | |      Fate: rewritten by test as b7ea6d14e664
+  | |      Fate: rewritten as b7ea6d14e664
   | |
   | x  471f378eab4c
   |/     Successors: [eb5a0daa2192]
   |      semi-colon: [eb5a0daa2192]
-  |      Fate: rewritten by test as eb5a0daa2192
+  |      Fate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -936,13 +936,13 @@
   @  eb5a0daa2192
   |
   | x  b7ea6d14e664
-  | |    Obsfate: rewritten by test as eb5a0daa2192
+  | |    Obsfate: rewritten as eb5a0daa2192
   | |
   | | x  0dec01379d3b
-  | |/     Obsfate: rewritten by test as b7ea6d14e664
+  | |/     Obsfate: rewritten as b7ea6d14e664
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten by test as eb5a0daa2192
+  |/     Obsfate: rewritten as eb5a0daa2192
   |
   o  ea207398892e
   
@@ -1051,7 +1051,7 @@
   | @  471f378eab4c
   |/     Successors: [7a230b46bf61]
   |      semi-colon: [7a230b46bf61]
-  |      Fate: rewritten by test as 7a230b46bf61
+  |      Fate: rewritten as 7a230b46bf61
   |
   o  ea207398892e
   
@@ -1082,7 +1082,7 @@
   | x  471f378eab4c
   |/     Successors: [7a230b46bf61]
   |      semi-colon: [7a230b46bf61]
-  |      Fate: rewritten by test as 7a230b46bf61
+  |      Fate: rewritten as 7a230b46bf61
   |
   o  ea207398892e
   
@@ -1127,7 +1127,7 @@
   (use 'hg evolve' to update to its parent successor)
   $ hg tlog
   @  471f378eab4c
-  |    Fate: pruned by test
+  |    Fate: pruned
   |
   o  ea207398892e