~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    foreign,
27
27
    lockable_files,
28
28
    lockdir,
 
29
    repository,
29
30
    revision,
30
31
    tests,
31
32
    trace,
 
33
    vf_repository,
32
34
    )
33
35
 
 
36
from bzrlib.repofmt import groupcompress_repo
 
37
 
34
38
# This is the dummy foreign revision control system, used 
35
39
# mainly here in the testsuite to test the foreign VCS infrastructure.
36
40
# It is basically standard Bazaar with some minor modifications to 
92
96
        self._base = a_bzrdir.transport.base
93
97
        self._ignore_fallbacks = False
94
98
        self.bzrdir = a_bzrdir
95
 
        foreign.ForeignBranch.__init__(self, 
 
99
        foreign.ForeignBranch.__init__(self,
96
100
            DummyForeignVcsMapping(DummyForeignVcs()))
97
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
 
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
98
102
            *args, **kwargs)
99
103
 
 
104
    def _get_checkout_format(self):
 
105
        """Return the most suitable metadir for a checkout of this branch.
 
106
        Weaves are used if this branch's repository uses weaves.
 
107
        """
 
108
        return self.bzrdir.checkout_metadir()
 
109
 
 
110
    def import_last_revision_info_and_tags(self, source, revno, revid,
 
111
                                           lossy=False):
 
112
        interbranch = InterToDummyVcsBranch(source, self)
 
113
        if lossy:
 
114
            result = interbranch.lossy_push(revid)
 
115
            revid = result.revidmap[revid]
 
116
        else:
 
117
            interbranch.push(revid)
 
118
        return (revno, revid)
 
119
 
 
120
 
 
121
class DummyForeignCommitBuilder(vf_repository.VersionedFileRootCommitBuilder):
 
122
 
 
123
    def _generate_revision_if_needed(self):
 
124
        mapping = DummyForeignVcsMapping(DummyForeignVcs())
 
125
        if self._lossy:
 
126
            self._new_revision_id = mapping.revision_id_foreign_to_bzr(
 
127
                (str(self._timestamp), str(self._timezone), "UNKNOWN"))
 
128
            self.random_revid = False
 
129
        elif self._new_revision_id is not None:
 
130
            self.random_revid = False
 
131
        else:
 
132
            self._new_revision_id = self._gen_revision_id()
 
133
            self.random_revid = True
 
134
 
 
135
 
 
136
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
 
137
    foreign.ForeignRepository):
 
138
    """Dummy foreign vcs repository."""
 
139
 
 
140
 
 
141
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
 
142
 
 
143
    repository_class = DummyForeignVcsRepository
 
144
    _commit_builder_class = DummyForeignCommitBuilder
 
145
 
 
146
    def get_format_string(self):
 
147
        return "Dummy Foreign Vcs Repository"
 
148
 
 
149
    def get_format_description(self):
 
150
        return "Dummy Foreign Vcs Repository"
 
151
 
100
152
 
101
153
class InterToDummyVcsBranch(branch.GenericInterBranch,
102
154
                            foreign.InterToForeignBranch):
117
169
        try:
118
170
            # This just handles simple cases, but that's good enough for tests
119
171
            my_history = self.target.revision_history()
120
 
            their_history = self.source.revision_history()
 
172
            if stop_revision is None:
 
173
                stop_revision = self.source.last_revision()
 
174
            their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
 
175
            their_history.reverse()
121
176
            if their_history[:min(len(my_history), len(their_history))] != my_history:
122
177
                raise errors.DivergedBranches(self.target, self.source)
123
178
            todo = their_history[len(my_history):]
173
228
        super(DummyForeignVcsBranchFormat, self).__init__()
174
229
        self._matchingbzrdir = DummyForeignVcsDirFormat()
175
230
 
176
 
    def open(self, a_bzrdir, name=None, _found=False, found_repository=None):
 
231
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
 
232
            found_repository=None):
177
233
        if not _found:
178
234
            raise NotImplementedError
179
235
        try:
208
264
    def get_branch_format(self):
209
265
        return DummyForeignVcsBranchFormat()
210
266
 
 
267
    @property
 
268
    def repository_format(self):
 
269
        return DummyForeignVcsRepositoryFormat()
 
270
 
211
271
    def initialize_on_transport(self, transport):
212
272
        """Initialize a new bzrdir in the base directory of a Transport."""
213
273
        # Since we don't have a .bzr directory, inherit the
240
300
        self._control_files = lockable_files.LockableFiles(self.transport,
241
301
            "lock", lockable_files.TransportLock)
242
302
 
 
303
    def create_workingtree(self):
 
304
        # dirstate requires a ".bzr" entry to exist
 
305
        self.root_transport.put_bytes(".bzr", "foo")
 
306
        return super(DummyForeignVcsDir, self).create_workingtree()
 
307
 
243
308
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
244
309
        if name is not None:
245
310
            raise errors.NoColocatedBranchSupport(self)
249
314
        """Produce a metadir suitable for cloning with."""
250
315
        return bzrdir.format_registry.make_bzrdir("default")
251
316
 
 
317
    def checkout_metadir(self):
 
318
        return self.cloning_metadir()
 
319
 
252
320
    def sprout(self, url, revision_id=None, force_new_repo=False,
253
321
               recurse='down', possible_transports=None,
254
322
               accelerator_tree=None, hardlink=False, stacked=False,
265
333
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
266
334
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
267
335
        DummyForeignProber)
 
336
    repository.format_registry.register(DummyForeignVcsRepositoryFormat())
 
337
    testcase.addCleanup(repository.format_registry.remove,
 
338
            DummyForeignVcsRepositoryFormat())
 
339
    branch.format_registry.register(DummyForeignVcsBranchFormat())
 
340
    testcase.addCleanup(branch.format_registry.remove,
 
341
            DummyForeignVcsBranchFormat())
268
342
    # We need to register the optimiser to make the dummy appears really
269
343
    # different from a regular bzr repository.
270
344
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
303
377
        reg = foreign.ForeignVcsRegistry()
304
378
        vcs = DummyForeignVcs()
305
379
        reg.register("dummy", vcs, "Dummy VCS")
306
 
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
307
 
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
 
380
        self.assertEquals((
 
381
            ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
 
382
            reg.parse_revision_id("dummy-v1:some-foreign-revid"))
308
383
 
309
384
 
310
385
class ForeignRevisionTests(tests.TestCase):