diff --git a/mercurial/ui.py b/mercurial/ui.py index e57df017640d14c3aa7e3b15389a0b153dfddfe3_bWVyY3VyaWFsL3VpLnB5..6024216754f4122ebca3b20ae2c09461c2b5faf4_bWVyY3VyaWFsL3VpLnB5 100644 --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -197,7 +197,7 @@ user = os.environ.get("EMAIL") if user is None: try: - user = '%s@%s' % (getpass.getuser(), socket.getfqdn()) + user = '%s@%s' % (util.getuser(), socket.getfqdn()) except KeyError: raise util.Abort(_("Please specify a username.")) return user diff --git a/mercurial/util.py b/mercurial/util.py index e57df017640d14c3aa7e3b15389a0b153dfddfe3_bWVyY3VyaWFsL3V0aWwucHk=..6024216754f4122ebca3b20ae2c09461c2b5faf4_bWVyY3VyaWFsL3V0aWwucHk= 100644 --- a/mercurial/util.py +++ b/mercurial/util.py @@ -12,7 +12,7 @@ from i18n import gettext as _ from demandload import * -demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") +demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") demandload(globals(), "os threading time") # used by parsedate @@ -510,6 +510,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')) + # Platform specific variants if os.name == 'nt': demandload(globals(), "msvcrt") diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py index e57df017640d14c3aa7e3b15389a0b153dfddfe3_bWVyY3VyaWFsL3V0aWxfd2luMzIucHk=..6024216754f4122ebca3b20ae2c09461c2b5faf4_bWVyY3VyaWFsL3V0aWxfd2luMzIucHk= 100644 --- a/mercurial/util_win32.py +++ b/mercurial/util_win32.py @@ -297,3 +297,5 @@ win32file.SetEndOfFile(self.handle) except pywintypes.error, err: raise WinIOError(err) + +getuser_fallback = win32api.GetUserName