# 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 --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -419,8 +419,7 @@ ui:: 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 --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -679,6 +679,7 @@ class localrepository(repo.repository): 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 --git a/mercurial/streamclone.py b/mercurial/streamclone.py diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -336,8 +336,8 @@ class ui(object): 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 @@ class ui(object): 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 --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -535,6 +535,20 @@ def is_win_9x(): 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 --git a/mercurial/util_win32.py b/mercurial/util_win32.py --- a/mercurial/util_win32.py +++ b/mercurial/util_win32.py @@ -297,3 +297,5 @@ class posixfile_nt(object): win32file.SetEndOfFile(self.handle) except pywintypes.error, err: raise WinIOError(err) + +getuser_fallback = win32api.GetUserName diff --git a/tests/test-committer b/tests/test-committer --- a/tests/test-committer +++ b/tests/test-committer @@ -12,8 +12,7 @@ hg commit -d '1000000 0' -m commit-1 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 @@ hg tip 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 --git a/tests/test-committer.out b/tests/test-committer.out --- a/tests/test-committer.out +++ b/tests/test-committer.out @@ -4,28 +4,22 @@ user: My Name "), 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