~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Samuel Bronson
  • Date: 2012-08-30 20:36:18 UTC
  • mto: (6015.57.3 2.4)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: naesten@gmail.com-20120830203618-y2dzw91nqpvpgxvx
Update INSTALL for switch to Python 2.6 and up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch):
92
92
    """A Dummy VCS Branch."""
93
93
 
94
 
    @property
95
 
    def user_transport(self):
96
 
        return self.bzrdir.user_transport
97
 
 
98
94
    def __init__(self, _format, _control_files, a_bzrdir, *args, **kwargs):
99
95
        self._format = _format
100
96
        self._base = a_bzrdir.transport.base
105
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
106
102
            *args, **kwargs)
107
103
 
108
 
    def _get_checkout_format(self, lightweight=False):
 
104
    def _get_checkout_format(self):
109
105
        """Return the most suitable metadir for a checkout of this branch.
110
106
        Weaves are used if this branch's repository uses weaves.
111
107
        """
145
141
    repository_class = DummyForeignVcsRepository
146
142
    _commit_builder_class = DummyForeignCommitBuilder
147
143
 
148
 
    @classmethod
149
 
    def get_format_string(cls):
 
144
    def get_format_string(self):
150
145
        return "Dummy Foreign Vcs Repository"
151
146
 
152
147
    def get_format_description(self):
153
148
        return "Dummy Foreign Vcs Repository"
154
149
 
155
150
 
156
 
def branch_history(graph, revid):
157
 
    ret = list(graph.iter_lefthand_ancestry(revid,
158
 
        (revision.NULL_REVISION,)))
159
 
    ret.reverse()
160
 
    return ret
161
 
 
162
 
 
163
151
class InterToDummyVcsBranch(branch.GenericInterBranch):
164
152
 
165
153
    @staticmethod
177
165
        try:
178
166
            graph = self.source.repository.get_graph()
179
167
            # This just handles simple cases, but that's good enough for tests
180
 
            my_history = branch_history(self.target.repository.get_graph(),
181
 
                result.old_revid)
 
168
            my_history = self.target.revision_history()
182
169
            if stop_revision is None:
183
170
                stop_revision = self.source.last_revision()
184
 
            their_history = branch_history(graph, stop_revision)
 
171
            their_history = list(graph.iter_lefthand_ancestry(stop_revision,
 
172
                (revision.NULL_REVISION,)))
 
173
            their_history.reverse()
185
174
            if their_history[:min(len(my_history), len(their_history))] != my_history:
186
175
                raise errors.DivergedBranches(self.target, self.source)
187
176
            todo = their_history[len(my_history):]
201
190
                else:
202
191
                    parent_revids = [parent_revid]
203
192
                builder = self.target.get_commit_builder(parent_revids, 
204
 
                        self.target.get_config_stack(), rev.timestamp,
 
193
                        self.target.get_config(), rev.timestamp,
205
194
                        rev.timezone, rev.committer, rev.properties,
206
195
                        new_revid)
207
196
                try:
208
 
                    parent_tree = self.target.repository.revision_tree(
209
 
                        parent_revid)
210
 
                    for path, ie in tree.iter_entries_by_dir():
 
197
                    for path, ie in tree.inventory.iter_entries():
211
198
                        new_ie = ie.copy()
212
199
                        new_ie.revision = None
213
200
                        builder.record_entry_contents(new_ie, 
214
 
                            [parent_tree.root_inventory],
 
201
                            [self.target.repository.revision_tree(parent_revid).inventory],
215
202
                            path, tree, 
216
203
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
217
204
                    builder.finish_inventory()
232
219
 
233
220
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
234
221
 
235
 
    @classmethod
236
 
    def get_format_string(cls):
 
222
    def get_format_string(self):
237
223
        return "Branch for Testing"
238
224
 
239
 
    @property
240
 
    def _matchingbzrdir(self):
241
 
        return DummyForeignVcsDirFormat()
 
225
    def __init__(self):
 
226
        super(DummyForeignVcsBranchFormat, self).__init__()
 
227
        self._matchingbzrdir = DummyForeignVcsDirFormat()
242
228
 
243
229
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
244
230
            found_repository=None):
245
 
        if name is None:
246
 
            name = a_bzrdir._get_selected_branch()
247
231
        if not _found:
248
232
            raise NotImplementedError
249
233
        try:
255
239
            return DummyForeignVcsBranch(_format=self,
256
240
                              _control_files=control_files,
257
241
                              a_bzrdir=a_bzrdir,
258
 
                              _repository=found_repository,
259
 
                              name=name)
 
242
                              _repository=found_repository)
260
243
        except errors.NoSuchFile:
261
244
            raise errors.NotBranchError(path=transport.base)
262
245
 
320
303
        self.root_transport.put_bytes(".bzr", "foo")
321
304
        return super(DummyForeignVcsDir, self).create_workingtree()
322
305
 
323
 
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True,
324
 
            possible_transports=None):
325
 
        if name is None:
326
 
            name = self._get_selected_branch()
327
 
        if name != "":
 
306
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
 
307
        if name is not None:
328
308
            raise errors.NoColocatedBranchSupport(self)
329
309
        return self._format.get_branch_format().open(self, _found=True)
330
310
 
331
311
    def cloning_metadir(self, stacked=False):
332
312
        """Produce a metadir suitable for cloning with."""
333
 
        return controldir.format_registry.make_bzrdir("default")
 
313
        return bzrdir.format_registry.make_bzrdir("default")
334
314
 
335
315
    def checkout_metadir(self):
336
316
        return self.cloning_metadir()
431
411
        foreign.update_workingtree_fileids(wt, target_basis)
432
412
        wt.lock_read()
433
413
        try:
434
 
            self.assertEquals(set([root_id, "bla-b"]), set(wt.all_file_ids()))
 
414
            self.assertEquals(set([root_id, "bla-b"]), set(wt.inventory))
435
415
        finally:
436
416
            wt.unlock()
437
417
 
446
426
    def test_create(self):
447
427
        """Test we can create dummies."""
448
428
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
449
 
        dir = controldir.ControlDir.open("d")
 
429
        dir = bzrdir.BzrDir.open("d")
450
430
        self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string())
451
431
        dir.open_repository()
452
432
        dir.open_branch()
455
435
    def test_sprout(self):
456
436
        """Test we can clone dummies and that the format is not preserved."""
457
437
        self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
458
 
        dir = controldir.ControlDir.open("d")
 
438
        dir = bzrdir.BzrDir.open("d")
459
439
        newdir = dir.sprout("e")
460
440
        self.assertNotEquals("A Dummy VCS Dir",
461
441
                             newdir._format.get_format_string())
485
465
            format=DummyForeignVcsDirFormat())
486
466
        target_tree.branch.lock_write()
487
467
        try:
488
 
            pushresult = source_tree.branch.push(
489
 
                target_tree.branch, lossy=True)
 
468
            pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
490
469
        finally:
491
470
            target_tree.branch.unlock()
492
471
        self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)