~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
102
102
            *args, **kwargs)
103
103
 
104
 
    def dpull(self, source, stop_revision=None):
105
 
        source.lock_read()
 
104
 
 
105
class InterToDummyVcsBranch(branch.GenericInterBranch,
 
106
                            foreign.InterToForeignBranch):
 
107
 
 
108
    @staticmethod
 
109
    def is_compatible(source, target):
 
110
        return isinstance(target, DummyForeignVcsBranch)
 
111
 
 
112
    def lossy_push(self, stop_revision=None):
 
113
        self.source.lock_read()
106
114
        try:
107
115
            # This just handles simple cases, but that's good enough for tests
108
 
            my_history = self.revision_history()
109
 
            their_history = source.revision_history()
 
116
            my_history = self.target.revision_history()
 
117
            their_history = self.source.revision_history()
110
118
            if their_history[:min(len(my_history), len(their_history))] != my_history:
111
 
                raise errors.DivergedBranches(self, source)
 
119
                raise errors.DivergedBranches(self.target, self.source)
112
120
            todo = their_history[len(my_history):]
113
121
            revidmap = {}
114
122
            for revid in todo:
115
 
                rev = source.repository.get_revision(revid)
116
 
                tree = source.repository.revision_tree(revid)
 
123
                rev = self.source.repository.get_revision(revid)
 
124
                tree = self.source.repository.revision_tree(revid)
117
125
                def get_file_with_stat(file_id, path=None):
118
126
                    return (tree.get_file(file_id), None)
119
127
                tree.get_file_with_stat = get_file_with_stat
120
 
                new_revid = self.mapping.revision_id_foreign_to_bzr(
121
 
                    (str(rev.timestamp), str(rev.timezone), str(self.revno())))
122
 
                parent_revno, parent_revid= self.last_revision_info()
123
 
                builder = self.get_commit_builder([parent_revid], 
124
 
                        self.get_config(), rev.timestamp,
 
128
                new_revid = self.target.mapping.revision_id_foreign_to_bzr(
 
129
                    (str(rev.timestamp), str(rev.timezone), 
 
130
                        str(self.target.revno())))
 
131
                parent_revno, parent_revid= self.target.last_revision_info()
 
132
                builder = self.target.get_commit_builder([parent_revid], 
 
133
                        self.target.get_config(), rev.timestamp,
125
134
                        rev.timezone, rev.committer, rev.properties,
126
135
                        new_revid)
127
136
                try:
129
138
                        new_ie = ie.copy()
130
139
                        new_ie.revision = None
131
140
                        builder.record_entry_contents(new_ie, 
132
 
                            [self.repository.get_inventory(parent_revid)],
 
141
                            [self.target.repository.get_inventory(parent_revid)],
133
142
                            path, tree, 
134
143
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
135
144
                    builder.finish_inventory()
137
146
                    builder.abort()
138
147
                    raise
139
148
                revidmap[revid] = builder.commit(rev.message)
140
 
                self.set_last_revision_info(parent_revno+1, revidmap[revid])
 
149
                self.target.set_last_revision_info(parent_revno+1, 
 
150
                    revidmap[revid])
141
151
                trace.mutter('lossily pushed revision %s -> %s', 
142
152
                    revid, revidmap[revid])
143
153
        finally:
144
 
            source.unlock()
 
154
            self.source.unlock()
145
155
        return revidmap
146
156
 
147
157
 
336
346
 
337
347
    def setUp(self):
338
348
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
349
        branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
339
350
        self.addCleanup(self.unregister)
340
351
        super(DummyForeignVcsTests, self).setUp()
341
352
 
344
355
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
345
356
        except ValueError:
346
357
            pass
 
358
        branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
347
359
 
348
360
    def test_create(self):
349
361
        """Test we can create dummies."""