Mercurial > evolve
changeset 3371:753e5ebabe7d
topics: take logic to parse username to a separate function
In next patch we will be adding support to `hg stack` to show users, and this
logic will be required there too. So let's take it out in a separate function.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 27 Dec 2017 23:51:18 +0530 |
parents | 1face8964965 |
children | 4138771105bb |
files | hgext3rd/topic/__init__.py hgext3rd/topic/stack.py |
diffstat | 2 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py Fri Jan 05 22:50:21 2018 +0100 +++ b/hgext3rd/topic/__init__.py Wed Dec 27 23:51:18 2017 +0530 @@ -1009,16 +1009,7 @@ 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() - + username = stack.parseusername(user) topicuser = (t, username) if trevs:
--- a/hgext3rd/topic/stack.py Fri Jan 05 22:50:21 2018 +0100 +++ b/hgext3rd/topic/stack.py Wed Dec 27 23:51:18 2017 +0530 @@ -28,6 +28,23 @@ if not util.safehasattr(context.basectx, 'isunstable'): context.basectx.isunstable = context.basectx.troubled +def parseusername(user): + """parses the ctx user and returns the username without email ID if + possible, otherwise returns the mail address from that""" + username = None + if user: + # user is of form "abc <abc@xyz.com>" + username = user.split('<')[0] + if not username: + # assuming user is of form "<abc@xyz.com>" + if len(user) > 1: + username = user[1:-1] + else: + username = user + username = username.strip() + + return username + def _stackcandidates(repo): """build the smaller set of revs that might be part of a stack.