Merge lp:~bialix/bzr/2.4-bug-967060 into lp:bzr/2.4

Proposed by Alexander Belchenko
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6069
Proposed branch: lp:~bialix/bzr/2.4-bug-967060
Merge into: lp:bzr/2.4
Diff against target: 88 lines (+37/-7)
3 files modified
bzrlib/_walkdirs_win32.pyx (+14/-7)
bzrlib/tests/test__walkdirs_win32.py (+19/-0)
doc/en/release-notes/bzr-2.4.txt (+4/-0)
To merge this branch: bzr merge lp:~bialix/bzr/2.4-bug-967060
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Jelmer Vernooij (community) Approve
John A Meinel Approve
Review via email: mp+99737@code.launchpad.net

Commit message

Provide st_uid and st_gid on _Win32Stat so it looks more like a normal stat object

Description of the change

_Win32Stat object provides members st_uid and st_gid, those are present in Python's os.stat object. These members required for external tools like bzr-git and dulwich. (Bug #967060).

I've based the fix on 2.4 branch to make sure we can merge it easily from 2.4 up to trunk (2.6). Actually we need this fix in bzr 2.5. I don't think there are plans to provide new windows installers for next bzr 2.4 releases.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

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

On 3/28/2012 4:11 PM, Alexander Belchenko wrote:
> Alexander Belchenko has proposed merging
> lp:~bialix/bzr/2.4-bug-967060 into lp:bzr/2.4.
>
> Requested reviews: bzr-core (bzr-core) Related bugs: Bug #967060 in
> Bazaar: "[win32] `bzr add file` in git tree fails with traceback:
> _Win32Stat misses st_uid/st_gid members"
> https://bugs.launchpad.net/bzr/+bug/967060
>
> For more details, see:
> https://code.launchpad.net/~bialix/bzr/2.4-bug-967060/+merge/99737
>
> _Win32Stat object provides members st_uid and st_gid, those are
> present in Python's os.stat object. These members required for
> external tools like bzr-git and dulwich. (Bug #967060).
>
> I've based the fix on 2.4 branch to make sure we can merge it
> easily from 2.4 up to trunk (2.6). Actually we need this fix in bzr
> 2.5. I don't think there are plans to provide new windows
> installers for next bzr 2.4 releases.
>

I can confirm that 'os.stat()' on Python returns 0 for uid and gid on
regular files. So it seems great to me.

John
=:->

 review: approve

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

iEYEARECAAYFAk9zHg0ACgkQJdeBCYSNAAMw4QCfdRgnIS+ME0cCaHnA1z0h8GtU
v7QAnjY23NRh4MzObef1qfbeo4DNclF6
=txr6
-----END PGP SIGNATURE-----

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

How about using properties returning 0 instead? This isn't a class designed for minimising memory usage, but as these values serve no purpose there seems no point storing them.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> How about using properties returning 0 instead? This isn't a class designed
> for minimising memory usage, but as these values serve no purpose there seems
> no point storing them.
That seems slightly better to me too, but either change seems reasonable.

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

Martin Packman пишет:
> How about using properties returning 0 instead? This isn't a class designed for minimising memory usage, but as these values serve no purpose there seems no point storing them.

I followed the approach John used for st_dev and st_ino. I can do it
either way. But then should I change st_dev and st_ino implementations
as well?

--
All the dude wanted was his rug back

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

Martin Packman пишет:
> How about using properties returning 0 instead? This isn't a class designed for minimising memory usage, but as these values serve no purpose there seems no point storing them.

Well, thinking about it more I'd like to avoid properties because they
mean more code for no real benefit. To avoid duplication in explicit
initialization of those 4 members to zero, I'd prefer move them into
constructor (__init__ method). There is no constructor today, but we can
add it.

--
All the dude wanted was his rug back

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> Martin Packman пишет:
> > How about using properties returning 0 instead? This isn't a class designed
> for minimising memory usage, but as these values serve no purpose there seems
> no point storing them.
>
> Well, thinking about it more I'd like to avoid properties because they
> mean more code for no real benefit. To avoid duplication in explicit
> initialization of those 4 members to zero, I'd prefer move them into
> constructor (__init__ method). There is no constructor today, but we can
> add it.
Presumably the benefit in using a property would mean 4 fields less to store in memory per instance, and less time to spend assigning those member variables per stat object. I'm not sure how big the gains of that are in practice though.

I don't think that sort of change should be a requirement for this fix to land. But if you feel like fixing that, it would be great. :)

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

Jelmer Vernooij пишет:
>> Martin Packman пишет:
>>> How about using properties returning 0 instead? This isn't a class designed
>> for minimising memory usage, but as these values serve no purpose there seems
>> no point storing them.
>>
>> Well, thinking about it more I'd like to avoid properties because they
>> mean more code for no real benefit. To avoid duplication in explicit
>> initialization of those 4 members to zero, I'd prefer move them into
>> constructor (__init__ method). There is no constructor today, but we can
>> add it.
> Presumably the benefit in using a property would mean 4 fields less to store in memory per instance, and less time to spend assigning those member variables per stat object. I'm not sure how big the gains of that are in practice though.
>
> I don't think that sort of change should be a requirement for this fix to land. But if you feel like fixing that, it would be great. :)

I'm not sure what is best here. I'd like to hear opinion of John Meinel.

--
All the dude wanted was his rug back

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

I'm pretty sure writing "cdef public int st_dev" does create some sort of
accessor function for the attribute, since it has to turn the int into a
PyInt. So it is pretty much the same to write:

property st_dev:
  def __get__: return 0

So i would slight prefer the property approach. I don't think either is
going to be a measurable impact, though.
John
=:->
On Mar 28, 2012 6:19 PM, "Alexander Belchenko" <email address hidden> wrote:

> Jelmer Vernooij пишет:
> >> Martin Packman пишет:
> >>> How about using properties returning 0 instead? This isn't a class
> designed
> >> for minimising memory usage, but as these values serve no purpose there
> seems
> >> no point storing them.
> >>
> >> Well, thinking about it more I'd like to avoid properties because they
> >> mean more code for no real benefit. To avoid duplication in explicit
> >> initialization of those 4 members to zero, I'd prefer move them into
> >> constructor (__init__ method). There is no constructor today, but we can
> >> add it.
> > Presumably the benefit in using a property would mean 4 fields less to
> store in memory per instance, and less time to spend assigning those member
> variables per stat object. I'm not sure how big the gains of that are in
> practice though.
> >
> > I don't think that sort of change should be a requirement for this fix
> to land. But if you feel like fixing that, it would be great. :)
>
> I'm not sure what is best here. I'd like to hear opinion of John Meinel.
>
> --
> All the dude wanted was his rug back
>
> https://code.launchpad.net/~bialix/bzr/2.4-bug-967060/+merge/99737
> You are reviewing the proposed merge of lp:~bialix/bzr/2.4-bug-967060 into
> lp:bzr/2.4.
>

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

