Ejemplo n.º 1
0
    def test_manifest(self):
        m = Manifest()
        m.add('foo', '49d8cbb15ce257920447006b46978b7af980a979')

        with self.assertRaises(AssertionError):
            m.add('bar', 'a324b8bf63f7d56de9d36f8747e3b68a72a4d968')

        m.add('hoge', '618faf0766206b33a8e424f93966ff5d99fd8828', 'x')

        self.assertEqual(m.items, [
            'foo\x0049d8cbb15ce257920447006b46978b7af980a979',
            'hoge\x00618faf0766206b33a8e424f93966ff5d99fd8828x',
        ])

        self.assertEqual(
            m.raw_data,
            'foo\x0049d8cbb15ce257920447006b46978b7af980a979\n'
            'hoge\x00618faf0766206b33a8e424f93966ff5d99fd8828x\n'
        )

        m2 = Manifest()
        m2.add('foo', '49d8cbb15ce257920447006b46978b7af980a979')
        m2.add('fuga', 'a7b3deabf88ddf313b21064bd29051cfbb284b7c')
        m2.add('hoge', '618faf0766206b33a8e424f93966ff5d99fd8828', 'x')

        chunk = m2.to_chunk(RawRevChunk02, m)
        m3 = Manifest.from_chunk(chunk, m)
        self.assertEquals(m2.items, m3.items)

        chunk = m.to_chunk(RawRevChunk02, m2)
        m3 = Manifest.from_chunk(chunk, m2)
        self.assertEquals(m.items, m3.items)

        m2 = Manifest()
        m2.add('fuga', 'a7b3deabf88ddf313b21064bd29051cfbb284b7c')
        m2.add('hoge', '618faf0766206b33a8e424f93966ff5d99fd8828', 'x')

        chunk = m2.to_chunk(RawRevChunk02, m)
        m3 = Manifest.from_chunk(chunk, m)
        self.assertEquals(m2.items, m3.items)

        m = Manifest()
        m.raw_data = (
            'foo\x0049d8cbb15ce257920447006b46978b7af980a979\n'
            'hoge\x00618faf0766206b33a8e424f93966ff5d99fd8828x\n'
        )

        self.assertEqual(m.items, [
            'foo\x0049d8cbb15ce257920447006b46978b7af980a979',
            'hoge\x00618faf0766206b33a8e424f93966ff5d99fd8828x',
        ])

        m2 = Manifest()
        for i in m:
            m2.add(i)
        self.assertEqual(m.raw_data, m2.raw_data)
        self.assertEqual(m.items, m2.items)
Ejemplo n.º 2
0
    def test_store_manifest(self):
        m = Manifest()
        m.add(b'foo', b'1' * 40)
        m.add(b'hoge', b'2' * 40)
        m.node = m.sha1

        chunk = m.to_chunk(self.RevChunk)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m))

        m2 = Manifest()
        m2.parent1 = m.node
        m2.items.append(m.items[0])
        m2.add(b'fuga', b'3' * 40)
        m2.items.append(m.items[1])
        m2.node = m2.sha1

        chunk = m2.to_chunk(self.RevChunk, m)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m2))

        m3 = Manifest()
        m3.parent1 = m.node
        m3.items.append(m.items[0])
        m3.add(b'fuga/bar/foo', b'3' * 40)
        m3.add(b'fuga/bar/qux', b'4' * 40)
        m3.add(b'fuga/foo', b'5' * 40, b'x')
        m3.add(b'fuga/fuga/bar', b'6' * 40)
        m3.add(b'fuga/fuga/baz', b'7' * 40, b'l')
        m3.add(b'fuga/fuga/qux', b'8' * 40)
        m3.add(b'hoge', b'9' * 40)
        m3.node = m3.sha1

        if self.RevChunk == RawRevChunk01:
            delta_node = m2
        else:
            delta_node = m
        chunk = m3.to_chunk(self.RevChunk, delta_node)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m3))

        m4 = Manifest()
        m4.parents = (m2.node, m3.node)
        for item in m3.items:
            m4.items.append(item)
        m4.node = m4.sha1

        if self.RevChunk == RawRevChunk01:
            delta_node = m3
        else:
            delta_node = m2
        chunk = m4.to_chunk(self.RevChunk, delta_node)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m4))

        m5 = Manifest()
        m5.parent1 = m4.node
        for item in chain(m4.items[:2], m4.items[5:]):
            m5.items.append(item)
        m5.node = m5.sha1

        chunk = m5.to_chunk(self.RevChunk, m4)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m5))

        m6 = Manifest()
        m6.parent1 = m5.node
        for item in m4.items:
            m6.items.append(item)
        m6.node = m6.sha1
        self.assertEqual(m4.raw_data, m6.raw_data)

        chunk = m6.to_chunk(self.RevChunk, m5)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m6))

        m7 = Manifest()
        for item in m3.items:
            m7.items.append(item)
        m7.node = m7.sha1

        chunk = m7.to_chunk(self.RevChunk)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m7))

        m8 = Manifest()
        for item in chain(m3.items[:3], m3.items[7:]):
            m8.items.append(item)
        m8.node = m8.sha1

        chunk = m8.to_chunk(self.RevChunk, m7)
        GitHgHelper.store(b'manifest', chunk)

        git_m = GitHgHelper.hg2git(chunk.node)
        self.assertEqual(GitCommit(git_m).tree, self.manifest_tree(m8))
