Merge lp:~bialix/bzr/2.3-bugfix-660174 into lp:bzr/2.3

Proposed by Alexander Belchenko
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 5652
Proposed branch: lp:~bialix/bzr/2.3-bugfix-660174
Merge into: lp:bzr/2.3
Diff against target: 100 lines (+40/-0)
4 files modified
bzrlib/osutils.py (+12/-0)
bzrlib/tests/features.py (+15/-0)
bzrlib/tests/test_osutils.py (+9/-0)
doc/en/release-notes/bzr-2.3.txt (+4/-0)
To merge this branch: bzr merge lp:~bialix/bzr/2.3-bugfix-660174
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+64692@code.launchpad.net

Commit message

Bug #660174, trap accidental import of pwd on Windows where it doesn't exist.

Description of the change

* Don't fail with traceback if `bzr serve` is running as a service on Windows,
  and there is no USERNAME, nor BZR_EMAIL or other whoami-related environment
  variables set. (Alexander Belchenko, Bug #660174)

To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

Should I provide a patch against trunk/2.4 or that one will be automatically merged to trunk and 2.4?

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/15/2011 4:08 PM, Alexander Belchenko wrote:
> Alexander Belchenko has proposed merging lp:~bialix/bzr/2.3-bugfix-660174 into lp:bzr/2.3.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> Bug #660174 in Bazaar: "locking a branch should not try to import pwd when running as a windows service"
> https://bugs.launchpad.net/bzr/+bug/660174
>
> For more details, see:
> https://code.launchpad.net/~bialix/bzr/2.3-bugfix-660174/+merge/64692
>
> * Don't fail with traceback if `bzr serve` is running as a service on Windows,
> and there is no USERNAME, nor BZR_EMAIL or other whoami-related environment
> variables set. (Alexander Belchenko, Bug #660174)
>

Anything in an earlier release will trickle into trunk, so you don't
have to be explicit.

> + # We should not fail with taceback in this case.
"traceback"

In the test, I would make sure all the other env vars are also removed,
so the test doesn't fail spuriously.

You should use "self.overrideEnv" rather than "set_or_unset_env". So you
don't have to restore the variable yourself.
    for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
        self.overrideEnv(name, None)

 review: needsfixing

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk34x9wACgkQJdeBCYSNAAP/5ACgqCGj3Io7XYxWl0YMu7eaqOXM
pl4An0JRNv8rOWQO2XJ0DrQb5j7XcAge
=jBCc
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
Alexander Belchenko (bialix) wrote :

John A Meinel пишет:
> In the test, I would make sure all the other env vars are also removed,
> so the test doesn't fail spuriously.
>
> You should use "self.overrideEnv" rather than "set_or_unset_env". So you
> don't have to restore the variable yourself.
> for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
> self.overrideEnv(name, None)
>
> review: needsfixing

overrideEnv() is nice, and it's much better indeed. Thanks for pointing
it out.

fixed and pushed.

Revision history for this message
John A Meinel (jameinel) :
review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/osutils.py'
2--- bzrlib/osutils.py 2011-01-12 21:06:32 +0000
3+++ bzrlib/osutils.py 2011-06-15 15:23:41 +0000
4@@ -2369,6 +2369,18 @@
5 except UnicodeDecodeError:
6 raise errors.BzrError("Can't decode username as %s." % \
7 user_encoding)
8+ except ImportError, e:
9+ if sys.platform != 'win32':
10+ raise
11+ if str(e) != 'No module named pwd':
12+ raise
13+ # https://bugs.launchpad.net/bzr/+bug/660174
14+ # getpass.getuser() is unable to return username on Windows
15+ # if there is no USERNAME environment variable set.
16+ # That could be true if bzr is running as a service,
17+ # e.g. running `bzr serve` as a service on Windows.
18+ # We should not fail with traceback in this case.
19+ username = u'UNKNOWN'
20 return username
21
22
23
24=== modified file 'bzrlib/tests/features.py'
25--- bzrlib/tests/features.py 2011-01-12 01:01:53 +0000
26+++ bzrlib/tests/features.py 2011-06-15 15:23:41 +0000
27@@ -18,6 +18,7 @@
28
29 import os
30 import stat
31+import sys
32
33 from bzrlib import tests
34
35@@ -131,3 +132,17 @@
36 bash_feature = ExecutableFeature('bash')
37 sed_feature = ExecutableFeature('sed')
38 diff_feature = ExecutableFeature('diff')
39+
40+
41+class Win32Feature(tests.Feature):
42+ """Feature testing whether we're running selftest on Windows
43+ or Windows-like platform.
44+ """
45+
46+ def _probe(self):
47+ return sys.platform == 'win32'
48+
49+ def feature_name(self):
50+ return "win32 platform"
51+
52+win32_feature = Win32Feature()
53
54=== modified file 'bzrlib/tests/test_osutils.py'
55--- bzrlib/tests/test_osutils.py 2011-05-13 11:34:44 +0000
56+++ bzrlib/tests/test_osutils.py 2011-06-15 15:23:41 +0000
57@@ -2036,6 +2036,7 @@
58 # Whatever the result is, if we don't raise an exception, it's ok.
59 osutils.terminal_width()
60
61+
62 class TestCreationOps(tests.TestCaseInTempDir):
63 _test_needs_features = [features.chown_feature]
64
65@@ -2071,6 +2072,7 @@
66 self.assertEquals(self.uid, s.st_uid)
67 self.assertEquals(self.gid, s.st_gid)
68
69+
70 class TestGetuserUnicode(tests.TestCase):
71
72 def test_ascii_user(self):
73@@ -2091,6 +2093,13 @@
74 self.overrideEnv('LOGNAME', u'jrandom\xb6'.encode(ue))
75 self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
76
77+ def test_no_username_bug_660174(self):
78+ self.requireFeature(features.win32_feature)
79+ for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
80+ self.overrideEnv(name, None)
81+ self.assertEqual(u'UNKNOWN', osutils.getuser_unicode())
82+
83+
84 class TestBackupNames(tests.TestCase):
85
86 def setUp(self):
87
88=== modified file 'doc/en/release-notes/bzr-2.3.txt'
89--- doc/en/release-notes/bzr-2.3.txt 2011-06-09 12:17:09 +0000
90+++ doc/en/release-notes/bzr-2.3.txt 2011-06-15 15:23:41 +0000
91@@ -33,6 +33,10 @@
92 .. Fixes for situations where bzr would previously crash or give incorrect
93 or undesirable results.
94
95+* Don't fail with traceback if `bzr serve` is running as a service on Windows,
96+ and there is no USERNAME, nor BZR_EMAIL or other whoami-related environment
97+ variables set. (Alexander Belchenko, Bug #660174)
98+
99 Documentation
100 *************
101

Subscribers

People subscribed via source and target branches