/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/repository_implementations/test_commit_builder.py

  • Committer: Martin Pool
  • Date: 2007-10-10 00:21:57 UTC
  • mfrom: (2900 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071010002157-utci0x44m2w47wgd
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for repository commit builder."""
18
18
 
 
19
from copy import copy
19
20
import errno
20
21
import os
21
22
import sys
51
52
                tree.unlock()
52
53
            parent_tree = tree.branch.repository.revision_tree(None)
53
54
            parent_invs = []
54
 
            builder.record_entry_contents(ie, parent_invs, '', tree)
 
55
            builder.record_entry_contents(ie, parent_invs, '', tree,
 
56
                tree.path_content_summary(''))
55
57
 
56
58
    def test_finish_inventory(self):
57
59
        tree = self.make_branch_and_tree(".")
120
122
        self.assertEqual(revision_id,
121
123
            tree.branch.repository.get_inventory(revision_id).revision_id)
122
124
 
123
 
    def test_commit_without_root(self):
124
 
        """This should cause a deprecation warning, not an assertion failure"""
 
125
    def test_commit_without_root_errors(self):
125
126
        tree = self.make_branch_and_tree(".")
126
127
        tree.lock_write()
127
128
        try:
128
 
            if tree.branch.repository.supports_rich_root():
129
 
                raise tests.TestSkipped('Format requires root')
130
129
            self.build_tree(['foo'])
131
130
            tree.add('foo', 'foo-id')
132
131
            entry = tree.inventory['foo-id']
133
132
            builder = tree.branch.get_commit_builder([])
134
 
            self.callDeprecated(['Root entry should be supplied to'
135
 
                ' record_entry_contents, as of bzr 0.10.'],
136
 
                builder.record_entry_contents, entry, [], 'foo', tree)
137
 
            builder.finish_inventory()
138
 
            rev_id = builder.commit('foo bar')
 
133
            self.assertRaises(errors.RootMissing,
 
134
                builder.record_entry_contents, entry, [], 'foo', tree,
 
135
                    tree.path_content_summary('foo'))
 
136
            builder.abort()
139
137
        finally:
140
138
            tree.unlock()
141
139
    
150
148
        try:
151
149
            ie = inventory.make_entry('directory', '', None,
152
150
                    tree.inventory.root.file_id)
153
 
            self.assertFalse(builder.record_entry_contents(
154
 
                ie, [parent_tree.inventory], '', tree))
 
151
            delta, version_recorded = builder.record_entry_contents(
 
152
                ie, [parent_tree.inventory], '', tree,
 
153
                tree.path_content_summary(''))
 
154
            self.assertFalse(version_recorded)
 
155
            self.assertEqual(None, delta)
155
156
            builder.abort()
156
157
        except:
157
158
            builder.abort()
226
227
    def _add_commit_check_unchanged(self, tree, name):
227
228
        tree.add([name], [name + 'id'])
228
229
        rev1 = tree.commit('')
229
 
        rev2 = tree.commit('')
 
230
        rev2 = self.mini_commit(tree, name, name, False, False)
230
231
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
231
232
        self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
232
233
        self.assertEqual(rev1, tree2.inventory[name + 'id'].revision)
320
321
        tree.add([name], [name + 'id'])
321
322
        rev1 = tree.commit('')
322
323
        changer()
 
324
        rev2 = self.mini_commit(tree, name, tree.id2path(name + 'id'))
 
325
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
 
326
        self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
 
327
        self.assertEqual(rev2, tree2.inventory[name + 'id'].revision)
 
328
        self.assertFileAncestry([rev1, rev2], tree, name)
 
329
 
 
330
    def mini_commit(self, tree, name, new_name, records_version=True,
 
331
        delta_against_basis=True):
 
332
        """Perform a miniature commit looking for record entry results.
 
333
        
 
334
        :param tree: The tree to commit.
 
335
        :param name: The path in the basis tree of the tree being committed.
 
336
        :param new_name: The path in the tree being committed.
 
337
        :param records_version: True if the commit of new_name is expected to
 
338
            record a new version.
 
339
        :param delta_against_basis: True of the commit of new_name is expected
 
340
            to have a delta against the basis.
 
341
        """
323
342
        tree.lock_write()
324
343
        try:
325
344
            # mini manual commit here so we can check the return of
326
345
            # record_entry_contents.
327
 
            builder = tree.branch.get_commit_builder([tree.last_revision()])
 
346
            parent_ids = tree.get_parent_ids()
 
347
            builder = tree.branch.get_commit_builder(parent_ids)
328
348
            parent_tree = tree.basis_tree()
329
349
            parent_tree.lock_read()
330
350
            self.addCleanup(parent_tree.unlock)
331
351
            parent_invs = [parent_tree.inventory]
 
352
            for parent_id in parent_ids[1:]:
 
353
                parent_invs.append(tree.branch.repository.revision_tree(
 
354
                    parent_id).inventory)
332
355
            # root
333
356
            builder.record_entry_contents(
334
357
                inventory.make_entry('directory', '', None,
335
 
                    tree.inventory.root.file_id), parent_invs, '', tree)
 
358
                    tree.inventory.root.file_id), parent_invs, '', tree,
 
359
                    tree.path_content_summary(''))
336
360
            def commit_id(file_id):
337
361
                old_ie = tree.inventory[file_id]
338
362
                path = tree.id2path(file_id)
339
363
                ie = inventory.make_entry(tree.kind(file_id), old_ie.name,
340
364
                    old_ie.parent_id, file_id)
341
 
                return builder.record_entry_contents(ie, parent_invs, path, tree)
 
365
                return builder.record_entry_contents(ie, parent_invs, path,
 
366
                    tree, tree.path_content_summary(path))
342
367
 
343
 
            file_id = name + 'id'
 
368
            file_id = tree.path2id(new_name)
344
369
            parent_id = tree.inventory[file_id].parent_id
345
370
            if parent_id != tree.inventory.root.file_id:
346
371
                commit_id(parent_id)
347
372
            # because a change of some sort is meant to have occurred,
348
373
            # recording the entry must return True.
349
 
            self.assertTrue(commit_id(file_id))
 
374
            delta, version_recorded = commit_id(file_id)
 
375
            if records_version:
 
376
                self.assertTrue(version_recorded)
 
377
            else:
 
378
                self.assertFalse(version_recorded)
 
379
            new_entry = builder.new_inventory[file_id]
 
380
            if delta_against_basis:
 
381
                expected_delta = (name, new_name, file_id, new_entry)
 
382
            else:
 
383
                expected_delta = None
 
384
            if expected_delta != delta:
 
385
                import pdb;pdb.set_trace()
 
386
            self.assertEqual(expected_delta, delta)
350
387
            builder.finish_inventory()
351
388
            rev2 = builder.commit('')
352
389
            tree.set_parent_ids([rev2])
356
393
            raise
357
394
        else:
358
395
            tree.unlock()
359
 
        tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
360
 
        self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
361
 
        self.assertEqual(rev2, tree2.inventory[name + 'id'].revision)
362
 
        self.assertFileAncestry([rev1, rev2], tree, name)
 
396
        return rev2
363
397
 
364
398
    def assertFileAncestry(self, ancestry, tree, name, alt_ancestry=None):
365
399
        # all the changes that have occured should be in the ancestry
408
442
        rev2 = self._rename_in_tree(tree1, name)
409
443
        rev3 = self._rename_in_tree(tree2, name)
410
444
        tree1.merge_from_branch(tree2.branch)
411
 
        rev4 = tree1.commit('')
 
445
        rev4 = self.mini_commit(tree1, 'new_' + name, 'new_' + name)
412
446
        tree3, = self._get_revtrees(tree1, [rev4])
413
447
        self.assertEqual(rev4, tree3.inventory[name + 'id'].revision)
414
448
        # TODO: change this to an assertFileGraph call to check the
440
474
        # change on the other side to merge back
441
475
        rev2 = self._rename_in_tree(tree2, name)
442
476
        tree1.merge_from_branch(tree2.branch)
443
 
        rev3 = tree1.commit('')
 
477
        rev3 = self.mini_commit(tree1, name, 'new_' + name, False)
444
478
        tree3, = self._get_revtrees(tree1, [rev2])
445
479
        self.assertEqual(rev2, tree3.inventory[name + 'id'].revision)
446
480
        self.assertFileAncestry([rev1, rev2], tree1, name)