~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

Abbreviate pack_stat struct format to '>6L'

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 _get_checkout_format(self):
 
104
    def _get_checkout_format(self, lightweight=False):
105
105
        """Return the most suitable metadir for a checkout of this branch.
106
106
        Weaves are used if this branch's repository uses weaves.
107
107
        """
110
110
    def import_last_revision_info_and_tags(self, source, revno, revid,
111
111
                                           lossy=False):
112
112
        interbranch = InterToDummyVcsBranch(source, self)
 
113
        result = interbranch.push(stop_revision=revid, lossy=True)
113
114
        if lossy:
114
 
            result = interbranch.lossy_push(revid)
115
115
            revid = result.revidmap[revid]
116
 
        else:
117
 
            interbranch.push(revid)
118
116
        return (revno, revid)
119
117
 
120
118
 
150
148
        return "Dummy Foreign Vcs Repository"
151
149
 
152
150
 
153
 
class InterToDummyVcsBranch(branch.GenericInterBranch,
154
 
                            foreign.InterToForeignBranch):
 
151
class InterToDummyVcsBranch(branch.GenericInterBranch):
155
152
 
156
153
    @staticmethod
157
154
    def is_compatible(source, target):
158
155
        return isinstance(target, DummyForeignVcsBranch)
159
156
 
160
 
    def push(self, overwrite=False, stop_revision=None):
161
 
        raise errors.NoRoundtrippingSupport(self.source, self.target)
162
 
 
163
 
    def lossy_push(self, stop_revision=None):
 
157
    def push(self, overwrite=False, stop_revision=None, lossy=False):
 
158
        if not lossy:
 
159
            raise errors.NoRoundtrippingSupport(self.source, self.target)
164
160
        result = branch.BranchPushResult()
165
161
        result.source_branch = self.source
166
162
        result.target_branch = self.target
167
163
        result.old_revno, result.old_revid = self.target.last_revision_info()
168
164
        self.source.lock_read()
169
165
        try:
 
166
            graph = self.source.repository.get_graph()
170
167
            # This just handles simple cases, but that's good enough for tests
171
168
            my_history = self.target.revision_history()
172
169
            if stop_revision is None:
173
170
                stop_revision = self.source.last_revision()
174
 
            their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
 
171
            their_history = list(graph.iter_lefthand_ancestry(stop_revision,
 
172
                (revision.NULL_REVISION,)))
175
173
            their_history.reverse()
176
174
            if their_history[:min(len(my_history), len(their_history))] != my_history:
177
175
                raise errors.DivergedBranches(self.target, self.source)
184
182
                    return (tree.get_file(file_id), None)
185
183
                tree.get_file_with_stat = get_file_with_stat
186
184
                new_revid = self.target.mapping.revision_id_foreign_to_bzr(
187
 
                    (str(rev.timestamp), str(rev.timezone), 
 
185
                    (str(rev.timestamp), str(rev.timezone),
188
186
                        str(self.target.revno())))
189
187
                parent_revno, parent_revid= self.target.last_revision_info()
190
188
                if parent_revid == revision.NULL_REVISION:
453
451
        source_tree = self.make_branch_and_tree("source")
454
452
        target_tree = self.make_branch_and_tree("target", 
455
453
            format=DummyForeignVcsDirFormat())
456
 
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
454
        pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
457
455
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
458
456
        self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
459
457
        self.assertEquals({}, pushresult.revidmap)
467
465
            format=DummyForeignVcsDirFormat())
468
466
        target_tree.branch.lock_write()
469
467
        try:
470
 
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
468
            pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
471
469
        finally:
472
470
            target_tree.branch.unlock()
473
471
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)