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

Boris Feld boris.feld at octobus.net
Wed Oct 11 08:09:53 EDT 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1507299827 -7200
#      Fri Oct 06 16:23:47 2017 +0200
# Node ID b6b6cb2b16cb2c44b10113134e212bae5b47adb0
# Parent  c6979350fac712aae8bd776553b3c7692a8136cf
# EXP-Topic obsfatekeyword
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b6b6cb2b16cb
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 --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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:
                 pass
         if not user:
+            if acceptempty:
+                return user
+
             raise error.Abort(_('no username supplied'),
                              hint=_("use 'hg config --edit' "
                                     'to set your username'))


More information about the Mercurial-devel mailing list