~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Aaron Bentley
  • Date: 2009-05-28 07:56:59 UTC
  • mfrom: (4384 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4386.
  • Revision ID: aaron@aaronbentley.com-20090528075659-bb835aj2sr711emf
Merge bzr.dev into commit-preview.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    format_registry,
35
35
    )
36
36
from bzrlib.inventory import Inventory
37
 
from bzrlib.revision import Revision
 
37
from bzrlib.revision import (
 
38
    NULL_REVISION,
 
39
    Revision,
 
40
    )
38
41
from bzrlib.tests import (
39
42
    TestCase,
40
43
    TestCaseWithTransport,
110
113
        return isinstance(target, DummyForeignVcsBranch)
111
114
 
112
115
    def lossy_push(self, stop_revision=None):
 
116
        result = branch.BranchPushResult()
 
117
        result.source_branch = self.source
 
118
        result.target_branch = self.target
 
119
        result.old_revno, result.old_revid = self.target.last_revision_info()
113
120
        self.source.lock_read()
114
121
        try:
115
122
            # This just handles simple cases, but that's good enough for tests
129
136
                    (str(rev.timestamp), str(rev.timezone), 
130
137
                        str(self.target.revno())))
131
138
                parent_revno, parent_revid= self.target.last_revision_info()
132
 
                builder = self.target.get_commit_builder([parent_revid], 
 
139
                if parent_revid == NULL_REVISION:
 
140
                    parent_revids = []
 
141
                else:
 
142
                    parent_revids = [parent_revid]
 
143
                builder = self.target.get_commit_builder(parent_revids, 
133
144
                        self.target.get_config(), rev.timestamp,
134
145
                        rev.timezone, rev.committer, rev.properties,
135
146
                        new_revid)
138
149
                        new_ie = ie.copy()
139
150
                        new_ie.revision = None
140
151
                        builder.record_entry_contents(new_ie, 
141
 
                            [self.target.repository.get_inventory(parent_revid)],
 
152
                            [self.target.repository.revision_tree(parent_revid).inventory],
142
153
                            path, tree, 
143
154
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
144
155
                    builder.finish_inventory()
152
163
                    revid, revidmap[revid])
153
164
        finally:
154
165
            self.source.unlock()
155
 
        return revidmap
 
166
        result.new_revno, result.new_revid = self.target.last_revision_info()
 
167
        result.revidmap = revidmap
 
168
        return result
156
169
 
157
170
 
158
171
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
372
385
        dir = BzrDir.open("d")
373
386
        newdir = dir.sprout("e")
374
387
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
 
388
 
 
389
    def test_lossy_push_empty(self):
 
390
        source_tree = self.make_branch_and_tree("source")
 
391
        target_tree = self.make_branch_and_tree("target", 
 
392
            format=DummyForeignVcsDirFormat())
 
393
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
394
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
395
        self.assertEquals(NULL_REVISION, pushresult.new_revid)
 
396
        self.assertEquals({}, pushresult.revidmap)
 
397
 
 
398
    def test_lossy_push_simple(self):
 
399
        source_tree = self.make_branch_and_tree("source")
 
400
        self.build_tree(['source/a', 'source/b'])
 
401
        source_tree.add(['a', 'b'])
 
402
        revid1 = source_tree.commit("msg")
 
403
        target_tree = self.make_branch_and_tree("target", 
 
404
            format=DummyForeignVcsDirFormat())
 
405
        target_tree.branch.lock_write()
 
406
        try:
 
407
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
408
        finally:
 
409
            target_tree.branch.unlock()
 
410
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
411
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
 
412
                           pushresult.revidmap)
 
413
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)