changeset 3721:98f2507c5551

only print a warning when no username is specified - revert most of 8b55c0ba - display the username during interactive commit
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 28 Nov 2006 21:16:05 +0100
parents 5cc99f4b5041
children 5191e2299d63
files doc/hgrc.5.txt mercurial/localrepo.py mercurial/streamclone.py mercurial/ui.py mercurial/util.py mercurial/util_win32.py tests/test-committer tests/test-committer.out
diffstat 7 files changed, 33 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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
-    <fred@example.com>".  Default is $EMAIL. If no default is found, or the
-    configured username is empty, it has to be specified manually.
+    <fred@example.com>".  Default is $EMAIL or username@hostname.
   verbose;;
     Increase the amount of output printed.  True or False.  Default is False.
 
--- 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])
--- 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 <email@example.com>"), 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):
--- 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.
 
--- 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
--- 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/"
--- a/tests/test-committer.out
+++ b/tests/test-committer.out
@@ -4,28 +4,22 @@ user:        My Name <myname@example.com
 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 <email@example.com>"), 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 <foo@bar.com>
 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