Merge lp:~mbp/bzr/integration-old into lp:~bzr/bzr/trunk-old

Proposed by Martin Pool
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~mbp/bzr/integration-old
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 257 lines
To merge this branch: bzr merge lp:~mbp/bzr/integration-old
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+9558@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

In the distant past we did a lot of file IO indirectly through LockableFiles. We now use the transport directly. This deletes some deprecated methods that forwarded to the transport, and their tests.

CountedLock.get_physical_lock status merely forwards so doesn't urgently need a test.

In passing I noticed this strange behaviour that get_branch_transport may or may not actually create a directory depending on whether you specify the format, thus the comment.

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

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

Martin Pool wrote:
> Martin Pool has proposed merging lp:~mbp/bzr/integration into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> In the distant past we did a lot of file IO indirectly through LockableFiles. We now use the transport directly. This deletes some deprecated methods that forwarded to the transport, and their tests.
>
> CountedLock.get_physical_lock status merely forwards so doesn't urgently need a test.
>
> In passing I noticed this strange behaviour that get_branch_transport may or may not actually create a directory depending on whether you specify the format, thus the comment.
>

 review: approve
 merge: approve

Though I'm a bit surprised you consider it difficult to test the
get_physical_lock_status.

Also, what is calling this function? As I see you added something new,
but did not add any new callers.

John
=:->

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

iEYEARECAAYFAkp26FEACgkQJdeBCYSNAANdtACeJt0Tkv0erqSnI6fQaA8G5IO6
l2cAoNM6YvsPiiejgSeS+U3nnef+SGEH
=88nM
-----END PGP SIGNATURE-----

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

2009/8/3 John A Meinel <email address hidden>:
> Though I'm a bit surprised you consider it difficult to test the
> get_physical_lock_status.

Not hard, I was just a bit lazy, and I kind of felt this should go
into some kind of parameterized test.

> Also, what is calling this function? As I see you added something new,
> but did not add any new callers.

Nothing yet; I'm working towards cleaning out the different aspects of
LockableFiles and this is one of them.

