Submitter | Boris Feld |
---|---|
Date | Oct. 11, 2017, 12:09 p.m. |
Message ID | <b6b6cb2b16cb2c44b101.1507723793@FB> |
Download | mbox | patch |
Permalink | /patch/24728/ |
State | Accepted |
Headers | show |
Comments
On Wed, 11 Oct 2017 14:09:53 +0200, Boris Feld wrote: > # HG changeset patch > # User Boris Feld <boris.feld@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. Nit: s/allow/accept/ ? > 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 Perhaps we'll need to suppress warning and prompt as well.
On Wed, 2017-10-11 at 22:35 +0900, Yuya Nishihara wrote: > On Wed, 11 Oct 2017 14:09:53 +0200, Boris Feld wrote: > > # HG changeset patch > > # User Boris Feld <boris.feld@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-deve > > l/ -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. > > Nit: s/allow/accept/ ? Good catch, I named it allowempty before renaming acceptempty but this one slipped by. > > > 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 > > Perhaps we'll need to suppress warning and prompt as well. That sounds like a good idea, end-users might be confused why Mercurial asks for their username while doing hg log.
Patch
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'))