changeset 2993:725b660d9886

topics: show the user who last touched the topic in --age This patch adds support for showing the user who last touched the topic in the age option to `hg topics`.
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 25 Sep 2017 03:23:06 +0530
parents db3c85c2cb47
children 1e8ac0fcd6b7
files hgext3rd/topic/__init__.py tests/test-topic.t
diffstat 2 files changed, 39 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- a/tests/test-topic.t	Mon Sep 25 03:06:37 2017 +0530
+++ b/tests/test-topic.t	Mon Sep 25 03:23:06 2017 +0530
@@ -38,7 +38,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
   
@@ -904,7 +905,7 @@
   t0^ Add file delta (base)
 
   $ hg topics --age
-   * changewut (1970-01-01)
+   * changewut (1970-01-01 by test)
 
   $ cd ..
 
@@ -951,24 +952,24 @@
 
   $ hg add b
   $ hg topic topic1990
-  $ hg ci -m "Added b" --config devel.default-date="631152000 0"
+  $ hg ci -m "Added b" --config devel.default-date="631152000 0" --user "foo"
   active topic 'topic1990' grew its first changeset
   $ hg add c
   $ hg topic topic2010
-  $ hg ci -m "Added c" --config devel.default-date="1262304000 0"
+  $ hg ci -m "Added c" --config devel.default-date="1262304000 0" --user "bar"
   active topic 'topic2010' grew its first changeset
 
   $ hg log -G
-  @  changeset:   3:9048b194797d
+  @  changeset:   3:76b16af75125
   |  tag:         tip
   |  topic:       topic2010
-  |  user:        test
+  |  user:        bar
   |  date:        Fri Jan 01 00:00:00 2010 +0000
   |  summary:     Added c
   |
-  o  changeset:   2:186d493c7f8d
+  o  changeset:   2:bba5bde53608
   |  topic:       topic1990
-  |  user:        test
+  |  user:        foo
   |  date:        Mon Jan 01 00:00:00 1990 +0000
   |  summary:     Added b
   |
@@ -985,17 +986,17 @@
    * topic2010
 
   $ hg topics --age
-   * topic2010 (2010-01-01)
-     topic1990 (1990-01-01)
-     topic1970 (1970-01-01)
+   * topic2010 (2010-01-01 by bar)
+     topic1990 (1990-01-01 by foo)
+     topic1970 (1970-01-01 by test)
 
   $ hg up topic1970
   switching to topic topic1970
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
 
   $ hg topics --age
-     topic2010 (2010-01-01)
-     topic1990 (1990-01-01)
-   * topic1970 (1970-01-01)
+     topic2010 (2010-01-01 by bar)
+     topic1990 (1990-01-01 by foo)
+   * topic1970 (1970-01-01 by test)
 
   $ cd ..