Ejemplo n.º 3
0
    def test_store_changeset(self):
        files = {}
        f = File()
        f.content = b'foo\n'
        f.node = f.sha1

        chunk = f.to_chunk(self.RevChunk)
        GitHgHelper.store(b'file', chunk)
        files[f.node] = GitHgHelper.hg2git(chunk.node)

        f2 = File()
        f2.content = b'bar\n'
        f2.node = f2.sha1

        chunk = f2.to_chunk(self.RevChunk)
        GitHgHelper.store(b'file', chunk)
        files[f2.node] = GitHgHelper.hg2git(chunk.node)

        m = Manifest()
        m.add(b'bar', f.node)
        m.add(b'foo/.bar', f.node)
        m.add(b'foo/.foo', f.node)
        m.add(b'foo/bar/baz', f.node)
        m.add(b'foo/bar/foo', f.node)
        m.add(b'foo/bar/qux', f.node)
        m.add(b'foo/foo', f.node)
        m.add(b'foo/hoge', f.node)
        m.add(b'foo/qux', f.node)
        m.add(b'qux', f.node)
        m.node = m.sha1

        chunk = m.to_chunk(self.RevChunk)
        GitHgHelper.store(b'manifest', chunk)

        store = GitHgStore()

        c = Changeset()
        c.manifest = m.node
        c.author = b'Cinnabar test <cinnabar@test>'
        c.timestamp = b'0'
        c.utcoffset = b'0'
        c.files = [i.path for i in m]
        c.body = b'Test commit'
        c.node = c.sha1

        store.store_changeset(c)
        c_gen = store.changeset(c.node)
        self.assertEqual(c.raw_data, c_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c.node))
        self.assertEqual(commit.body, c.body)
        ct = self.commit_tree(m, files)
        self.assertEqual(commit.tree, ct)

        # Weird case as seen in the GNU octave repo.
        # The bar subdirectory is supposed to be transposed to the same
        # content as the git tree for the manifest above.
        m2 = Manifest()
        m2.add(b'bar/bar', f.node)
        m2.add(b'bar/foo/.foo', f.node)
        m2.add(b'bar/foo//.bar', f.node)
        m2.add(b'bar/foo//.foo', f2.node)
        m2.add(b'bar/foo//bar/baz', f2.node)
        m2.add(b'bar/foo//bar/foo', f.node)
        m2.add(b'bar/foo//hoge', f.node)
        m2.add(b'bar/foo/bar/baz', f.node)
        m2.add(b'bar/foo/bar/qux', f.node)
        m2.add(b'bar/foo/foo', f.node)
        m2.add(b'bar/foo/qux', f.node)
        m2.add(b'bar/qux', f.node)
        m2.node = m2.sha1

        chunk = m2.to_chunk(self.RevChunk, m)
        GitHgHelper.store(b'manifest', chunk)

        c2 = Changeset()
        c2.parent1 = c.node
        c2.manifest = m2.node
        c2.author = b'Cinnabar test <cinnabar@test>'
        c2.timestamp = b'0'
        c2.utcoffset = b'0'
        c2.files = [i.path for i in m2]
        c2.body = b'Test commit'
        c2.node = c2.sha1

        store.store_changeset(c2)
        c2_gen = store.changeset(c2.node)
        self.assertEqual(c2.raw_data, c2_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c2.node))
        self.assertEqual(commit.body, c2.body)
        self.assertEqual(ct, one(Git.ls_tree(commit.tree, b'bar'))[2])

        # Corner case: empty manifest
        m3 = Manifest()
        m3.node = m3.sha1
        self.assertEqual(b'b80de5d138758541c5f05265ad144ab9fa86d1db', m3.node)

        chunk = m3.to_chunk(self.RevChunk, m2)
        GitHgHelper.store(b'manifest', chunk)
        commit = GitCommit(GitHgHelper.hg2git(m3.node))
        self.assertEqual(EMPTY_TREE, commit.tree)

        c3 = Changeset()
        c3.parent1 = c2.node
        c3.manifest = m3.node
        c3.author = b'Cinnabar test <cinnabar@test>'
        c3.timestamp = b'0'
        c3.utcoffset = b'0'
        c3.body = b'Test commit'
        c3.node = c3.sha1

        store.store_changeset(c3)
        c3_gen = store.changeset(c3.node)
        self.assertEqual(c3.raw_data, c3_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c3.node))
        self.assertEqual(commit.body, c3.body)
        self.assertEqual(EMPTY_TREE, commit.tree)

        # Corner case: null manifest
        c4 = Changeset()
        c4.parent1 = c3.node
        c4.manifest = NULL_NODE_ID
        c4.author = b'Cinnabar test <cinnabar@test>'
        c4.timestamp = b'0'
        c4.utcoffset = b'0'
        c4.body = b'Test commit'
        c4.node = c4.sha1

        store.store_changeset(c4)
        c4_gen = store.changeset(c4.node)
        self.assertEqual(c4.raw_data, c4_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c4.node))
        self.assertEqual(commit.body, c4.body)
        self.assertEqual(EMPTY_TREE, commit.tree)

        # Corner case: identical changeset with a difference that wouldn't
        # appear in the git commit without adjustment (which is: cinnabar adds
        # a nul character to the commit message..
        chunk = c2.to_chunk(RawRevChunk02)
        c5 = Changeset.from_chunk(chunk)
        c5.branch = b'branched'
        c5.node = c5.sha1

        store.store_changeset(c5)
        c5_gen = store.changeset(c5.node)
        self.assertEqual(c5.raw_data, c5_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c5.node))
        self.assertEqual(commit.body, c5.body + b'\0')
        self.assertEqual(ct, one(Git.ls_tree(commit.tree, b'bar'))[2])