John A Meinel пишет:
> I'm pretty sure writing "cdef public int st_dev" does create some sort of
> accessor function for the attribute, since it has to turn the int into a
> PyInt. So it is pretty much the same to write:
>
> property st_dev:
> def __get__: return 0

Well, actually access to int variable performed by internal Python
function, so Pyrex does not generate any special explicit accessor
function, but only creates an entry in tp_members structure. But for
property Pyrex does generate special (although trivial) code to convert
C zero to proper Python object.

> So i would slight prefer the property approach. I don't think either is
> going to be a measurable impact, though.

OK, I'll change the code to use properties. That way we can avoid
duplication in setting those variables to zero and save 16 bytes for
each stat object instance.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Thanks fixing that Alexander !

I'll put this proposal into a wip one, pign here or on IRC when you feel it can be landed or if you want a final review.

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

Ping-pong.

I've changed the code to use properties, and added small test to check that all properties are present and return expected value. Please, take a look. I think it's ready to land.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Looks good to me, thanks.

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

test__walkdirs_win32.Test_Win32Stat.test_zero_members_present OK 0ms

review: Approve
Revision history for this message
Martin Packman (gz) 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/_walkdirs_win32.pyx'
2--- bzrlib/_walkdirs_win32.pyx 2011-04-05 12:15:34 +0000
3+++ bzrlib/_walkdirs_win32.pyx 2012-03-29 08:38:20 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (C) 2008-2011 Canonical Ltd
6+# Copyright (C) 2008-2012 Canonical Ltd
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10@@ -95,8 +95,19 @@
11 return self._st_size
12
13 # os.stat always returns 0, so we hard code it here
14- cdef readonly int st_dev
15- cdef readonly int st_ino
16+ property st_dev:
17+ def __get__(self):
18+ return 0
19+ property st_ino:
20+ def __get__(self):
21+ return 0
22+ # st_uid and st_gid required for some external tools like bzr-git & dulwich
23+ property st_uid:
24+ def __get__(self):
25+ return 0
26+ property st_gid:
27+ def __get__(self):
28+ return 0
29
30 def __repr__(self):
31 """Repr is the same as a Stat object.
32@@ -195,8 +206,6 @@
33 statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
34 statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
35 statvalue._st_size = _get_size(data)
36- statvalue.st_ino = 0
37- statvalue.st_dev = 0
38 return statvalue
39
40 def read_dir(self, prefix, top):
41@@ -288,6 +297,4 @@
42 statvalue.st_mtime = st.st_mtime
43 statvalue.st_atime = st.st_atime
44 statvalue._st_size = st.st_size
45- statvalue.st_ino = 0
46- statvalue.st_dev = 0
47 return statvalue
48
49=== modified file 'bzrlib/tests/test__walkdirs_win32.py'
50--- bzrlib/tests/test__walkdirs_win32.py 2010-05-16 12:21:31 +0000
51+++ bzrlib/tests/test__walkdirs_win32.py 2012-03-29 08:38:20 +0000
52@@ -93,3 +93,22 @@
53 self.assertEqual(errno.ENOENT, e.errno)
54 self.assertEqual(3, e.winerror)
55 self.assertEqual((3, u'no_such_dir/*'), e.args)
56+
57+
58+class Test_Win32Stat(tests.TestCaseInTempDir):
59+
60+ _test_needs_features = [win32_readdir_feature]
61+
62+ def setUp(self):
63+ super(Test_Win32Stat, self).setUp()
64+ from bzrlib._walkdirs_win32 import lstat
65+ self.win32_lstat = lstat
66+
67+ def test_zero_members_present(self):
68+ self.build_tree(['foo'])
69+ st = self.win32_lstat('foo')
70+ # we only want to ensure that some members are present
71+ self.assertEqual(0, st.st_dev)
72+ self.assertEqual(0, st.st_ino)
73+ self.assertEqual(0, st.st_uid)
74+ self.assertEqual(0, st.st_gid)
75
76=== modified file 'doc/en/release-notes/bzr-2.4.txt'
77--- doc/en/release-notes/bzr-2.4.txt 2012-02-26 19:56:15 +0000
78+++ doc/en/release-notes/bzr-2.4.txt 2012-03-29 08:38:20 +0000
79@@ -55,6 +55,10 @@
80 * Prevent a traceback being printed to stderr when logging has problems and
81 accept utf-8 byte string without breaking. (Martin Packman, #714449)
82
83+* _Win32Stat object provides members st_uid and st_gid, those are present
84+ in Python's os.stat object. These members required for external tools like
85+ bzr-git and dulwich. (Alexander Belchenko, #967060)
86+
87 Documentation
88 *************
89

Subscribers

People subscribed via source and target branches