[Python-apps-team] Bug#569554: #569554: patch

Wagner Bruna wagner.bruna+mercurial at gmail.com
Fri Feb 12 20:04:57 UTC 2010


Hello,

> When "hg ci" is run without the "-u" option it should
> take the contents of /etc/mailname (if it exists) as
> the domain name part of the user address.
> 
> EG It should use rjc at coker.com.au when I run it not
> rjc at server.coker.com.au.

Patch attached. But recent Mercurial versions will by
default fail for interactive commits if a username
isn't configured, so this change may not be that useful.

> Also it would be nice if an environment variable  could
> be used for this so I could set it in .bashrc and not
> have to worry about a -u option.

This is already supported: just set HGUSER (see "hg help
environment" for details). Alternatively you may set
your username in ~/.hgrc, like this:

[ui]
username = rjc at coker.com.au

Regards,
Wagner

# HG changeset patch
# User Wagner Bruna <wbruna at yahoo.com>
# Date 1266003625 7200
# Node ID ea28d910ae620b3358fad0967a1a93f8c5b46434
# Parent  41d0ed2c79df052bf2076c05d639ac95b58dbf10
bug#448655: try /etc/mailname for setting the username

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -186,7 +186,11 @@
              user = self.prompt(_("enter a commit username:"), default=None)
          if user is None and not self.interactive():
              try:
-                user = '%s@%s' % (util.getuser(), socket.getfqdn())
+                try:
+                    mailname = open('/etc/mailname').read().strip()
+                    user = '%s@%s' % (util.getuser(), mailname)
+                except IOError:
+                    user = '%s@%s' % (util.getuser(), socket.getfqdn())
                  self.warn(_("No username found, using '%s' instead\n") % user)
              except KeyError:
                  pass





More information about the Python-apps-team mailing list