/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Tests for GitShaMap."""

from dulwich.objects import (
    Blob,
    Commit,
    Tree,
    )

import os
import stat

from ...revision import (
    Revision,
    )

from ...tests import (
    TestCase,
    TestCaseInTempDir,
    UnavailableFeature,
    )
from ...transport import (
    get_transport,
    )

from ..cache import (
    DictBzrGitCache,
    IndexBzrGitCache,
    IndexGitCacheFormat,
    SqliteBzrGitCache,
    TdbBzrGitCache,
    )


class TestGitShaMap:

    def _get_test_commit(self):
        c = Commit()
        c.committer = b"Jelmer <jelmer@samba.org>"
        c.commit_time = 0
        c.commit_timezone = 0
        c.author = b"Jelmer <jelmer@samba.org>"
        c.author_time = 0
        c.author_timezone = 0
        c.message = b"Teh foo bar"
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
        return c

    def test_commit(self):
        self.map.start_write_group()
        updater = self.cache.get_updater(Revision(b"myrevid"))
        c = self._get_test_commit()
        updater.add_object(c, {
            "testament3-sha1": b"cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
            None)
        updater.finish()
        self.map.commit_write_group()
        self.assertEqual(
            [("commit", (b"myrevid",
                         b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba",
                         {"testament3-sha1": b"cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
                         ))],
            list(self.map.lookup_git_sha(c.id)))
        self.assertEqual(c.id, self.map.lookup_commit(b"myrevid"))

    def test_lookup_notfound(self):
        self.assertRaises(KeyError, list,
                          self.map.lookup_git_sha(b"5686645d49063c73d35436192dfc9a160c672301"))

    def test_blob(self):
        self.map.start_write_group()
        updater = self.cache.get_updater(Revision(b"myrevid"))
        updater.add_object(self._get_test_commit(), {
                           "testament3-sha1": b"Test"}, None)
        b = Blob()
        b.data = b"TEH BLOB"
        updater.add_object(b, (b"myfileid", b"myrevid"), None)
        updater.finish()
        self.map.commit_write_group()
        self.assertEqual(
            [("blob", (b"myfileid", b"myrevid"))],
            list(self.map.lookup_git_sha(b.id)))
        self.assertEqual(b.id,
                         self.map.lookup_blob_id(b"myfileid", b"myrevid"))

    def test_tree(self):
        self.map.start_write_group()
        updater = self.cache.get_updater(Revision(b"somerevid"))
        updater.add_object(self._get_test_commit(), {
            "testament3-sha1": b"mytestamentsha"}, None)
        t = Tree()
        t.add(b"somename", stat.S_IFREG, Blob().id)
        updater.add_object(t, (b"fileid", b"myrevid"), b"")
        updater.finish()
        self.map.commit_write_group()
        self.assertEqual([("tree", (b"fileid", b"myrevid"))],
                         list(self.map.lookup_git_sha(t.id)))
        # It's possible for a backend to not implement lookup_tree
        try:
            self.assertEqual(t.id,
                             self.map.lookup_tree_id(b"fileid", b"myrevid"))
        except NotImplementedError:
            pass

    def test_revids(self):
        self.map.start_write_group()
        updater = self.cache.get_updater(Revision(b"myrevid"))
        c = self._get_test_commit()
        updater.add_object(c, {"testament3-sha1": b"mtestament"}, None)
        updater.finish()
        self.map.commit_write_group()
        self.assertEqual([b"myrevid"], list(self.map.revids()))

    def test_missing_revisions(self):
        self.map.start_write_group()
        updater = self.cache.get_updater(Revision(b"myrevid"))
        c = self._get_test_commit()
        updater.add_object(c, {"testament3-sha1": b"testament"}, None)
        updater.finish()
        self.map.commit_write_group()
        self.assertEqual(set([b"lala", b"bla"]),
                         set(self.map.missing_revisions([b"myrevid", b"lala", b"bla"])))


class DictGitShaMapTests(TestCase, TestGitShaMap):

    def setUp(self):
        TestCase.setUp(self)
        self.cache = DictBzrGitCache()
        self.map = self.cache.idmap


class SqliteGitShaMapTests(TestCaseInTempDir, TestGitShaMap):

    def setUp(self):
        TestCaseInTempDir.setUp(self)
        self.cache = SqliteBzrGitCache(os.path.join(self.test_dir, 'foo.db'))
        self.map = self.cache.idmap


class TdbGitShaMapTests(TestCaseInTempDir, TestGitShaMap):

    def setUp(self):
        TestCaseInTempDir.setUp(self)
        try:
            self.cache = TdbBzrGitCache(os.path.join(self.test_dir, 'foo.tdb'))
        except ImportError:
            raise UnavailableFeature("Missing tdb")
        self.map = self.cache.idmap


class IndexGitShaMapTests(TestCaseInTempDir, TestGitShaMap):

    def setUp(self):
        TestCaseInTempDir.setUp(self)
        transport = get_transport(self.test_dir)
        IndexGitCacheFormat().initialize(transport)
        self.cache = IndexBzrGitCache(transport)
        self.map = self.cache.idmap