changeset 182:7533ffec1b5a

Display only the name of the committer, if possible.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 01 Feb 2014 14:04:01 -0800
parents 87d6922340d9
children f940cdefe537
files wikked/scm/base.py wikked/scm/mercurial.py wikked/views/history.py
diffstat 3 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/wikked/scm/base.py	Sat Feb 01 14:03:20 2014 -0800
+++ b/wikked/scm/base.py	Sat Feb 01 14:04:01 2014 -0800
@@ -1,3 +1,5 @@
+import re
+
 
 STATE_COMMITTED = 0
 STATE_MODIFIED = 1
@@ -39,6 +41,20 @@
         raise NotImplementedError()
 
 
+class Author(object):
+    def __init__(self, name=None, email=None):
+        self.name = name
+        self.email = email
+        if name is not None and email is None:
+            m = re.match(r'(?P<name>.+)\s+\<(?P<email>.+@.+\.\w+)\>', name)
+            if m is not None:
+                self.name = str(m.group('name'))
+                self.email = str(m.group('email'))
+
+    def __str__(self):
+        return '%s <%s>' % (self.name, self.email)
+
+
 class Revision(object):
     def __init__(self, rev_id=-1):
         self.rev_id = rev_id
--- a/wikked/scm/mercurial.py	Sat Feb 01 14:03:20 2014 -0800
+++ b/wikked/scm/mercurial.py	Sat Feb 01 14:04:01 2014 -0800
@@ -8,7 +8,7 @@
 from hglib.error import CommandError
 from hglib.util import cmdbuilder
 from base import (
-        SourceControl, Revision, SourceControlError,
+        SourceControl, Author, Revision, SourceControlError,
         ACTION_ADD, ACTION_EDIT, ACTION_DELETE,
         STATE_NEW, STATE_MODIFIED, STATE_COMMITTED)
 
@@ -141,7 +141,7 @@
         rev.rev_id = int(m.group(1))
         rev.rev_name = rev.rev_id[:12]
         rev.rev_hash = m.group(2)
-        rev.author = m.group(3)
+        rev.author = Author(m.group(3))
         rev.timestamp = float(m.group(4))
 
         i = 1
@@ -198,7 +198,7 @@
         for rev in repo_revs:
             r = Revision(rev.node)
             r.rev_name = rev.node[:12]
-            r.author = unicode(rev.author)
+            r.author = Author(rev.author)
             r.timestamp = time.mktime(rev.date.timetuple())
             r.description = unicode(rev.desc)
             if needs_files:
--- a/wikked/views/history.py	Sat Feb 01 14:03:20 2014 -0800
+++ b/wikked/views/history.py	Sat Feb 01 14:04:01 2014 -0800
@@ -19,7 +19,7 @@
             'index': i + 1,
             'rev_id': rev.rev_id,
             'rev_name': rev.rev_name,
-            'author': rev.author,
+            'author': rev.author.name,
             'timestamp': rev.timestamp,
             'description': rev.description
             }