~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree_4.py

  • Committer: Andrew Bennetts
  • Date: 2010-08-17 06:45:33 UTC
  • mfrom: (5050.17.9 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: andrew.bennetts@canonical.com-20100817064533-kof2i2f3r6mr4ayb
Merge lp:bzr/2.2 into lp:bzr, including fixes for #192859, #224373, #300062, #585667, #614404, #617503.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
57
57
        finally:
58
58
            state.unlock()
59
59
 
60
 
    def test_resets_ignores_on_last_unlock(self):
61
 
        # Only the last unlock call will actually reset the
62
 
        # ignores. (bug #785671)
63
 
        tree = self.make_workingtree()
64
 
        tree.lock_read()
65
 
        try:
66
 
            tree.lock_read()
67
 
            try:
68
 
                tree.is_ignored("foo")
69
 
            finally:
70
 
                tree.unlock()
71
 
            self.assertIsNot(None, tree._ignoreglobster)
72
 
        finally:
73
 
            tree.unlock()
74
 
        self.assertIs(None, tree._ignoreglobster)
75
 
 
76
60
    def test_uses_lockdir(self):
77
61
        """WorkingTreeFormat4 uses its own LockDir:
78
62
 
190
174
        # it's given; any calls to forbidden methods will raise an
191
175
        # AssertionError
192
176
        repo = tree.branch.repository
193
 
        self.overrideAttr(repo, "get_revision", self.fail)
194
 
        self.overrideAttr(repo, "get_inventory", self.fail)
195
 
        self.overrideAttr(repo, "_get_inventory_xml", self.fail)
 
177
        repo.get_revision = self.fail
 
178
        repo.get_inventory = self.fail
 
179
        repo._get_inventory_xml = self.fail
196
180
        # try to set the parent trees.
197
181
        tree.set_parent_trees([(rev1, rev1_tree)])
198
182
 
230
214
        # answer 'get_parent_ids' for the revision tree- dirstate does not
231
215
        # cache the parents of a parent tree at this point.
232
216
        #repo.get_revision = self.fail
233
 
        self.overrideAttr(repo, "get_inventory", self.fail)
234
 
        self.overrideAttr(repo, "_get_inventory_xml", self.fail)
 
217
        repo.get_inventory = self.fail
 
218
        repo._get_inventory_xml = self.fail
235
219
        # set the parent trees.
236
220
        tree.set_parent_trees([(rev1, rev1_tree), (rev2, rev2_tree)])
237
221
        # read the first tree
274
258
        lock_and_call_current_dirstate(tree, 'lock_tree_write')
275
259
        self.assertRaises(errors.ObjectNotLocked, tree.current_dirstate)
276
260
 
277
 
    def test_set_parent_trees_uses_update_basis_by_delta(self):
278
 
        builder = self.make_branch_builder('source')
279
 
        builder.start_series()
280
 
        self.addCleanup(builder.finish_series)
281
 
        builder.build_snapshot('A', [], [
282
 
            ('add', ('', 'root-id', 'directory', None)),
283
 
            ('add', ('a', 'a-id', 'file', 'content\n'))])
284
 
        builder.build_snapshot('B', ['A'], [
285
 
            ('modify', ('a-id', 'new content\nfor a\n')),
286
 
            ('add', ('b', 'b-id', 'file', 'b-content\n'))])
287
 
        tree = self.make_workingtree('tree')
288
 
        source_branch = builder.get_branch()
289
 
        tree.branch.repository.fetch(source_branch.repository, 'B')
290
 
        tree.pull(source_branch, stop_revision='A')
291
 
        tree.lock_write()
292
 
        self.addCleanup(tree.unlock)
293
 
        state = tree.current_dirstate()
294
 
        called = []
295
 
        orig_update = state.update_basis_by_delta
296
 
        def log_update_basis_by_delta(delta, new_revid):
297
 
            called.append(new_revid)
298
 
            return orig_update(delta, new_revid)
299
 
        state.update_basis_by_delta = log_update_basis_by_delta
300
 
        basis = tree.basis_tree()
301
 
        self.assertEqual('a-id', basis.path2id('a'))
302
 
        self.assertEqual(None, basis.path2id('b'))
303
 
        def fail_set_parent_trees(trees, ghosts):
304
 
            raise AssertionError('dirstate.set_parent_trees() was called')
305
 
        state.set_parent_trees = fail_set_parent_trees
306
 
        repo = tree.branch.repository
307
 
        tree.pull(source_branch, stop_revision='B')
308
 
        self.assertEqual(['B'], called)
309
 
        basis = tree.basis_tree()
310
 
        self.assertEqual('a-id', basis.path2id('a'))
311
 
        self.assertEqual('b-id', basis.path2id('b'))
312
 
 
313
 
    def test_set_parent_trees_handles_missing_basis(self):
314
 
        builder = self.make_branch_builder('source')
315
 
        builder.start_series()
316
 
        self.addCleanup(builder.finish_series)
317
 
        builder.build_snapshot('A', [], [
318
 
            ('add', ('', 'root-id', 'directory', None)),
319
 
            ('add', ('a', 'a-id', 'file', 'content\n'))])
320
 
        builder.build_snapshot('B', ['A'], [
321
 
            ('modify', ('a-id', 'new content\nfor a\n')),
322
 
            ('add', ('b', 'b-id', 'file', 'b-content\n'))])
323
 
        builder.build_snapshot('C', ['A'], [
324
 
            ('add', ('c', 'c-id', 'file', 'c-content\n'))])
325
 
        b_c = self.make_branch('branch_with_c')
326
 
        b_c.pull(builder.get_branch(), stop_revision='C')
327
 
        b_b = self.make_branch('branch_with_b')
328
 
        b_b.pull(builder.get_branch(), stop_revision='B')
329
 
        # This is reproducing some of what 'switch' does, just to isolate the
330
 
        # set_parent_trees() step.
331
 
        wt = b_b.create_checkout('tree', lightweight=True)
332
 
        fmt = wt.bzrdir.find_branch_format()
333
 
        fmt.set_reference(wt.bzrdir, None, b_c)
334
 
        # Re-open with the new reference
335
 
        wt = wt.bzrdir.open_workingtree()
336
 
        wt.set_parent_trees([('C', b_c.repository.revision_tree('C'))])
337
 
        self.assertEqual(None, wt.basis_tree().path2id('b'))
338
 
 
339
261
    def test_new_dirstate_on_new_lock(self):
340
262
        # until we have detection for when a dirstate can be reused, we
341
263
        # want to reparse dirstate on every new lock.
675
597
 
676
598
    def get_tree_with_cachable_file_foo(self):
677
599
        tree = self.make_branch_and_tree('.')
678
 
        tree.lock_write()
679
 
        self.addCleanup(tree.unlock)
680
 
        self.build_tree_contents([('foo', 'a bit of content for foo\n')])
 
600
        self.build_tree(['foo'])
681
601
        tree.add(['foo'], ['foo-id'])
682
 
        tree.current_dirstate()._cutoff_time = time.time() + 60
 
602
        # a 4 second old timestamp is always hashable - sucks to delay
 
603
        # the test suite, but not testing this is worse.
 
604
        time.sleep(4)
683
605
        return tree
684
606
 
685
607
    def test_commit_updates_hash_cache(self):
686
608
        tree = self.get_tree_with_cachable_file_foo()
687
609
        revid = tree.commit('a commit')
688
610
        # tree's dirstate should now have a valid stat entry for foo.
 
611
        tree.lock_read()
 
612
        self.addCleanup(tree.unlock)
689
613
        entry = tree._get_entry(path='foo')
690
614
        expected_sha1 = osutils.sha_file_by_name('foo')
691
615
        self.assertEqual(expected_sha1, entry[1][0][1])
692
 
        self.assertEqual(len('a bit of content for foo\n'), entry[1][0][2])
693
616
 
694
617
    def test_observed_sha1_cachable(self):
695
618
        tree = self.get_tree_with_cachable_file_foo()
696
619
        expected_sha1 = osutils.sha_file_by_name('foo')
697
620
        statvalue = os.lstat("foo")
698
 
        tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
699
 
        entry = tree._get_entry(path="foo")
700
 
        entry_state = entry[1][0]
701
 
        self.assertEqual(expected_sha1, entry_state[1])
702
 
        self.assertEqual(statvalue.st_size, entry_state[2])
703
 
        tree.unlock()
704
 
        tree.lock_read()
 
621
        tree.lock_write()
 
622
        try:
 
623
            tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
 
624
            self.assertEqual(expected_sha1,
 
625
                tree._get_entry(path="foo")[1][0][1])
 
626
        finally:
 
627
            tree.unlock()
705
628
        tree = tree.bzrdir.open_workingtree()
706
629
        tree.lock_read()
707
630
        self.addCleanup(tree.unlock)
708
 
        entry = tree._get_entry(path="foo")
709
 
        entry_state = entry[1][0]
710
 
        self.assertEqual(expected_sha1, entry_state[1])
711
 
        self.assertEqual(statvalue.st_size, entry_state[2])
 
631
        self.assertEqual(expected_sha1, tree._get_entry(path="foo")[1][0][1])
712
632
 
713
633
    def test_observed_sha1_new_file(self):
714
634
        tree = self.make_branch_and_tree('.')