Ejemplo n.º 4
0
    def test_store_changeset(self):
        files = {}
        f = File()
        f.content = b'foo\n'
        f.node = f.sha1

        chunk = f.to_chunk(self.RevChunk)
        GitHgHelper.store(b'file', chunk)
        files[f.node] = GitHgHelper.hg2git(chunk.node)

        f2 = File()
        f2.content = b'bar\n'
        f2.node = f2.sha1

        chunk = f2.to_chunk(self.RevChunk)
        GitHgHelper.store(b'file', chunk)
        files[f2.node] = GitHgHelper.hg2git(chunk.node)

        m = Manifest()
        m.add(b'bar', f.node)
        m.add(b'foo/.bar', f.node)
        m.add(b'foo/.foo', f.node)
        m.add(b'foo/bar/baz', f.node)
        m.add(b'foo/bar/foo', f.node)
        m.add(b'foo/bar/qux', f.node)
        m.add(b'foo/foo', f.node)
        m.add(b'foo/hoge', f.node)
        m.add(b'foo/qux', f.node)
        m.add(b'qux', f.node)
        m.node = m.sha1

        chunk = m.to_chunk(self.RevChunk)
        GitHgHelper.store(b'manifest', chunk)

        store = GitHgStore()

        c = Changeset()
        c.manifest = m.node
        c.author = b'Cinnabar test <cinnabar@test>'
        c.timestamp = b'0'
        c.utcoffset = b'0000'
        c.files = [i.path for i in m]
        c.body = b'Test commit'
        c.node = c.sha1

        store.store_changeset(c)
        c_gen = store.changeset(c.node)
        self.assertEqual(c.raw_data, c_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c.node))
        self.assertEqual(commit.body, c.body)
        ct = self.commit_tree(m, files)
        self.assertEqual(commit.tree, ct)

        # Weird case as seen in the GNU octave repo.
        # The bar subdirectory is supposed to be transposed to the same
        # content as the git tree for the manifest above.
        m2 = Manifest()
        m2.add(b'bar/bar', f.node)
        m2.add(b'bar/foo/.foo', f.node)
        m2.add(b'bar/foo//.bar', f.node)
        m2.add(b'bar/foo//.foo', f2.node)
        m2.add(b'bar/foo//bar/baz', f2.node)
        m2.add(b'bar/foo//bar/foo', f.node)
        m2.add(b'bar/foo//hoge', f.node)
        m2.add(b'bar/foo/bar/baz', f.node)
        m2.add(b'bar/foo/bar/qux', f.node)
        m2.add(b'bar/foo/foo', f.node)
        m2.add(b'bar/foo/qux', f.node)
        m2.add(b'bar/qux', f.node)
        m2.node = m2.sha1

        chunk = m2.to_chunk(self.RevChunk, m)
        GitHgHelper.store(b'manifest', chunk)

        c2 = Changeset()
        c2.parent1 = c.node
        c2.manifest = m2.node
        c2.author = b'Cinnabar test <cinnabar@test>'
        c2.timestamp = b'0'
        c2.utcoffset = b'0000'
        c2.files = [i.path for i in m2]
        c2.body = b'Test commit'
        c2.node = c2.sha1

        store.store_changeset(c2)
        c2_gen = store.changeset(c2.node)
        self.assertEqual(c2.raw_data, c2_gen.raw_data)

        commit = GitCommit(GitHgHelper.hg2git(c2.node))
        self.assertEqual(commit.body, c2.body)
        self.assertEqual(ct, one(Git.ls_tree(commit.tree, b'bar'))[2])