ui: add the possibility to returns None as username in ui
authorBoris Feld <boris.feld@octobus.net>
Fri, 06 Oct 2017 16:23:47 +0200
changeset 34849 9f2891fb426c
parent 34848 6a6371d2970e
child 34850 62a4ccf9784a
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.
mercurial/ui.py
--- a/mercurial/ui.py	Fri Oct 06 17:15:49 2017 +0200
+++ b/mercurial/ui.py	Fri Oct 06 16:23:47 2017 +0200
@@ -765,13 +765,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 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 @@
                 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():