[PATCH 1 of 8] Move generating short username to display in hg/hgweb annotate to ui module

Thomas Arendsen Hein thomas at intevation.de
Sun Aug 28 11:54:51 CDT 2005


# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID ee4f60abad9399dd1e3c5671f6790044e64dbe52
# Parent  8bf19f96b97ad6447adef4640ac0d0e46c0bea05
Move generating short username to display in hg/hgweb annotate to ui module.

diff -r 8bf19f96b97a -r ee4f60abad93 mercurial/commands.py
--- a/mercurial/commands.py	Sun Aug 28 14:41:16 2005
+++ b/mercurial/commands.py	Sun Aug 28 15:29:28 2005
@@ -472,14 +472,7 @@
             return bcache[rev]
         except KeyError:
             cl = repo.changelog.read(repo.changelog.node(rev))
-            name = cl[1]
-            f = name.find('@')
-            if f >= 0:
-                name = name[:f]
-            f = name.find('<')
-            if f >= 0:
-                name = name[f+1:]
-            bcache[rev] = name
+            bcache[rev] = name = ui.shortuser(cl[1])
             return name
 
     if not pats:
diff -r 8bf19f96b97a -r ee4f60abad93 mercurial/hgweb.py
--- a/mercurial/hgweb.py	Sun Aug 28 14:41:16 2005
+++ b/mercurial/hgweb.py	Sun Aug 28 15:29:28 2005
@@ -507,14 +507,7 @@
                     name = bcache[r]
                 except KeyError:
                     cl = self.repo.changelog.read(cnode)
-                    name = cl[1]
-                    f = name.find('@')
-                    if f >= 0:
-                        name = name[:f]
-                    f = name.find('<')
-                    if f >= 0:
-                        name = name[f+1:]
-                    bcache[r] = name
+                    bcache[r] = name = self.repo.ui.shortuser(cl[1])
 
                 if last != cnode:
                     parity = 1 - parity
diff -r 8bf19f96b97a -r ee4f60abad93 mercurial/ui.py
--- a/mercurial/ui.py	Sun Aug 28 14:41:16 2005
+++ b/mercurial/ui.py	Sun Aug 28 15:29:28 2005
@@ -78,6 +78,16 @@
                                 os.environ.get("USERNAME", "unknown"))
                  + '@' + socket.getfqdn()))
 
+    def shortuser(self, user):
+        """Return a short representation of a user name or email address."""
+        f = user.find('@')
+        if f >= 0:
+            user = user[:f]
+        f = user.find('<')
+        if f >= 0:
+            user = user[f+1:]
+        return user
+
     def expandpath(self, loc):
         paths = {}
         for name, path in self.configitems("paths"):


More information about the Mercurial mailing list