hgext3rd/topic/__init__.py
changeset 2993 725b660d9886
parent 2992 db3c85c2cb47
child 2994 1e8ac0fcd6b7
--- a/hgext3rd/topic/__init__.py	Mon Sep 25 03:06:37 2017 +0530
+++ b/hgext3rd/topic/__init__.py	Mon Sep 25 03:23:06 2017 +0530
@@ -405,7 +405,8 @@
 
       hg topics
 
-    List of topics with their last touched time sorted according to it::
+    List of topics sorted according to their last touched time displaying last
+    touched time and the user who last touched the topic::
 
       hg topic --age
 
@@ -789,7 +790,7 @@
     activetopic = repo.currenttopic
     for timevalue in times:
         curtopics = sorted(timedict[timevalue][1])
-        for topic in curtopics:
+        for topic, user in curtopics:
             fm.startitem()
             marker = ' '
             label = 'topic'
@@ -806,6 +807,8 @@
             else:
                 timestr = templatefilters.age(timedict[timevalue][0])
             fm.write('lasttouched', '%s', timestr, label='topic.list.time')
+            if user:
+                fm.write('usertouched', ' by %s', user, label='topic.list.user')
             fm.plain(')')
             fm.plain('\n')
     fm.end()
@@ -819,6 +822,7 @@
     curtime = time.time()
     for t in topics:
         secspassed = -1
+        user = None
         maxtime = (0, 0)
         trevs = repo.revs("topic(%s)", t)
         # Need to check for the time of all changesets in the topic, whether
@@ -826,23 +830,38 @@
         # XXX: can we just rely on the max rev number for this
         for revs in trevs:
             rt = repo[revs].date()
-            if rt[0] > maxtime[0]:
+            if rt[0] >= maxtime[0]:
                 # Can store the rev to gather more info
                 # latesthead = revs
                 maxtime = rt
+                user = repo[revs].user()
             # looking on the markers also to get more information and accurate
             # last touch time.
             obsmarkers = compat.getmarkers(repo, [repo[revs].node()])
             for marker in obsmarkers:
                 rt = marker.date()
                 if rt[0] > maxtime[0]:
+                    user = marker.metadata().get('user', user)
                     maxtime = rt
+
+        # Making the username more better
+        username = None
+        if user:
+            # user is of form "abc <abc@xyz.com>"
+            username = user.split('<')[0]
+            if not username:
+                # user is of form "<abc@xyz.com>"
+                username = user[1:-1]
+            username = username.strip()
+
+        topicuser = (t, username)
+
         if trevs:
             secspassed = (curtime - maxtime[0])
         try:
-            topicstime[secspassed][1].append(t)
+            topicstime[secspassed][1].append(topicuser)
         except KeyError:
-            topicstime[secspassed] = (maxtime, [t])
+            topicstime[secspassed] = (maxtime, [topicuser])
 
     return topicstime