bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.196
by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker. |
1 |
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
|
0.200.264
by Jelmer Vernooij
Add more tests. |
17 |
from dulwich.objects import ( |
18 |
Blob, |
|
|
0.200.265
by Jelmer Vernooij
Add more tests. |
19 |
Tree, |
|
0.200.264
by Jelmer Vernooij
Add more tests. |
20 |
)
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
21 |
import os |
22 |
||
|
0.200.264
by Jelmer Vernooij
Add more tests. |
23 |
from bzrlib import ( |
24 |
knit, |
|
|
0.200.265
by Jelmer Vernooij
Add more tests. |
25 |
osutils, |
|
0.200.264
by Jelmer Vernooij
Add more tests. |
26 |
versionedfile, |
27 |
)
|
|
28 |
from bzrlib.bzrdir import ( |
|
29 |
BzrDir, |
|
30 |
)
|
|
31 |
from bzrlib.inventory import ( |
|
32 |
Inventory, |
|
33 |
)
|
|
34 |
from bzrlib.repository import ( |
|
35 |
Repository, |
|
36 |
)
|
|
37 |
from bzrlib.tests import ( |
|
38 |
TestCaseWithTransport, |
|
39 |
)
|
|
40 |
from bzrlib.transport import ( |
|
41 |
get_transport, |
|
42 |
)
|
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
43 |
|
44 |
from bzrlib.plugins.git import ( |
|
45 |
get_rich_root_format, |
|
46 |
)
|
|
|
0.200.264
by Jelmer Vernooij
Add more tests. |
47 |
from bzrlib.plugins.git.fetch import ( |
48 |
BzrFetchGraphWalker, |
|
49 |
import_git_blob, |
|
50 |
import_git_tree, |
|
51 |
)
|
|
52 |
from bzrlib.plugins.git.mapping import ( |
|
53 |
BzrGitMappingv1, |
|
54 |
default_mapping, |
|
55 |
)
|
|
56 |
from bzrlib.plugins.git.shamap import ( |
|
57 |
DictGitShaMap, |
|
58 |
)
|
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
59 |
from bzrlib.plugins.git.tests import ( |
60 |
GitBranchBuilder, |
|
61 |
run_git, |
|
62 |
)
|
|
|
0.200.196
by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker. |
63 |
|
64 |
||
65 |
class FetchGraphWalkerTests(TestCaseWithTransport): |
|
66 |
||
67 |
def setUp(self): |
|
68 |
TestCaseWithTransport.setUp(self) |
|
69 |
self.mapping = default_mapping |
|
70 |
||
71 |
def test_empty(self): |
|
72 |
tree = self.make_branch_and_tree("wt") |
|
73 |
graphwalker = BzrFetchGraphWalker(tree.branch.repository, self.mapping) |
|
74 |
self.assertEquals(None, graphwalker.next()) |
|
75 |
||
76 |
||
|
0.200.269
by Jelmer Vernooij
Prepare for testing remote repos. |
77 |
class RepositoryFetchTests: |
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
78 |
|
79 |
def make_git_repo(self, path): |
|
80 |
os.mkdir(path) |
|
81 |
os.chdir(path) |
|
82 |
run_git("init") |
|
83 |
os.chdir("..") |
|
84 |
||
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
85 |
def clone_git_repo(self, from_url, to_url, revision_id=None): |
86 |
oldrepos = self.open_git_repo(from_url) |
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
87 |
dir = BzrDir.create(to_url, get_rich_root_format()) |
88 |
newrepos = dir.create_repository() |
|
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
89 |
oldrepos.copy_content_into(newrepos, revision_id=revision_id) |
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
90 |
return newrepos |
91 |
||
92 |
def test_empty(self): |
|
93 |
self.make_git_repo("d") |
|
94 |
newrepos = self.clone_git_repo("d", "f") |
|
95 |
self.assertEquals([], newrepos.all_revision_ids()) |
|
96 |
||
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
97 |
def make_onerev_branch(self): |
98 |
self.make_git_repo("d") |
|
99 |
os.chdir("d") |
|
100 |
bb = GitBranchBuilder() |
|
101 |
bb.set_file("foobar", "foo\nbar\n", False) |
|
102 |
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg") |
|
103 |
gitsha = bb.finish()[mark] |
|
104 |
os.chdir("..") |
|
105 |
return "d", gitsha |
|
106 |
||
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
107 |
def test_single_rev(self): |
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
108 |
path, gitsha = self.make_onerev_branch() |
109 |
oldrepo = self.open_git_repo(path) |
|
110 |
newrepo = self.clone_git_repo(path, "f") |
|
|
0.228.1
by Jelmer Vernooij
Add basic tests for local fetch. |
111 |
self.assertEquals([oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)], newrepo.all_revision_ids()) |
112 |
||
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
113 |
def test_single_rev_specific(self): |
114 |
path, gitsha = self.make_onerev_branch() |
|
115 |
oldrepo = self.open_git_repo(path) |
|
116 |
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) |
|
117 |
newrepo = self.clone_git_repo(path, "f", revision_id=revid) |
|
118 |
self.assertEquals([revid], newrepo.all_revision_ids()) |
|
119 |
||
120 |
def test_incremental(self): |
|
121 |
self.make_git_repo("d") |
|
122 |
os.chdir("d") |
|
123 |
bb = GitBranchBuilder() |
|
124 |
bb.set_file("foobar", "foo\nbar\n", False) |
|
125 |
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg") |
|
126 |
bb.set_file("foobar", "fooll\nbar\n", False) |
|
127 |
mark2 = bb.commit("Somebody <somebody@someorg.org>", "nextmsg") |
|
128 |
marks = bb.finish() |
|
129 |
gitsha1 = marks[mark1] |
|
130 |
gitsha2 = marks[mark2] |
|
131 |
os.chdir("..") |
|
132 |
oldrepo = self.open_git_repo("d") |
|
133 |
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1) |
|
134 |
newrepo = self.clone_git_repo("d", "f", revision_id=revid1) |
|
135 |
self.assertEquals([revid1], newrepo.all_revision_ids()) |
|
136 |
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2) |
|
137 |
newrepo.fetch(oldrepo, revision_id=revid2) |
|
|
0.200.269
by Jelmer Vernooij
Prepare for testing remote repos. |
138 |
self.assertEquals(set([revid1, revid2]), set(newrepo.all_revision_ids())) |
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
139 |
|
|
0.228.2
by Jelmer Vernooij
Add test for fetching executables. |
140 |
def test_executable(self): |
141 |
self.make_git_repo("d") |
|
142 |
os.chdir("d") |
|
143 |
bb = GitBranchBuilder() |
|
144 |
bb.set_file("foobar", "foo\nbar\n", True) |
|
145 |
bb.set_file("notexec", "foo\nbar\n", False) |
|
146 |
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg") |
|
147 |
gitsha = bb.finish()[mark] |
|
148 |
os.chdir("..") |
|
|
0.200.268
by Jelmer Vernooij
Add more fetch tests. |
149 |
oldrepo = self.open_git_repo("d") |
|
0.228.2
by Jelmer Vernooij
Add test for fetching executables. |
150 |
newrepo = self.clone_git_repo("d", "f") |
151 |
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) |
|
152 |
tree = newrepo.revision_tree(revid) |
|
153 |
self.assertTrue(tree.has_filename("foobar")) |
|
154 |
self.assertEquals(True, tree.inventory[tree.path2id("foobar")].executable) |
|
155 |
self.assertTrue(tree.has_filename("notexec")) |
|
156 |
self.assertEquals(False, tree.inventory[tree.path2id("notexec")].executable) |
|
|
0.200.264
by Jelmer Vernooij
Add more tests. |
157 |
|
158 |
||
|
0.200.269
by Jelmer Vernooij
Prepare for testing remote repos. |
159 |
class LocalRepositoryFetchTests(RepositoryFetchTests, TestCaseWithTransport): |
160 |
||
161 |
def open_git_repo(self, path): |
|
162 |
return Repository.open(path) |
|
163 |
||
164 |
||
|
0.200.264
by Jelmer Vernooij
Add more tests. |
165 |
class ImportObjects(TestCaseWithTransport): |
166 |
||
167 |
def setUp(self): |
|
168 |
super(ImportObjects, self).setUp() |
|
169 |
self._map = DictGitShaMap() |
|
|
0.200.265
by Jelmer Vernooij
Add more tests. |
170 |
self._mapping = BzrGitMappingv1() |
|
0.200.264
by Jelmer Vernooij
Add more tests. |
171 |
factory = knit.make_file_factory(True, versionedfile.PrefixMapper()) |
172 |
self._texts = factory(self.get_transport('texts')) |
|
173 |
||
174 |
def test_import_blob_simple(self): |
|
175 |
blob = Blob.from_string("bar") |
|
176 |
inv = Inventory() |
|
177 |
inv.revision_id = "somerevid" |
|
|
0.200.265
by Jelmer Vernooij
Add more tests. |
178 |
import_git_blob(self._texts, self._mapping, "bla", blob, |
|
0.200.264
by Jelmer Vernooij
Add more tests. |
179 |
inv, [], self._map, False) |
180 |
self.assertEquals(set([('bla', 'somerevid')]), self._texts.keys()) |
|
|
0.200.265
by Jelmer Vernooij
Add more tests. |
181 |
self.assertEquals(self._texts.get_record_stream([('bla', 'somerevid')], |
182 |
"unordered", True).next().get_bytes_as("fulltext"), "bar") |
|
183 |
self.assertEquals(False, inv["bla"].executable) |
|
184 |
self.assertEquals("file", inv["bla"].kind) |
|
185 |
self.assertEquals("somerevid", inv["bla"].revision) |
|
186 |
self.assertEquals(osutils.sha_strings(["bar"]), inv["bla"].text_sha1) |
|
187 |
||
188 |
def test_import_tree_empty_root(self): |
|
189 |
inv = Inventory() |
|
190 |
inv.revision_id = "somerevid" |
|
191 |
tree = Tree() |
|
192 |
tree.serialize() |
|
193 |
import_git_tree(self._texts, self._mapping, "", tree, inv, [], |
|
|
0.200.267
by Jelmer Vernooij
Add more tests for fetch code. |
194 |
self._map, {}.__getitem__) |
|
0.200.265
by Jelmer Vernooij
Add more tests. |
195 |
self.assertEquals(set([("TREE_ROOT", 'somerevid')]), self._texts.keys()) |
196 |
self.assertEquals(False, inv["TREE_ROOT"].executable) |
|
197 |
self.assertEquals("directory", inv["TREE_ROOT"].kind) |
|
198 |
self.assertEquals({}, inv["TREE_ROOT"].children) |
|
199 |
self.assertEquals("somerevid", inv["TREE_ROOT"].revision) |
|
200 |
self.assertEquals(None, inv["TREE_ROOT"].text_sha1) |
|
201 |
||
202 |
def test_import_tree_empty(self): |
|
203 |
inv = Inventory() |
|
204 |
inv.revision_id = "somerevid" |
|
205 |
tree = Tree() |
|
206 |
tree.serialize() |
|
207 |
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [], |
|
|
0.200.267
by Jelmer Vernooij
Add more tests for fetch code. |
208 |
self._map, {}.__getitem__) |
|
0.200.265
by Jelmer Vernooij
Add more tests. |
209 |
self.assertEquals(set([("bla", 'somerevid')]), self._texts.keys()) |
210 |
self.assertEquals("directory", inv["bla"].kind) |
|
211 |
self.assertEquals(False, inv["bla"].executable) |
|
212 |
self.assertEquals({}, inv["bla"].children) |
|
213 |
self.assertEquals("somerevid", inv["bla"].revision) |
|
214 |
self.assertEquals(None, inv["bla"].text_sha1) |
|
|
0.200.267
by Jelmer Vernooij
Add more tests for fetch code. |
215 |
|
216 |
def test_import_tree_with_file(self): |
|
217 |
inv = Inventory() |
|
218 |
inv.revision_id = "somerevid" |
|
219 |
blob = Blob.from_string("bar1") |
|
220 |
tree = Tree() |
|
221 |
tree.add(0100600, "foo", blob.id) |
|
222 |
tree.serialize() |
|
223 |
objects = { blob.id: blob, tree.id: tree } |
|
224 |
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [], |
|
225 |
self._map, objects.__getitem__) |
|
226 |
self.assertEquals(["foo"], inv["bla"].children.keys()) |
|
227 |
self.assertEquals(set(["bla", "bla/foo"]), |
|
228 |
set([ie.file_id for (path, ie) in inv.entries()])) |
|
229 |
ie = inv["bla/foo"] |
|
230 |
self.assertEquals("file", ie.kind) |
|
231 |
self.assertEquals("bla/foo", ie.file_id) |
|
232 |
self.assertEquals("somerevid", ie.revision) |
|
233 |
self.assertEquals(osutils.sha_strings(["bar1"]), ie.text_sha1) |
|
234 |
self.assertEquals(False, ie.executable) |
|
235 |
||
236 |
def test_import_tree_with_file_exe(self): |
|
237 |
inv = Inventory() |
|
238 |
inv.revision_id = "somerevid" |
|
239 |
blob = Blob.from_string("bar") |
|
240 |
tree = Tree() |
|
241 |
tree.add(0100755, "foo", blob.id) |
|
242 |
tree.serialize() |
|
243 |
objects = { blob.id: blob, tree.id: tree } |
|
244 |
import_git_tree(self._texts, self._mapping, "bla", tree, inv, [], |
|
245 |
self._map, objects.__getitem__) |
|
246 |
self.assertEquals(["foo"], inv["bla"].children.keys()) |
|
247 |
ie = inv["bla/foo"] |
|
248 |
self.assertEquals("file", ie.kind) |
|
249 |
self.assertEquals(True, ie.executable) |