Merge lp:~abentley/bzr/commit-preview into lp:~bzr/bzr/trunk-old

Proposed by Aaron Bentley
Status: Merged
Approved by: Ian Clatworthy
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~abentley/bzr/commit-preview
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 139 lines
To merge this branch: bzr merge lp:~abentley/bzr/commit-preview
Reviewer Review Type Date Requested Status
Ian Clatworthy Approve
Review via email: mp+6727@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

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

Hi all,

This patch is a followup on my changes to allow PreviewTree to be
committed. It turns out that get_file_with_stat should be declared on
the Tree interface. This patch moves the code from MutableTree to Tree,
and updates the tests accordingly.

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

iEYEARECAAYFAkoVRrkACgkQ0F+nu1YWqI3NswCePVKEnKq6danx6Nf8JSizvuZL
MJgAn2FBFMkyS2MHICAMaIvq8Hfn+wtu
=nQw3
-----END PGP SIGNATURE-----

Revision history for this message
Ian Clatworthy (ian-clatworthy) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/mutabletree.py'
--- bzrlib/mutabletree.py 2009-04-09 20:23:07 +0000
+++ bzrlib/mutabletree.py 2009-05-28 12:36:32 +0000
@@ -232,20 +232,6 @@
232 """Helper function for add - sets the entries of kinds."""232 """Helper function for add - sets the entries of kinds."""
233 raise NotImplementedError(self._gather_kinds)233 raise NotImplementedError(self._gather_kinds)
234234
235 def get_file_with_stat(self, file_id, path=None):
236 """Get a file handle and stat object for file_id.
237
238 The default implementation returns (self.get_file, None) for backwards
239 compatibility.
240
241 :param file_id: The file id to read.
242 :param path: The path of the file, if it is known.
243 :return: A tuple (file_handle, stat_value_or_None). If the tree has
244 no stat facility, or need for a stat cache feedback during commit,
245 it may return None for the second element of the tuple.
246 """
247 return (self.get_file(file_id, path), None)
248
249 @needs_read_lock235 @needs_read_lock
250 def last_revision(self):236 def last_revision(self):
251 """Return the revision id of the last commit performed in this tree.237 """Return the revision id of the last commit performed in this tree.
252238
=== modified file 'bzrlib/tests/tree_implementations/__init__.py'
--- bzrlib/tests/tree_implementations/__init__.py 2009-04-11 16:06:53 +0000
+++ bzrlib/tests/tree_implementations/__init__.py 2009-05-28 12:36:33 +0000
@@ -365,6 +365,7 @@
365 submod_tests = loader.loadTestsFromModuleNames([365 submod_tests = loader.loadTestsFromModuleNames([
366 'bzrlib.tests.tree_implementations.test_annotate_iter',366 'bzrlib.tests.tree_implementations.test_annotate_iter',
367 'bzrlib.tests.tree_implementations.test_get_file_mtime',367 'bzrlib.tests.tree_implementations.test_get_file_mtime',
368 'bzrlib.tests.tree_implementations.test_get_file_with_stat',
368 'bzrlib.tests.tree_implementations.test_get_root_id',369 'bzrlib.tests.tree_implementations.test_get_root_id',
369 'bzrlib.tests.tree_implementations.test_get_symlink_target',370 'bzrlib.tests.tree_implementations.test_get_symlink_target',
370 'bzrlib.tests.tree_implementations.test_inv',371 'bzrlib.tests.tree_implementations.test_inv',
371372
=== renamed file 'bzrlib/tests/workingtree_implementations/test_get_file_with_stat.py' => 'bzrlib/tests/tree_implementations/test_get_file_with_stat.py'
--- bzrlib/tests/workingtree_implementations/test_get_file_with_stat.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/tree_implementations/test_get_file_with_stat.py 2009-05-28 12:36:33 +0000
@@ -18,15 +18,16 @@
1818
19import os19import os
2020
21from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree21from bzrlib.tests.tree_implementations import TestCaseWithTree
2222
2323
24class TestGetFileWithStat(TestCaseWithWorkingTree):24class TestGetFileWithStat(TestCaseWithTree):
2525
26 def test_get_file_with_stat_id_only(self):26 def test_get_file_with_stat_id_only(self):
27 tree = self.make_branch_and_tree('.')27 work_tree = self.make_branch_and_tree('.')
28 self.build_tree(['foo'])28 self.build_tree(['foo'])
29 tree.add(['foo'], ['foo-id'])29 work_tree.add(['foo'], ['foo-id'])
30 tree = self._convert_tree(work_tree)
30 tree.lock_read()31 tree.lock_read()
31 self.addCleanup(tree.unlock)32 self.addCleanup(tree.unlock)
32 file_obj, statvalue = tree.get_file_with_stat('foo-id')33 file_obj, statvalue = tree.get_file_with_stat('foo-id')
@@ -36,9 +37,10 @@
36 self.assertEqual(["contents of foo\n"], file_obj.readlines())37 self.assertEqual(["contents of foo\n"], file_obj.readlines())
3738
38 def test_get_file_with_stat_id_and_path(self):39 def test_get_file_with_stat_id_and_path(self):
39 tree = self.make_branch_and_tree('.')40 work_tree = self.make_branch_and_tree('.')
40 self.build_tree(['foo'])41 self.build_tree(['foo'])
41 tree.add(['foo'], ['foo-id'])42 work_tree.add(['foo'], ['foo-id'])
43 tree = self._convert_tree(work_tree)
42 tree.lock_read()44 tree.lock_read()
43 self.addCleanup(tree.unlock)45 self.addCleanup(tree.unlock)
44 file_obj, statvalue = tree.get_file_with_stat('foo-id', 'foo')46 file_obj, statvalue = tree.get_file_with_stat('foo-id', 'foo')
4547
=== modified file 'bzrlib/tests/workingtree_implementations/__init__.py'
--- bzrlib/tests/workingtree_implementations/__init__.py 2009-04-11 16:06:53 +0000
+++ bzrlib/tests/workingtree_implementations/__init__.py 2009-05-28 12:36:33 +0000
@@ -72,7 +72,6 @@
72 'bzrlib.tests.workingtree_implementations.test_eol_conversion',72 'bzrlib.tests.workingtree_implementations.test_eol_conversion',
73 'bzrlib.tests.workingtree_implementations.test_executable',73 'bzrlib.tests.workingtree_implementations.test_executable',
74 'bzrlib.tests.workingtree_implementations.test_flush',74 'bzrlib.tests.workingtree_implementations.test_flush',
75 'bzrlib.tests.workingtree_implementations.test_get_file_with_stat',
76 'bzrlib.tests.workingtree_implementations.test_get_file_mtime',75 'bzrlib.tests.workingtree_implementations.test_get_file_mtime',
77 'bzrlib.tests.workingtree_implementations.test_get_parent_ids',76 'bzrlib.tests.workingtree_implementations.test_get_parent_ids',
78 'bzrlib.tests.workingtree_implementations.test_inv',77 'bzrlib.tests.workingtree_implementations.test_inv',
7978
=== modified file 'bzrlib/transform.py'
--- bzrlib/transform.py 2009-05-28 07:46:53 +0000
+++ bzrlib/transform.py 2009-05-28 12:36:32 +0000
@@ -1915,7 +1915,7 @@
1915 name = self._transform._limbo_name(trans_id)1915 name = self._transform._limbo_name(trans_id)
1916 return open(name, 'rb')1916 return open(name, 'rb')
19171917
1918 def get_file_with_stat(self, file_id, path):1918 def get_file_with_stat(self, file_id, path=None):
1919 return self.get_file(file_id, path), None1919 return self.get_file(file_id, path), None
19201920
1921 def annotate_iter(self, file_id,1921 def annotate_iter(self, file_id,
19221922
=== modified file 'bzrlib/tree.py'
--- bzrlib/tree.py 2009-05-23 04:55:52 +0000
+++ bzrlib/tree.py 2009-05-28 12:36:32 +0000
@@ -263,6 +263,20 @@
263 """263 """
264 raise NotImplementedError(self.get_file)264 raise NotImplementedError(self.get_file)
265265
266 def get_file_with_stat(self, file_id, path=None):
267 """Get a file handle and stat object for file_id.
268
269 The default implementation returns (self.get_file, None) for backwards
270 compatibility.
271
272 :param file_id: The file id to read.
273 :param path: The path of the file, if it is known.
274 :return: A tuple (file_handle, stat_value_or_None). If the tree has
275 no stat facility, or need for a stat cache feedback during commit,
276 it may return None for the second element of the tuple.
277 """
278 return (self.get_file(file_id, path), None)
279
266 def get_file_text(self, file_id, path=None):280 def get_file_text(self, file_id, path=None):
267 """Return the byte content of a file.281 """Return the byte content of a file.
268282
269283
=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py 2009-05-13 17:16:28 +0000
+++ bzrlib/workingtree.py 2009-05-28 12:36:33 +0000
@@ -446,7 +446,7 @@
446446
447 def get_file_with_stat(self, file_id, path=None, filtered=True,447 def get_file_with_stat(self, file_id, path=None, filtered=True,
448 _fstat=os.fstat):448 _fstat=os.fstat):
449 """See MutableTree.get_file_with_stat."""449 """See Tree.get_file_with_stat."""
450 if path is None:450 if path is None:
451 path = self.id2path(file_id)451 path = self.id2path(file_id)
452 file_obj = self.get_file_byname(path, filtered=False)452 file_obj = self.get_file_byname(path, filtered=False)