/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree_4.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
"""Tests for WorkingTreeFormat4"""
19
19
 
64
64
            - when the WorkingTree is locked, LockDir can see that
65
65
        """
66
66
        # this test could be factored into a subclass of tests common to both
67
 
        # format 3 and 4, but for now its not much of an issue as there is only one in common.
 
67
        # format 3 and 4, but for now its not much of an issue as there is only
 
68
        # one in common.
68
69
        t = self.get_transport()
69
70
        tree = self.make_workingtree()
70
71
        self.assertIsDirectory('.bzr', t)
92
93
    def test_dirstate_stores_all_parent_inventories(self):
93
94
        tree = self.make_workingtree()
94
95
 
95
 
        # We're going to build in tree a working tree 
96
 
        # with three parent trees, with some files in common.  
97
 
    
 
96
        # We're going to build in tree a working tree
 
97
        # with three parent trees, with some files in common.
 
98
 
98
99
        # We really don't want to do commit or merge in the new dirstate-based
99
100
        # tree, because that might not work yet.  So instead we build
100
101
        # revisions elsewhere and pull them across, doing by hand part of the
130
131
        rev2_revtree = repo.revision_tree(rev2)
131
132
        rev3_revtree = repo.revision_tree(rev3)
132
133
        # tree doesn't contain a text merge yet but we'll just
133
 
        # set the parents as if a merge had taken place. 
134
 
        # this should cause the tree data to be folded into the 
 
134
        # set the parents as if a merge had taken place.
 
135
        # this should cause the tree data to be folded into the
135
136
        # dirstate.
136
137
        tree.set_parent_trees([
137
138
            (rev1, rev1_revtree),
156
157
 
157
158
    def test_dirstate_doesnt_read_parents_from_repo_when_setting(self):
158
159
        """Setting parent trees on a dirstate working tree takes
159
 
        the trees it's given and doesn't need to read them from the 
 
160
        the trees it's given and doesn't need to read them from the
160
161
        repository.
161
162
        """
162
163
        tree = self.make_workingtree()
170
171
        tree.branch.pull(subtree.branch)
171
172
 
172
173
        # break the repository's legs to make sure it only uses the trees
173
 
        # it's given; any calls to forbidden methods will raise an 
 
174
        # it's given; any calls to forbidden methods will raise an
174
175
        # AssertionError
175
176
        repo = tree.branch.repository
176
177
        repo.get_revision = self.fail
180
181
        tree.set_parent_trees([(rev1, rev1_tree)])
181
182
 
182
183
    def test_dirstate_doesnt_read_from_repo_when_returning_cache_tree(self):
183
 
        """Getting parent trees from a dirstate tree does not read from the 
 
184
        """Getting parent trees from a dirstate tree does not read from the
184
185
        repos inventory store. This is an important part of the dirstate
185
186
        performance optimisation work.
186
187
        """
206
207
        tree.branch.pull(subtree.branch)
207
208
 
208
209
        # break the repository's legs to make sure it only uses the trees
209
 
        # it's given; any calls to forbidden methods will raise an 
 
210
        # it's given; any calls to forbidden methods will raise an
210
211
        # AssertionError
211
212
        repo = tree.branch.repository
212
 
        # dont uncomment this: the revision object must be accessed to 
213
 
        # answer 'get_parent_ids' for the revision tree- dirstate does not 
 
213
        # dont uncomment this: the revision object must be accessed to
 
214
        # answer 'get_parent_ids' for the revision tree- dirstate does not
214
215
        # cache the parents of a parent tree at this point.
215
216
        #repo.get_revision = self.fail
216
217
        repo.get_inventory = self.fail
221
222
        result_rev1_tree = tree.revision_tree(rev1)
222
223
        # read the second
223
224
        result_rev2_tree = tree.revision_tree(rev2)
224
 
        # compare - there should be no differences between the handed and 
 
225
        # compare - there should be no differences between the handed and
225
226
        # returned trees
226
227
        self.assertTreesEqual(rev1_tree, result_rev1_tree)
227
228
        self.assertTreesEqual(rev2_tree, result_rev2_tree)
228
229
 
229
230
    def test_dirstate_doesnt_cache_non_parent_trees(self):
