/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_fetch.py

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    Repo as GitRepo,
24
24
    )
25
25
import os
26
 
import stat
27
26
 
28
27
from bzrlib import (
29
28
    knit,
42
41
from bzrlib.tests import (
43
42
    TestCaseWithTransport,
44
43
    )
 
44
from bzrlib.transport import (
 
45
    get_transport,
 
46
    )
45
47
 
 
48
from bzrlib.plugins.git import (
 
49
    get_rich_root_format,
 
50
    )
46
51
from bzrlib.plugins.git.fetch import (
47
52
    import_git_blob,
48
53
    import_git_tree,
49
54
    )
50
55
from bzrlib.plugins.git.mapping import (
51
56
    BzrGitMappingv1,
52
 
    DEFAULT_FILE_MODE,
 
57
    default_mapping,
 
58
    )
 
59
from bzrlib.plugins.git.shamap import (
 
60
    DictGitShaMap,
53
61
    )
54
62
from bzrlib.plugins.git.tests import (
55
63
    GitBranchBuilder,
64
72
 
65
73
    def clone_git_repo(self, from_url, to_url, revision_id=None):
66
74
        oldrepos = self.open_git_repo(from_url)
67
 
        dir = BzrDir.create(to_url)
 
75
        dir = BzrDir.create(to_url, get_rich_root_format())
68
76
        newrepos = dir.create_repository()
69
77
        oldrepos.copy_content_into(newrepos, revision_id=revision_id)
70
78
        return newrepos
257
265
        return Repository.open(path)
258
266
 
259
267
 
260
 
class DummyStoreUpdater(object):
261
 
 
262
 
    def add_object(self, obj, ie, path):
263
 
        pass
264
 
 
265
 
    def finish(self):
266
 
        pass
267
 
 
268
 
 
269
268
class ImportObjects(TestCaseWithTransport):
270
269
 
271
270
    def setUp(self):
272
271
        super(ImportObjects, self).setUp()
 
272
        self._map = DictGitShaMap()
273
273
        self._mapping = BzrGitMappingv1()
274
274
        factory = knit.make_file_factory(True, versionedfile.PrefixMapper())
275
275
        self._texts = factory(self.get_transport('texts'))
278
278
        blob = Blob.from_string("bar")
279
279
        base_inv = Inventory()
280
280
        objs = { "blobname": blob}
281
 
        ret = import_git_blob(self._texts, self._mapping, "bla", "bla",
282
 
            (None, "blobname"), 
283
 
            base_inv, None, "somerevid", [], objs.__getitem__, 
284
 
            (None, DEFAULT_FILE_MODE), DummyStoreUpdater(),
285
 
            self._mapping.generate_file_id)
 
281
        ret, _= import_git_blob(self._texts, self._mapping, "bla", "blobname", 
 
282
            base_inv, None, None, "somerevid", [], self._map, objs.__getitem__, False,
 
283
            False)
286
284
        self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys())
287
285
        self.assertEquals(self._texts.get_record_stream([('bla', 'somerevid')],
288
286
            "unordered", True).next().get_bytes_as("fulltext"), "bar")
298
296
    def test_import_tree_empty_root(self):
299
297
        base_inv = Inventory(root_id=None)
300
298
        tree = Tree()
301
 
        ret, child_modes = import_git_tree(self._texts, self._mapping, "", "",
302
 
               (None, tree.id), base_inv, 
303
 
               None, "somerevid", [], {tree.id: tree}.__getitem__,
304
 
               (None, stat.S_IFDIR), DummyStoreUpdater(),
305
 
               self._mapping.generate_file_id)
306
 
        self.assertEquals(child_modes, {})
 
299
        tree.serialize()
 
300
        ret, _, _ = import_git_tree(self._texts, self._mapping, "", 
 
301
               tree.id, base_inv, None,
 
302
               None, "somerevid", [], self._map, {tree.id: tree}.__getitem__)
307
303
        self.assertEquals(set([("TREE_ROOT", 'somerevid')]), self._texts.keys())
308
304
        self.assertEquals(1, len(ret))
309
305
        self.assertEquals(None, ret[0][0])
318
314
    def test_import_tree_empty(self):
319
315
        base_inv = Inventory()
320
316
        tree = Tree()
321
 
        ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
322
 
           (None, tree.id), base_inv, None, "somerevid", [], 
323
 
           { tree.id: tree }.__getitem__,
324
 
           (None, stat.S_IFDIR), DummyStoreUpdater(),
325
 
           self._mapping.generate_file_id)
