17
17
"""Tests for GitShaMap."""
19
from dulwich.objects import (
28
from bzrlib.inventory import (
34
from bzrlib.revision import (
38
21
from bzrlib.tests import (
41
24
UnavailableFeature,
43
from bzrlib.transport import (
47
from bzrlib.plugins.git.cache import (
27
from bzrlib.plugins.git.shamap import (
55
33
class TestGitShaMap:
57
def _get_test_commit(self):
59
c.committer = "Jelmer <jelmer@samba.org>"
62
c.author = "Jelmer <jelmer@samba.org>"
65
c.message = "Teh foo bar"
66
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
69
35
def test_commit(self):
70
36
self.map.start_write_group()
71
updater = self.cache.get_updater(Revision("myrevid"))
72
c = self._get_test_commit()
73
updater.add_object(c, {
74
"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
37
self.map.add_entry("5686645d49063c73d35436192dfc9a160c672301",
38
"commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"))
77
39
self.map.commit_write_group()
79
("commit", ("myrevid",
80
"cc9462f7f8263ef5adfbeff2fb936bb36b504cba",
81
{"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
83
self.map.lookup_git_sha(c.id))
84
self.assertEquals(c.id, self.map.lookup_commit("myrevid"))
41
("commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba")),
42
self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
86
44
def test_lookup_notfound(self):
87
45
self.assertRaises(KeyError,
88
46
self.map.lookup_git_sha, "5686645d49063c73d35436192dfc9a160c672301")
90
48
def test_blob(self):
49
thesha = "5686645d49063c73d35436192dfc9a160c672301"
91
50
self.map.start_write_group()
92
updater = self.cache.get_updater(Revision("myrevid"))
93
updater.add_object(self._get_test_commit(), { "testament3-sha1": "Test" }, None)
96
ie = InventoryFile("myfileid", "somename", ROOT_ID)
97
ie.revision = "myrevid"
98
updater.add_object(b, ie, None)
51
self.map.add_entry(thesha, "blob", ("myfileid", "myrevid"))
100
52
self.map.commit_write_group()
101
53
self.assertEquals(
102
54
("blob", ("myfileid", "myrevid")),
103
self.map.lookup_git_sha(b.id))
104
self.assertEquals(b.id,
105
self.map.lookup_blob_id("myfileid", "myrevid"))
55
self.map.lookup_git_sha(thesha))
56
self.assertEquals(thesha, self.map.lookup_blob("myfileid", "myrevid"))
107
58
def test_tree(self):
59
thesha = "5686645d49063c73d35436192dfc9a160c672301"
108
60
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(stat.S_IFREG, "somename", Blob().id)
114
ie = InventoryDirectory("fileid", "myname", ROOT_ID)
115
ie.revision = "irrelevant"
116
updater.add_object(t, ie, "")
61
self.map.add_entry(thesha,
62
"tree", ("somepath", "myrevid"))
118
63
self.map.commit_write_group()
119
self.assertEquals(("tree", ("fileid", "myrevid")),
120
self.map.lookup_git_sha(t.id))
121
# It's possible for a backend to not implement lookup_tree
123
self.assertEquals(t.id,
124
self.map.lookup_tree_id("fileid", "myrevid"))
125
except NotImplementedError:
65
("tree", ("somepath", "myrevid")),
66
self.map.lookup_git_sha(thesha))
67
self.assertEquals(thesha, self.map.lookup_tree("somepath", "myrevid"))
128
69
def test_revids(self):
129
70
self.map.start_write_group()
130
updater = self.cache.get_updater(Revision("myrevid"))
131
c = self._get_test_commit()
132
updater.add_object(c, {"testament3-sha1": "mtestament"}, None)
71
self.map.add_entry("5686645d49063c73d35436192dfc9a160c672301",
72
"commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"))
134
73
self.map.commit_write_group()
135
74
self.assertEquals(["myrevid"], list(self.map.revids()))
137
def test_missing_revisions(self):
138
self.map.start_write_group()
139
updater = self.cache.get_updater(Revision("myrevid"))
140
c = self._get_test_commit()
141
updater.add_object(c, {"testament3-sha1": "testament"}, None)
143
self.map.commit_write_group()
144
self.assertEquals(set(["lala", "bla"]),
145
set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
148
77
class DictGitShaMapTests(TestCase,TestGitShaMap):
151
80
TestCase.setUp(self)
152
self.cache = DictBzrGitCache()
153
self.map = self.cache.idmap
156
class SqliteGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
81
self.map = DictGitShaMap()
84
class SqliteGitShaMapTests(TestCase,TestGitShaMap):
159
TestCaseInTempDir.setUp(self)
160
self.cache = SqliteBzrGitCache(os.path.join(self.test_dir, 'foo.db'))
161
self.map = self.cache.idmap
88
self.map = SqliteGitShaMap()
164
91
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):