1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for GitShaMap."""
19
from dulwich.objects import (
28
from .... import osutils
30
from ....bzr.inventory import (
36
from ....revision import (
40
from ....tests import (
45
from ....transport import (
59
def _get_test_commit(self):
61
c.committer = "Jelmer <jelmer@samba.org>"
64
c.author = "Jelmer <jelmer@samba.org>"
67
c.message = "Teh foo bar"
68
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
71
def test_commit(self):
72
self.map.start_write_group()
73
updater = self.cache.get_updater(Revision("myrevid"))
74
c = self._get_test_commit()
75
updater.add_object(c, {
76
"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
79
self.map.commit_write_group()
81
[("commit", ("myrevid",
82
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba",
83
{"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
85
list(self.map.lookup_git_sha(c.id)))
86
self.assertEquals(c.id, self.map.lookup_commit("myrevid"))
88
def test_lookup_notfound(self):
89
self.assertRaises(KeyError, list,
90
self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
93
self.map.start_write_group()
94
updater = self.cache.get_updater(Revision("myrevid"))
95
updater.add_object(self._get_test_commit(), { "testament3-sha1": "Test" }, None)
98
updater.add_object(b, ("myfileid", "myrevid"), None)
100
self.map.commit_write_group()
102
[("blob", ("myfileid", "myrevid"))],
103
list(self.map.lookup_git_sha(b.id)))
104
self.assertEquals(b.id,
105
self.map.lookup_blob_id("myfileid", "myrevid"))
108
self.map.start_write_group()
109
updater = self.cache.get_updater(Revision("myrevid"))
110
updater.add_object(self._get_test_commit(), {
111
"testament3-sha1": "mytestamentsha" }, None)
113
t.add("somename", stat.S_IFREG, Blob().id)
114
updater.add_object(t, ("fileid", ), "")
116
self.map.commit_write_group()
117
self.assertEquals([("tree", ("fileid", "myrevid"))],
118
list(self.map.lookup_git_sha(t.id)))
119
# It's possible for a backend to not implement lookup_tree
121
self.assertEquals(t.id,
122
self.map.lookup_tree_id("fileid", "myrevid"))
123
except NotImplementedError:
126
def test_revids(self):
127
self.map.start_write_group()
128
updater = self.cache.get_updater(Revision("myrevid"))
129
c = self._get_test_commit()
130
updater.add_object(c, {"testament3-sha1": "mtestament"}, None)
132
self.map.commit_write_group()
133
self.assertEquals(["myrevid"], list(self.map.revids()))
135
def test_missing_revisions(self):
136
self.map.start_write_group()
137
updater = self.cache.get_updater(Revision("myrevid"))
138
c = self._get_test_commit()
139
updater.add_object(c, {"testament3-sha1": "testament"}, None)
141
self.map.commit_write_group()
142
self.assertEquals(set(["lala", "bla"]),
143
set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
146
class DictGitShaMapTests(TestCase,TestGitShaMap):
150
self.cache = DictBzrGitCache()
151
self.map = self.cache.idmap
154
class SqliteGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
157
TestCaseInTempDir.setUp(self)
158
self.cache = SqliteBzrGitCache(os.path.join(self.test_dir, 'foo.db'))
159
self.map = self.cache.idmap
162
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
165
TestCaseInTempDir.setUp(self)
167
self.cache = TdbBzrGitCache(
168
os.path.join(self.test_dir, 'foo.tdb').encode(osutils._fs_enc))
170
raise UnavailableFeature("Missing tdb")
171
self.map = self.cache.idmap
174
class IndexGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
177
TestCaseInTempDir.setUp(self)
178
transport = get_transport(self.test_dir)
179
IndexGitCacheFormat().initialize(transport)
180
self.cache = IndexBzrGitCache(transport)
181
self.map = self.cache.idmap