コード例 #1
0
 def setUp(self):
     super(GitImportProcessorTests, self).setUp()
     self.repo = MemoryRepo()
     try:
         from dulwich.fastexport import GitImportProcessor
     except ImportError:
         raise SkipTest("python-fastimport not available")
     self.processor = GitImportProcessor(self.repo)
コード例 #2
0
ファイル: __init__.py プロジェクト: silvrwolfboy/breezy
 def finish(self):
     """We are finished building, close the stream, get the id mapping"""
     self.stream.seek(0)
     if self.orig_stream is None:
         from dulwich.repo import Repo
         r = Repo(".")
         from dulwich.fastexport import GitImportProcessor
         importer = GitImportProcessor(r)
         return importer.import_stream(self.stream)
コード例 #3
0
ファイル: test_fastexport.py プロジェクト: rcrowley/dulwich
class GitImportProcessorTests(TestCase):
    """Tests for the GitImportProcessor tests."""

    def setUp(self):
        super(GitImportProcessorTests, self).setUp()
        self.repo = MemoryRepo()
        try:
            from dulwich.fastexport import GitImportProcessor
        except ImportError:
            raise TestSkipped("python-fastimport not available")
        self.processor = GitImportProcessor(self.repo)

    def test_commit_handler(self):
        from fastimport import commands
        cmd = commands.CommitCommand("refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            "FOO", None, [], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEquals("Jelmer <*****@*****.**>", commit.author)
        self.assertEquals("Jelmer <*****@*****.**>", commit.committer)
        self.assertEquals("FOO", commit.message)
        self.assertEquals([], commit.parents)
        self.assertEquals(432432432.0, commit.commit_time)
        self.assertEquals(432432432.0, commit.author_time)
        self.assertEquals(3600, commit.commit_timezone)
        self.assertEquals(3600, commit.author_timezone)
        self.assertEquals(commit, self.repo["refs/heads/foo"])

    def test_import_stream(self):
        markers = self.processor.import_stream(StringIO("""blob
mark :1
data 11
text for a

commit refs/heads/master
mark :2
committer Joe Foo <*****@*****.**> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a

"""))
        self.assertEquals(2, len(markers))
        self.assertTrue(isinstance(self.repo[markers["1"]], Blob))
        self.assertTrue(isinstance(self.repo[markers["2"]], Commit))
コード例 #4
0
ファイル: test_fastexport.py プロジェクト: rcrowley/dulwich
 def setUp(self):
     super(GitImportProcessorTests, self).setUp()
     self.repo = MemoryRepo()
     try:
         from dulwich.fastexport import GitImportProcessor
     except ImportError:
         raise TestSkipped("python-fastimport not available")
     self.processor = GitImportProcessor(self.repo)
コード例 #5
0
ファイル: dulwich_bug.py プロジェクト: tedks/dulwich-bug
#!/usr/bin/python
"""
A simple test script that calls GitImportProcessor on sys.stdin.
"""
import sys

from dulwich.repo import Repo
from dulwich.fastexport import GitImportProcessor

from tempfile import mkdtemp

if __name__ == "__main__":
    nr = Repo.init(mkdtemp())
    fi = GitImportProcessor(nr)
    fi.import_stream(sys.stdin)
    exit(0)
コード例 #6
0
class GitImportProcessorTests(TestCase):
    """Tests for the GitImportProcessor tests."""
    def setUp(self):
        super(GitImportProcessorTests, self).setUp()
        self.repo = MemoryRepo()
        try:
            from dulwich.fastexport import GitImportProcessor
        except ImportError:
            raise SkipTest("python-fastimport not available")
        self.processor = GitImportProcessor(self.repo)

    def test_reset_handler(self):
        from fastimport import commands
        [c1] = build_commit_graph(self.repo.object_store, [[1]])
        cmd = commands.ResetCommand("refs/heads/foo", c1.id)
        self.processor.reset_handler(cmd)
        self.assertEquals(c1.id, self.repo.get_refs()["refs/heads/foo"])

    def test_commit_handler(self):
        from fastimport import commands
        cmd = commands.CommitCommand(
            "refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [],
            [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual("Jelmer <*****@*****.**>", commit.author)
        self.assertEqual("Jelmer <*****@*****.**>", commit.committer)
        self.assertEqual("FOO", commit.message)
        self.assertEqual([], commit.parents)
        self.assertEqual(432432432.0, commit.commit_time)
        self.assertEqual(432432432.0, commit.author_time)
        self.assertEqual(3600, commit.commit_timezone)
        self.assertEqual(3600, commit.author_timezone)
        self.assertEqual(commit, self.repo["refs/heads/foo"])

    def test_import_stream(self):
        markers = self.processor.import_stream(
            BytesIO("""blob
mark :1
data 11
text for a

commit refs/heads/master
mark :2
committer Joe Foo <*****@*****.**> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a

"""))
        self.assertEqual(2, len(markers))
        self.assertTrue(isinstance(self.repo[markers["1"]], Blob))
        self.assertTrue(isinstance(self.repo[markers["2"]], Commit))

    def test_file_add(self):
        from fastimport import commands
        cmd = commands.BlobCommand("23", "data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
            "refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [],
            [commands.FileModifyCommand("path", 0o100644, ":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(
            [('path', 0o100644, '6320cd248dd8aeaab759d5871f8781b5c0505172')],
            self.repo[commit.tree].items())

    def simple_commit(self):
        from fastimport import commands
        cmd = commands.BlobCommand("23", "data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
            "refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [],
            [commands.FileModifyCommand("path", 0o100644, ":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        return commit

    def make_file_commit(self, file_cmds):
        """Create a trivial commit with the specified file commands.

        :param file_cmds: File commands to run.
        :return: The created commit object
        """
        from fastimport import commands
        cmd = commands.CommitCommand(
            "refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600), "FOO", None, [],
            file_cmds)
        self.processor.commit_handler(cmd)
        return self.repo[self.processor.last_commit]

    def test_file_copy(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
            [commands.FileCopyCommand("path", "new_path")])
        self.assertEqual([
            ('new_path', 0o100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
            ('path', 0o100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
        ], self.repo[commit.tree].items())

    def test_file_move(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
            [commands.FileRenameCommand("path", "new_path")])
        self.assertEqual([
            ('new_path', 0o100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
        ], self.repo[commit.tree].items())

    def test_file_delete(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteCommand("path")])
        self.assertEqual([], self.repo[commit.tree].items())

    def test_file_deleteall(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteAllCommand()])
        self.assertEqual([], self.repo[commit.tree].items())
コード例 #7
0
ファイル: test_fastexport.py プロジェクト: AaronO/dulwich
class GitImportProcessorTests(TestCase):
    """Tests for the GitImportProcessor tests."""

    def setUp(self):
        super(GitImportProcessorTests, self).setUp()
        self.repo = MemoryRepo()
        try:
            from dulwich.fastexport import GitImportProcessor
        except ImportError:
            raise SkipTest("python-fastimport not available")
        self.processor = GitImportProcessor(self.repo)

    def test_commit_handler(self):
        from fastimport import commands
        cmd = commands.CommitCommand("refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            "FOO", None, [], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual("Jelmer <*****@*****.**>", commit.author)
        self.assertEqual("Jelmer <*****@*****.**>", commit.committer)
        self.assertEqual("FOO", commit.message)
        self.assertEqual([], commit.parents)
        self.assertEqual(432432432.0, commit.commit_time)
        self.assertEqual(432432432.0, commit.author_time)
        self.assertEqual(3600, commit.commit_timezone)
        self.assertEqual(3600, commit.author_timezone)
        self.assertEqual(commit, self.repo["refs/heads/foo"])

    def test_import_stream(self):
        markers = self.processor.import_stream(StringIO("""blob
mark :1
data 11
text for a

commit refs/heads/master
mark :2
committer Joe Foo <*****@*****.**> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a

"""))
        self.assertEqual(2, len(markers))
        self.assertTrue(isinstance(self.repo[markers["1"]], Blob))
        self.assertTrue(isinstance(self.repo[markers["2"]], Commit))

    def test_file_add(self):
        from fastimport import commands
        cmd = commands.BlobCommand("23", "data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand("refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            "FOO", None, [], [commands.FileModifyCommand("path", 0100644, ":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual([
            ('path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172')],
            self.repo[commit.tree].items())

    def simple_commit(self):
        from fastimport import commands
        cmd = commands.BlobCommand("23", "data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand("refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            "FOO", None, [], [commands.FileModifyCommand("path", 0100644, ":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        return commit

    def make_file_commit(self, file_cmds):
        """Create a trivial commit with the specified file commands.

        :param file_cmds: File commands to run.
        :return: The created commit object
        """
        from fastimport import commands
        cmd = commands.CommitCommand("refs/heads/foo", "mrkr",
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            ("Jelmer", "*****@*****.**", 432432432.0, 3600),
            "FOO", None, [], file_cmds)
        self.processor.commit_handler(cmd)
        return self.repo[self.processor.last_commit]

    def test_file_copy(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileCopyCommand("path", "new_path")])
        self.assertEqual([
            ('new_path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
            ('path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
            ], self.repo[commit.tree].items())

    def test_file_move(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileRenameCommand("path", "new_path")])
        self.assertEqual([
            ('new_path', 0100644, '6320cd248dd8aeaab759d5871f8781b5c0505172'),
            ], self.repo[commit.tree].items())

    def test_file_delete(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteCommand("path")])
        self.assertEqual([], self.repo[commit.tree].items())

    def test_file_deleteall(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteAllCommand()])
        self.assertEqual([], self.repo[commit.tree].items())
コード例 #8
0
ファイル: dulwich_bug.py プロジェクト: tedks/dulwich-bug
#!/usr/bin/python

"""
A simple test script that calls GitImportProcessor on sys.stdin.
"""
import sys

from dulwich.repo import Repo
from dulwich.fastexport import GitImportProcessor

from tempfile import mkdtemp


if __name__ == "__main__":
    nr = Repo.init(mkdtemp())
    fi = GitImportProcessor(nr)
    fi.import_stream(sys.stdin)
    exit(0)
    
コード例 #9
0
ファイル: test_fastexport.py プロジェクト: jelmer/dulwich
class GitImportProcessorTests(TestCase):
    """Tests for the GitImportProcessor tests."""

    def setUp(self):
        super(GitImportProcessorTests, self).setUp()
        self.repo = MemoryRepo()
        try:
            from dulwich.fastexport import GitImportProcessor
        except ImportError:
            raise SkipTest("python-fastimport not available")
        self.processor = GitImportProcessor(self.repo)

    def test_reset_handler(self):
        from fastimport import commands
        [c1] = build_commit_graph(self.repo.object_store, [[1]])
        cmd = commands.ResetCommand(b"refs/heads/foo", c1.id)
        self.processor.reset_handler(cmd)
        self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])
        self.assertEqual(c1.id, self.processor.last_commit)

    def test_reset_handler_marker(self):
        from fastimport import commands
        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
        self.processor.markers[b'10'] = c1.id
        cmd = commands.ResetCommand(b"refs/heads/foo", b':10')
        self.processor.reset_handler(cmd)
        self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])

    def test_reset_handler_default(self):
        from fastimport import commands
        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
        cmd = commands.ResetCommand(b"refs/heads/foo", None)
        self.processor.reset_handler(cmd)
        self.assertEqual(ZERO_SHA, self.repo.get_refs()[b"refs/heads/foo"])

    def test_commit_handler(self):
        from fastimport import commands
        cmd = commands.CommitCommand(
                b"refs/heads/foo",  b"mrkr",
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                b"FOO", None, [], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(b"Jelmer <*****@*****.**>", commit.author)
        self.assertEqual(b"Jelmer <*****@*****.**>", commit.committer)
        self.assertEqual(b"FOO", commit.message)
        self.assertEqual([], commit.parents)
        self.assertEqual(432432432.0, commit.commit_time)
        self.assertEqual(432432432.0, commit.author_time)
        self.assertEqual(3600, commit.commit_timezone)
        self.assertEqual(3600, commit.author_timezone)
        self.assertEqual(commit, self.repo[b"refs/heads/foo"])

    def test_commit_handler_markers(self):
        from fastimport import commands
        [c1, c2, c3] = build_commit_graph(self.repo.object_store,
                                          [[1], [2], [3]])
        self.processor.markers[b'10'] = c1.id
        self.processor.markers[b'42'] = c2.id
        self.processor.markers[b'98'] = c3.id
        cmd = commands.CommitCommand(
                b"refs/heads/foo",  b"mrkr",
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                b"FOO", b':10', [b':42', b':98'], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(c1.id, commit.parents[0])
        self.assertEqual(c2.id, commit.parents[1])
        self.assertEqual(c3.id, commit.parents[2])

    def test_import_stream(self):
        markers = self.processor.import_stream(BytesIO(b"""blob
mark :1
data 11
text for a

commit refs/heads/master
mark :2
committer Joe Foo <*****@*****.**> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a

"""))
        self.assertEqual(2, len(markers))
        self.assertTrue(isinstance(self.repo[markers[b"1"]], Blob))
        self.assertTrue(isinstance(self.repo[markers[b"2"]], Commit))

    def test_file_add(self):
        from fastimport import commands
        cmd = commands.BlobCommand(b"23", b"data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
                b"refs/heads/foo", b"mrkr",
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                b"FOO", None, [],
                [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual([
            (b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172')],
            self.repo[commit.tree].items())

    def simple_commit(self):
        from fastimport import commands
        cmd = commands.BlobCommand(b"23", b"data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
                b"refs/heads/foo", b"mrkr",
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                b"FOO", None, [],
                [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        return commit

    def make_file_commit(self, file_cmds):
        """Create a trivial commit with the specified file commands.

        :param file_cmds: File commands to run.
        :return: The created commit object
        """
        from fastimport import commands
        cmd = commands.CommitCommand(
                b"refs/heads/foo", b"mrkr",
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
                b"FOO", None, [], file_cmds)
        self.processor.commit_handler(cmd)
        return self.repo[self.processor.last_commit]

    def test_file_copy(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
                [commands.FileCopyCommand(b"path", b"new_path")])
        self.assertEqual([
                (b'new_path', 0o100644,
                 b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
                (b'path', 0o100644,
                 b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
                ], self.repo[commit.tree].items())

    def test_file_move(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
                [commands.FileRenameCommand(b"path", b"new_path")])
        self.assertEqual([
                (b'new_path', 0o100644,
                 b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
                ], self.repo[commit.tree].items())

    def test_file_delete(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteCommand(b"path")])
        self.assertEqual([], self.repo[commit.tree].items())

    def test_file_deleteall(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteAllCommand()])
        self.assertEqual([], self.repo[commit.tree].items())