230
 
        """Getting parent trees from a dirstate tree does not read from the 
 
231
        """Getting parent trees from a dirstate tree does not read from the
231
232
        repos inventory store. This is an important part of the dirstate
232
233
        performance optimisation work.
233
234
        """
282
283
        rev_id = tree.commit('first post')
283
284
        rev_id2 = tree.commit('second post')
284
285
        rev_tree = tree.branch.repository.revision_tree(rev_id)
285
 
        # Exception is not a great thing to raise, but this test is 
286
 
        # very short, and code is used to sanity check other tests, so 
 
286
        # Exception is not a great thing to raise, but this test is
 
287
        # very short, and code is used to sanity check other tests, so
287
288
        # a full error object is YAGNI.
288
289
        self.assertRaises(
289
290
            Exception, workingtree_4.InterDirStateTree, rev_tree, tree)
489
490
        subtree = self.make_branch_and_tree('dir')
490
491
        # the most primitive operation: kind
491
492
        self.assertEqual('directory', tree.kind('dir-id'))
492
 
        # a diff against the basis should give us a directory
 
493
        # a diff against the basis should give us a directory and the root (as
 
494
        # the root is new too).
493
495
        tree.lock_read()
494
496
        expected = [('dir-id',
495
497
            (None, u'dir'),
498
500
            (None, 'root'),
499
501
            (None, u'dir'),
500
502
            (None, 'directory'),
501
 
            (None, False))]
 
503
            (None, False)),
 
504
            ('root', (None, u''), True, (False, True), (None, None),
 
505
            (None, u''), (None, 'directory'), (None, 0))]
502
506
        self.assertEqual(expected, list(tree.iter_changes(tree.basis_tree(),
503
507
            specific_files=['dir'])))
504
508
        tree.unlock()
578
582
        self.assertEqual([], changes)
579
583
        self.assertEqual(['', 'versioned', 'versioned2'], returned)
580
584
 
 
585
    def test_iter_changes_unversioned_error(self):
 
586
        """ Check if a PathsNotVersionedError is correctly raised and the
 
587
            paths list contains all unversioned entries only.
 
588
        """
 
589
        tree = self.make_branch_and_tree('tree')
 
590
        self.build_tree_contents([('tree/bar', '')])
 
591
        tree.add(['bar'], ['bar-id'])
 
592
        tree.lock_read()
 
593
        self.addCleanup(tree.unlock)
 
594
        tree_iter_changes = lambda files: [
 
595
            c for c in tree.iter_changes(tree.basis_tree(), specific_files=files,
 
596
                                         require_versioned=True)
 
597
        ]
 
598
        e = self.assertRaises(errors.PathsNotVersionedError,
 
599
                              tree_iter_changes, ['bar', 'foo'])
 
600
        self.assertEqual(e.paths, ['foo'])
 
601
 
581
602
    def get_tree_with_cachable_file_foo(self):
582
603
        tree = self.make_branch_and_tree('.')
583
604
        self.build_tree(['foo'])
584
605
        tree.add(['foo'], ['foo-id'])
585
 
        # a 4 second old timestamp is always hashable - sucks to delay 
 
606
        # a 4 second old timestamp is always hashable - sucks to delay
586
607
        # the test suite, but not testing this is worse.
587
608
        time.sleep(4)
588
609
        return tree
592
613
        revid = tree.commit('a commit')
593
614
        # tree's dirstate should now have a valid stat entry for foo.
594
615
        tree.lock_read()
 
616
        self.addCleanup(tree.unlock)
595
617
        entry = tree._get_entry(path='foo')
596
618
        expected_sha1 = osutils.sha_file_by_name('foo')
597
619
        self.assertEqual(expected_sha1, entry[1][0][1])
659
681
        # Create a corrupted dirstate
660
682
        tree.lock_write()
661
683
        try:
662
 
            tree.commit('init') # We need a parent, or we always compare with NULL
 
684
            # We need a parent, or we always compare with NULL
 
685
            tree.commit('init')
663
686
            state = tree.current_dirstate()
664
687
            state._read_dirblocks_if_needed()
665
688
            # Now add in an invalid entry, a rename with a dangling pointer