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