Patchwork [07,of,11] ui: add the possibility to returns None as username in ui

mail settings
Submitter Boris Feld
Date Oct. 9, 2017, 6:40 p.m.
Message ID <7a980312f1ef903557c0.1507574449@FB>
Download mbox | patch
Permalink /patch/24671/
State Superseded
Headers show


Boris Feld - Oct. 9, 2017, 6:40 p.m.
# HG changeset patch
# User Boris Feld <>
# Date 1507299827 -7200
#      Fri Oct 06 16:23:47 2017 +0200
# Node ID 7a980312f1ef903557c040ea44b61395d3591f8f
# Parent  73e204102f7e4af7172c9e88e39675ca73cfc34f
# EXP-Topic obsfatekeyword
# Available At
#              hg pull -r 7a980312f1ef
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 allowempty parameter instead of catching Abort.


diff -r 73e204102f7e -r 7a980312f1ef mercurial/
--- a/mercurial/	Fri Oct 06 17:15:49 2017 +0200
+++ b/mercurial/	Fri Oct 06 16:23:47 2017 +0200
@@ -758,13 +758,15 @@ 
             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 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 or returns None if
+        acceptempty is True.
         user = encoding.environ.get("HGUSER")
         if user is None:
@@ -782,6 +784,9 @@ 
             except KeyError:
         if not user:
+            if acceptempty:
+                return user
             raise error.Abort(_('no username supplied'),
                              hint=_("use 'hg config --edit' "
                                     'to set your username'))