# HG changeset patch # User Boris Feld # Date 2017-10-06 14:23:47 # Node ID 9f2891fb426c5396737962b27edea5765a879199 # Parent 6a6371d2970eeefd4174160999483c36dec89541 ui: add the possibility to returns None as username in ui In a later patch we want to retrieve the current username or None if it isn't defined. Add the acceptempty parameter instead of catching Abort. diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -765,13 +765,15 @@ class ui(object): return feature not in exceptions return True - def username(self): + def username(self, acceptempty=False): """Return default username to be used in commits. Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL and stop searching if one of these is set. + If not found and acceptempty is True, returns None. If not found and ui.askusername is True, ask the user, else use ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". + If no username could be found, raise an Abort error. """ user = encoding.environ.get("HGUSER") if user is None: @@ -780,6 +782,8 @@ class ui(object): user = os.path.expandvars(user) if user is None: user = encoding.environ.get("EMAIL") + if user is None and acceptempty: + return user if user is None and self.configbool("ui", "askusername"): user = self.prompt(_("enter a commit username:"), default=None) if user is None and not self.interactive():