[PATCH] util: Changed shortuser() to provide slightly more verbose names (Issue2276)

David Frey dpfrey at shaw.ca
Tue Aug 3 23:58:15 CDT 2010


# HG changeset patch
# User David Frey <dpfrey at shaw.ca>
# Date 1280897356 25200
# Node ID 5abdad9cb3a4ea47c2d2dd57c03959f392289ffb
# Parent  b6f72d8d77ae5df0dd80b3236169159d020bf269
util: Changed shortuser() to provide slightly more verbose names (Issue2276)

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1130,18 +1130,17 @@
 
 def shortuser(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:]
-    f = user.find(' ')
-    if f >= 0:
-        user = user[:f]
-    f = user.find('.')
-    if f >= 0:
-        user = user[:f]
+    lt = user.find('<')
+    at = user.find('@')
+    gt = user.find('>')
+    if lt >= 0 < at < gt: # e-mail surrounded by <>
+        user = user[lt + 1:at]
+    elif at > 0: # e-mail only
+        user = user[:at]
+    else: # name only
+        sp = user.find(' ')
+        if sp > 0:
+            user = user[:sp]
     return user
 
 def email(author):
diff --git a/tests/test-annotate b/tests/test-annotate
--- a/tests/test-annotate
+++ b/tests/test-annotate
@@ -113,3 +113,13 @@
 echo % annotate after ABA with follow
 hg annotate --follow foo
 
+echo % user formatting
+echo a > formatting
+hg ci -A -m a -u "jdoe at email.com"
+echo b >> formatting
+hg ci -m b -u "John X. Doe <jdoe at email.com>"
+echo c >> formatting
+hg ci -m c -u "John X. Doe <john.doe at email.net>"
+echo d >> formatting
+hg ci -m d -u "John X. Doe"
+hg annotate -u formatting
diff --git a/tests/test-annotate.out b/tests/test-annotate.out
--- a/tests/test-annotate.out
+++ b/tests/test-annotate.out
@@ -103,3 +103,9 @@
 % generate ABA rename configuration
 % annotate after ABA with follow
 foo: foo
+% user formatting
+adding formatting
+    jdoe: a
+    jdoe: b
+john.doe: c
+    John: d


More information about the Mercurial-devel mailing list