--
Martin <http://launchpad.net/~mbp/>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/bzrdir.py'
2--- bzrlib/bzrdir.py 2009-08-03 04:11:06 +0000
3+++ bzrlib/bzrdir.py 2009-08-04 14:35:47 +0000
4@@ -1634,6 +1634,8 @@
5
6 def get_branch_transport(self, branch_format):
7 """See BzrDir.get_branch_transport()."""
8+ # XXX: this shouldn't implicitly create the directory if it's just
9+ # promising to get a transport -- mbp 20090727
10 if branch_format is None:
11 return self.transport.clone('branch')
12 try:
13
14=== modified file 'bzrlib/counted_lock.py'
15--- bzrlib/counted_lock.py 2009-03-25 04:20:12 +0000
16+++ bzrlib/counted_lock.py 2009-08-04 14:35:47 +0000
17@@ -46,6 +46,18 @@
18 self._lock_mode = None
19 self._lock_count = 0
20
21+ def get_physical_lock_status(self):
22+ """Return physical lock status.
23+
24+ Returns true if a lock is held on the transport. If no lock is held, or
25+ the underlying locking mechanism does not support querying lock
26+ status, false is returned.
27+ """
28+ try:
29+ return self._real_lock.peek() is not None
30+ except NotImplementedError:
31+ return False
32+
33 def is_locked(self):
34 return self._lock_mode is not None
35
36
37=== modified file 'bzrlib/lockable_files.py'
38--- bzrlib/lockable_files.py 2009-07-10 07:47:21 +0000
39+++ bzrlib/lockable_files.py 2009-08-04 14:35:47 +0000
40@@ -65,11 +65,7 @@
41 class LockableFiles(object):
42 """Object representing a set of related files locked within the same scope.
43
44- These files are used by a WorkingTree, Repository or Branch, and should
45- generally only be touched by that object.
46-
47- LockableFiles also provides some policy on top of Transport for encoding
48- control files as utf-8.
49+ This coordinates access to the lock along with providing a transaction.
50
51 LockableFiles manage a lock count and can be locked repeatedly by
52 a single caller. (The underlying lock implementation generally does not
53@@ -77,13 +73,6 @@
54
55 Instances of this class are often called control_files.
56
57- This object builds on top of a Transport, which is used to actually write
58- the files to disk, and an OSLock or LockDir, which controls how access to
59- the files is controlled. The particular type of locking used is set when
60- the object is constructed. In older formats OSLocks are used everywhere.
61- in newer formats a LockDir is used for Repositories and Branches, and
62- OSLocks for the local filesystem.
63-
64 This class is now deprecated; code should move to using the Transport
65 directly for file operations and using the lock or CountedLock for
66 locking.
67@@ -151,7 +140,7 @@
68 def _find_modes(self):
69 """Determine the appropriate modes for files and directories.
70
71- :deprecated: Replaced by BzrDir._find_modes.
72+ :deprecated: Replaced by BzrDir._find_creation_modes.
73 """
74 # XXX: The properties created by this can be removed or deprecated
75 # once all the _get_text_store methods etc no longer use them.
76@@ -170,81 +159,6 @@
77 # Remove the sticky and execute bits for files
78 self._file_mode = self._dir_mode & ~07111
79
80- @deprecated_method(deprecated_in((1, 6, 0)))
81- def controlfilename(self, file_or_path):
82- """Return location relative to branch.
83-
84- :deprecated: Use Transport methods instead.
85- """
86- return self._transport.abspath(self._escape(file_or_path))
87-
88- @needs_read_lock
89- @deprecated_method(deprecated_in((1, 5, 0)))
90- def get(self, relpath):
91- """Get a file as a bytestream.
92-
93- :deprecated: Use a Transport instead of LockableFiles.
94- """
95- relpath = self._escape(relpath)
96- return self._transport.get(relpath)
97-
98- @needs_read_lock
99- @deprecated_method(deprecated_in((1, 5, 0)))
100- def get_utf8(self, relpath):
101- """Get a file as a unicode stream.
102-
103- :deprecated: Use a Transport instead of LockableFiles.
104- """
105- relpath = self._escape(relpath)
106- # DO NOT introduce an errors=replace here.
107- return codecs.getreader('utf-8')(self._transport.get(relpath))
108-
109- @needs_write_lock
110- @deprecated_method(deprecated_in((1, 6, 0)))
111- def put(self, path, file):
112- """Write a file.
113-
114- :param path: The path to put the file, relative to the .bzr control
115- directory
116- :param file: A file-like or string object whose contents should be copied.
117-
118- :deprecated: Use Transport methods instead.
119- """
120- self._transport.put_file(self._escape(path), file, mode=self._file_mode)
121-
122- @needs_write_lock
123- @deprecated_method(deprecated_in((1, 6, 0)))
124- def put_bytes(self, path, a_string):
125- """Write a string of bytes.
126-
127- :param path: The path to put the bytes, relative to the transport root.
128- :param a_string: A string object, whose exact bytes are to be copied.
129-
130- :deprecated: Use Transport methods instead.
131- """
132- self._transport.put_bytes(self._escape(path), a_string,
133- mode=self._file_mode)
134-
135- @needs_write_lock
136- @deprecated_method(deprecated_in((1, 6, 0)))
137- def put_utf8(self, path, a_string):
138- """Write a string, encoding as utf-8.
139-
140- :param path: The path to put the string, relative to the transport root.
141- :param string: A string or unicode object whose contents should be copied.
142-
143- :deprecated: Use Transport methods instead.
144- """
145- # IterableFile would not be needed if Transport.put took iterables
146- # instead of files. ADHB 2005-12-25
147- # RBC 20060103 surely its not needed anyway, with codecs transcode
148- # file support ?
149- # JAM 20060103 We definitely don't want encode(..., 'replace')
150- # these are valuable files which should have exact contents.
151- if not isinstance(a_string, basestring):
152- raise errors.BzrBadParameterNotString(a_string)
153- self.put_bytes(path, a_string.encode('utf-8'))
154-
155 def leave_in_place(self):
156 """Set this LockableFiles to not clear the physical lock on unlock."""
157 self._lock.leave_in_place()
158
159=== modified file 'bzrlib/tests/test_counted_lock.py'
160--- bzrlib/tests/test_counted_lock.py 2009-03-25 04:20:12 +0000
161+++ bzrlib/tests/test_counted_lock.py 2009-08-04 14:35:47 +0000
162@@ -215,3 +215,5 @@
163 l.break_lock()
164 self.assertFalse(l.is_locked())
165 self.assertFalse(real_lock.is_locked())
166+
167+ # TODO: test get_physical_lock_status
168
169=== modified file 'bzrlib/tests/test_lockable_files.py'
170--- bzrlib/tests/test_lockable_files.py 2009-06-23 08:43:05 +0000
171+++ bzrlib/tests/test_lockable_files.py 2009-08-04 14:35:47 +0000
172@@ -1,4 +1,4 @@
173-# Copyright (C) 2005, 2006, 2008 Canonical Ltd
174+# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
175 #
176 # This program is free software; you can redistribute it and/or modify
177 # it under the terms of the GNU General Public License as published by
178@@ -46,79 +46,6 @@
179 # so won't modernize them now. - mbp 20080430
180 class _TestLockableFiles_mixin(object):
181
182- def test_read_write(self):
183- self.assertRaises(NoSuchFile,
184- self.applyDeprecated,
185- deprecated_in((1, 5, 0)),
186- self.lockable.get, 'foo')
187- self.assertRaises(NoSuchFile,
188- self.applyDeprecated,
189- deprecated_in((1, 5, 0)),
190- self.lockable.get_utf8, 'foo')
191- self.lockable.lock_write()
192- self.addCleanup(self.lockable.unlock)
193- unicode_string = u'bar\u1234'
194- self.assertEqual(4, len(unicode_string))
195- byte_string = unicode_string.encode('utf-8')
196- self.assertEqual(6, len(byte_string))
197- self.assertRaises(UnicodeEncodeError,
198- self.applyDeprecated,
199- deprecated_in((1, 6, 0)),
200- self.lockable.put, 'foo',
201- StringIO(unicode_string))
202- self.applyDeprecated(
203- deprecated_in((1, 6, 0)),
204- self.lockable.put,
205- 'foo', StringIO(byte_string))
206- byte_stream = self.applyDeprecated(
207- deprecated_in((1, 5, 0)),
208- self.lockable.get,
209- 'foo')
210- self.assertEqual(byte_string, byte_stream.read())
211- unicode_stream = self.applyDeprecated(
212- deprecated_in((1, 5, 0)),
213- self.lockable.get_utf8,
214- 'foo')
215- self.assertEqual(unicode_string,
216- unicode_stream.read())
217- self.assertRaises(BzrBadParameterNotString,
218- self.applyDeprecated,
219- deprecated_in((1, 6, 0)),
220- self.lockable.put_utf8,
221- 'bar',
222- StringIO(unicode_string))
223- self.applyDeprecated(
224- deprecated_in((1, 6, 0)),
225- self.lockable.put_utf8,
226- 'bar',
227- unicode_string)
228- unicode_stream = self.applyDeprecated(
229- deprecated_in((1, 5, 0)),
230- self.lockable.get_utf8,
231- 'bar')
232- self.assertEqual(unicode_string,
233- unicode_stream.read())
234- byte_stream = self.applyDeprecated(
235- deprecated_in((1, 5, 0)),
236- self.lockable.get,
237- 'bar')
238- self.assertEqual(byte_string, byte_stream.read())
239- self.applyDeprecated(
240- deprecated_in((1, 6, 0)),
241- self.lockable.put_bytes,
242- 'raw', 'raw\xffbytes')
243- byte_stream = self.applyDeprecated(
244- deprecated_in((1, 5, 0)),
245- self.lockable.get,
246- 'raw')
247- self.assertEqual('raw\xffbytes', byte_stream.read())
248-
249- def test_locks(self):
250- self.lockable.lock_read()
251- self.addCleanup(self.lockable.unlock)
252- self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
253- StringIO('bar\u1234'))
254-
255 def test_transactions(self):
256 self.assertIs(self.lockable.get_transaction().__class__,
257 PassThroughTransaction)