diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -472,14 +472,7 @@ def annotate(ui, repo, *pats, **opts): 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 --git a/mercurial/hgweb.py b/mercurial/hgweb.py --- a/mercurial/hgweb.py +++ b/mercurial/hgweb.py @@ -507,14 +507,7 @@ class hgweb: 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 --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -78,6 +78,16 @@ class ui: 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"):