Patchwork [3,of,7,V3] ui: add the possibility to returns None as username in ui

login
register
mail settings
Submitter Boris Feld
Date Oct. 17, 2017, 3:14 p.m.
Message ID <fc484d70e64944dc3e91.1508253244@FB>
Download mbox | patch
Permalink /patch/25116/
State Accepted
Headers show

Comments

Boris Feld - Oct. 17, 2017, 3:14 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1507299827 -7200
#      Fri Oct 06 16:23:47 2017 +0200
# Node ID fc484d70e64944dc3e918efdca08ec0ca8466c4d
# Parent  89093dd3ab72c2b2e3b95f6a69414ab2a174c910
# EXP-Topic obsfatekeyword
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fc484d70e649
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.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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():