# HG changeset patch # User Benoit Boissinot # Date 1164744965 -3600 # Node ID 98f2507c55510e6335f9cdd8e230c88a08d63e28 # Parent 5cc99f4b5041c6e3a23b28ecbda19e05be6a5d82 only print a warning when no username is specified - revert most of 8b55c0ba - display the username during interactive commit diff -r 5cc99f4b5041 -r 98f2507c5551 doc/hgrc.5.txt --- a/doc/hgrc.5.txt Tue Nov 28 19:11:46 2006 +0100 +++ b/doc/hgrc.5.txt Tue Nov 28 21:16:05 2006 +0100 @@ -419,8 +419,7 @@ username;; The committer of a changeset created when running "commit". Typically a person's name and email address, e.g. "Fred Widget - ". Default is $EMAIL. If no default is found, or the - configured username is empty, it has to be specified manually. + ". Default is $EMAIL or username@hostname. verbose;; Increase the amount of output printed. True or False. Default is False. diff -r 5cc99f4b5041 -r 98f2507c5551 mercurial/localrepo.py --- a/mercurial/localrepo.py Tue Nov 28 19:11:46 2006 +0100 +++ b/mercurial/localrepo.py Tue Nov 28 21:16:05 2006 +0100 @@ -679,6 +679,7 @@ if text: edittext.append(text) edittext.append("") + edittext.append("HG: user: %s" % user) if p2 != nullid: edittext.append("HG: branch merge") edittext.extend(["HG: changed %s" % f for f in changed]) diff -r 5cc99f4b5041 -r 98f2507c5551 mercurial/streamclone.py diff -r 5cc99f4b5041 -r 98f2507c5551 mercurial/ui.py --- a/mercurial/ui.py Tue Nov 28 19:11:46 2006 +0100 +++ b/mercurial/ui.py Tue Nov 28 21:16:05 2006 +0100 @@ -336,8 +336,8 @@ Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL and stop searching if one of these is set. - Abort if no username is found, to force specifying the commit user - with line option or repo hgrc. + If not found, use ($LOGNAME or $USER or $LNAME or + $USERNAME) +"@full.hostname". """ user = os.environ.get("HGUSER") if user is None: @@ -345,12 +345,11 @@ if user is None: user = os.environ.get("EMAIL") if not user: - self.status(_("Please choose a commit username to be recorded " - "in the changelog via\ncommand line option " - '(-u "First Last "), in the\n' - "configuration files (hgrc), or by setting the " - "EMAIL environment variable.\n\n")) - raise util.Abort(_("No commit username specified!")) + try: + user = '%s@%s' % (util.getuser(), socket.getfqdn()) + except KeyError: + raise util.Abort(_("Please specify a username.")) + self.warn(_("No username found, using '%s' instead\n" % user)) return user def shortuser(self, user): diff -r 5cc99f4b5041 -r 98f2507c5551 mercurial/util.py --- a/mercurial/util.py Tue Nov 28 19:11:46 2006 +0100 +++ b/mercurial/util.py Tue Nov 28 21:16:05 2006 +0100 @@ -535,6 +535,20 @@ except AttributeError: return os.name == 'nt' and 'command' in os.environ.get('comspec', '') +getuser_fallback = None + +def getuser(): + '''return name of current user''' + try: + return getpass.getuser() + except ImportError: + # import of pwd will fail on windows - try fallback + if getuser_fallback: + return getuser_fallback() + # raised if win32api not available + raise Abort(_('user name not available - set USERNAME ' + 'environment variable')) + def username(uid=None): """Return the name of the user with the given uid. diff -r 5cc99f4b5041 -r 98f2507c5551 mercurial/util_win32.py --- a/mercurial/util_win32.py Tue Nov 28 19:11:46 2006 +0100 +++ b/mercurial/util_win32.py Tue Nov 28 21:16:05 2006 +0100 @@ -297,3 +297,5 @@ win32file.SetEndOfFile(self.handle) except pywintypes.error, err: raise WinIOError(err) + +getuser_fallback = win32api.GetUserName diff -r 5cc99f4b5041 -r 98f2507c5551 tests/test-committer --- a/tests/test-committer Tue Nov 28 19:11:46 2006 +0100 +++ b/tests/test-committer Tue Nov 28 21:16:05 2006 +0100 @@ -12,8 +12,7 @@ hg tip unset EMAIL -echo 1 > asdf -hg commit -d '1000000 0' -m commit-1 +echo 1234 > asdf hg commit -d '1000000 0' -u "foo@bar.com" -m commit-1 hg tip echo "[ui]" >> .hg/hgrc @@ -24,3 +23,6 @@ echo 1 > asdf hg commit -d '1000000 0' -u "foo@bar.com" -m commit-1 hg tip +echo 123 > asdf +rm .hg/hgrc +hg commit -d '1000000 0' -m commit-1 2>&1 | sed -e "s/[^ \t]*@[^ \t]*/user@host/" diff -r 5cc99f4b5041 -r 98f2507c5551 tests/test-committer.out --- a/tests/test-committer.out Tue Nov 28 19:11:46 2006 +0100 +++ b/tests/test-committer.out Tue Nov 28 21:16:05 2006 +0100 @@ -4,28 +4,22 @@ date: Mon Jan 12 13:46:40 1970 +0000 summary: commit-1 -Please choose a commit username to be recorded in the changelog via -command line option (-u "First Last "), in the -configuration files (hgrc), or by setting the EMAIL environment variable. - -abort: No commit username specified! -transaction abort! -rollback completed -changeset: 1:2becd0bae6e6 +changeset: 1:4997f15a1b24 tag: tip user: foo@bar.com date: Mon Jan 12 13:46:40 1970 +0000 summary: commit-1 -changeset: 2:7a0176714f78 +changeset: 2:72b8012b424e tag: tip user: foobar date: Mon Jan 12 13:46:40 1970 +0000 summary: commit-1 -changeset: 3:f9b58c5a6352 +changeset: 3:35ff3067bedd tag: tip user: foo@bar.com date: Mon Jan 12 13:46:40 1970 +0000 summary: commit-1 +No username found, using user@host instead