326
 
        self.assertEquals(child_modes, {})
 
317
        tree.serialize()
 
318
        ret, _, _ = import_git_tree(self._texts, self._mapping, "bla", 
 
319
           tree.id, base_inv, None, None, "somerevid", [], 
 
320
           self._map, { tree.id: tree }.__getitem__)
327
321
        self.assertEquals(set([("bla", 'somerevid')]), self._texts.keys())
328
322
        self.assertEquals(1, len(ret))
329
323
        self.assertEquals(None, ret[0][0])
339
333
        base_inv = Inventory()
340
334
        blob = Blob.from_string("bar1")
341
335
        tree = Tree()
342
 
        tree.add(stat.S_IFREG | 0644, "foo", blob.id)
 
336
        tree.add(0100600, "foo", blob.id)
 
337
        tree.serialize()
343
338
        objects = { blob.id: blob, tree.id: tree }
344
 
        ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
345
 
                (None, tree.id), base_inv, None, "somerevid", [],
346
 
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
347
 
            self._mapping.generate_file_id)
348
 
        self.assertEquals(child_modes, {})
 
339
        ret, _, _ = import_git_tree(self._texts, self._mapping, "bla", tree.id, 
 
340
            base_inv, None, None, "somerevid", [], self._map, objects.__getitem__)
349
341
        self.assertEquals(2, len(ret))
350
342
        self.assertEquals(None, ret[0][0])
351
343
        self.assertEquals("bla", ret[0][1])
360
352
        self.assertEquals(osutils.sha_strings(["bar1"]), ie.text_sha1)
361
353
        self.assertEquals(False, ie.executable)
362
354
 
363
 
    def test_import_tree_with_unusual_mode_file(self):
364
 
        base_inv = Inventory()
365
 
        blob = Blob.from_string("bar1")
366
 
        tree = Tree()
367
 
        tree.add(stat.S_IFREG | 0664, "foo", blob.id)
368
 
        objects = { blob.id: blob, tree.id: tree }
369
 
        ret, child_modes = import_git_tree(self._texts, self._mapping, "bla", "bla",
370
 
                (None, tree.id), base_inv, None, "somerevid", [],
371
 
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
372
 
            self._mapping.generate_file_id)
373
 
        self.assertEquals(child_modes, { "bla/foo": stat.S_IFREG | 0664 })
374
 
 
375
355
    def test_import_tree_with_file_exe(self):
376
356
        base_inv = Inventory(root_id=None)
377
357
        blob = Blob.from_string("bar")
378
358
        tree = Tree()
379
359
        tree.add(0100755, "foo", blob.id)
 
360
        tree.serialize()
380
361
        objects = { blob.id: blob, tree.id: tree }
381
 
        ret, child_modes = import_git_tree(self._texts, self._mapping, "", "",
382
 
                (None, tree.id), base_inv, None, "somerevid", [],
383
 
            objects.__getitem__, (None, stat.S_IFDIR), DummyStoreUpdater(),
384
 
            self._mapping.generate_file_id)
385
 
        self.assertEquals(child_modes, {})
 
362
        ret, _, _ = import_git_tree(self._texts, self._mapping, "", tree.id, 
 
363
            base_inv, None, None, "somerevid", [], self._map, objects.__getitem__)
386
364
        self.assertEquals(2, len(ret))
387
365
        self.assertEquals(None, ret[0][0])
388
366
        self.assertEquals("", ret[0][1])