Patchwork [6,of,9] template: show user in obsfateprinter

login
register
mail settings
Submitter Boris Feld
Date July 6, 2017, 9:50 p.m.
Message ID <ae148d33f0cff729874e.1499377814@FB>
Download mbox | patch
Permalink /patch/22050/
State Changes Requested, archived
Headers show

Comments

Boris Feld - July 6, 2017, 9:50 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499088840 -7200
#      Mon Jul 03 15:34:00 2017 +0200
# Node ID ae148d33f0cff729874e141d9638960da19b0232
# Parent  955b9374e3bee67ac49bf2924f44be67a6528747
# EXP-Topic obsfatetemplate
template: show user in obsfateprinter

Extract, deduplicate users informations from obs markers in order to display
them.

Obsfate display them differently in verbose mode or not:
- In verbose mode, they are all displayed
- In other cases, only users different from default user are displayed. The
  logic here is that an user should remember what changes he made so in most
  cases that would be extraneous information.

Patch

diff -r 955b9374e3be -r ae148d33f0cf mercurial/obsutil.py
--- a/mercurial/obsutil.py	Mon Jul 03 15:33:27 2017 +0200
+++ b/mercurial/obsutil.py	Mon Jul 03 15:34:00 2017 +0200
@@ -564,8 +564,21 @@ 
         verb = 'split'
     return {'verb': verb}
 
+def _successorsetusers(successorset, markers):
+    """ Returns a sorted list of markers users without duplicates
+    """
+    if not markers:
+        return {}
+
+    # Check that user is present in meta
+    markersmeta = [dict(m[3]) for m in markers]
+    users = set(meta.get('user') for meta in markersmeta if meta.get('user'))
+
+    return {'users': sorted(users)}
+
 FORMATSSETSFUNCTIONS = [
     _successorsetverb,
+    _successorsetusers,
 ]
 
 def preparesuccessorset(successorset, rawmarkers):
diff -r 955b9374e3be -r ae148d33f0cf mercurial/templatekw.py
--- a/mercurial/templatekw.py	Mon Jul 03 15:33:27 2017 +0200
+++ b/mercurial/templatekw.py	Mon Jul 03 15:34:00 2017 +0200
@@ -634,6 +634,13 @@ 
     return _hybrid(gen(data), data, lambda x: {'successorset': x},
                    lambda d: d["successorset"])
 
+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 _obsfatelineprinter(obsfateline, repo, ui):
     """Format and display obsfate related data
     """
@@ -647,6 +654,17 @@ 
     # Verb
     line.append(obsfateline['verb'])
 
+    # Users
+    if (verbose or normal) and 'users' in obsfateline:
+        users = obsfateline['users']
+
+        if normal:
+            username = _getusername(ui)
+            users = [user for user in users if user != username]
+
+        if users:
+            line.append(" by %s" % ", ".join(users))
+
     # Successors
     successors = obsfateline["successors"]
 
@@ -675,6 +693,7 @@ 
 
     This line will contains these information:
     - The list of closest successors in the log output
+    - The users which have evolve the changeset
     """
 
     # Get the needed obsfate data
diff -r 955b9374e3be -r ae148d33f0cf tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t	Mon Jul 03 15:33:27 2017 +0200
+++ b/tests/test-obsmarker-template.t	Mon Jul 03 15:34:00 2017 +0200
@@ -95,14 +95,14 @@ 
   o  d004c8f274b9
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:d004c8f274b9
+  |/     Obsfate: rewritten by test1, test2 as 4:d004c8f274b9
   o  ea207398892e
   
   $ hg fatelog -v
   o  d004c8f274b9
   |
   | @  471f378eab4c
-  |/     Obsfate: rewritten as 4:d004c8f274b9
+  |/     Obsfate: rewritten by test1, test2 as 4:d004c8f274b9
   o  ea207398892e
   
   $ hg up 'desc(A1)' --hidden
@@ -125,7 +125,7 @@ 
   o  d004c8f274b9
   |
   | @  a468dc9b3633
-  |/     Obsfate: rewritten as 4:d004c8f274b9
+  |/     Obsfate: rewritten by test2 as 4:d004c8f274b9
   o  ea207398892e
   
 Predecessors template should show all the predecessors as we force their display
@@ -205,14 +205,13 @@ 
   @  d004c8f274b9
   |
   | x  a468dc9b3633
-  |/     Obsfate: rewritten as 4:d004c8f274b9
+  |/     Obsfate: rewritten by test2 as 4:d004c8f274b9
   | x  f137d23bb3e1
   | |
   | x  471f378eab4c
-  |/     Obsfate: rewritten as 3:a468dc9b3633
+  |/     Obsfate: rewritten by test1 as 3:a468dc9b3633
   o  ea207398892e
   
-
 Test templates with splitted commit
 ===================================