/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.51 by Jelmer Vernooij
Fix copyright.
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
2
# -*- encoding: utf-8 -*-
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
3
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
8
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
13
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
18
from bzrlib.inventory import (
19
    InventoryDirectory,
20
    InventoryFile,
21
    )
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
22
from bzrlib.revision import (
23
    Revision,
24
    )
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
25
0.200.264 by Jelmer Vernooij
Add more tests.
26
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
27
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
28
    Commit,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
29
    Tree,
0.200.264 by Jelmer Vernooij
Add more tests.
30
    )
31
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
32
from bzrlib.plugins.git import tests
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
33
from bzrlib.plugins.git.mapping import (
34
    BzrGitMappingv1,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
35
    directory_to_tree,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
36
    escape_file_id,
37
    unescape_file_id,
38
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
39
40
41
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
42
43
    def test_simple_git_to_bzr_revision_id(self):
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
44
        self.assertEqual("git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
45
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
46
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
47
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
48
49
    def test_simple_bzr_to_git_revision_id(self):
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
50
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
51
                         BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
52
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
53
                            "git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
54
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
55
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
56
    def test_is_control_file(self):
57
        mapping = BzrGitMappingv1()
58
        self.assertTrue(mapping.is_control_file(".bzrdummy"))
59
        self.assertTrue(mapping.is_control_file(".bzrfileids"))
60
        self.assertFalse(mapping.is_control_file(".bzrfoo"))
61
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
62
63
class FileidTests(tests.TestCase):
64
65
    def test_escape_space(self):
66
        self.assertEquals("bla_s", escape_file_id("bla "))
67
68
    def test_escape_underscore(self):
69
        self.assertEquals("bla__", escape_file_id("bla_"))
70
71
    def test_escape_underscore_space(self):
72
        self.assertEquals("bla___s", escape_file_id("bla_ "))
73
74
    def test_unescape_underscore(self):
75
        self.assertEquals("bla ", unescape_file_id("bla_s"))
76
77
    def test_unescape_underscore_space(self):
78
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
79
80
81
class TestImportCommit(tests.TestCase):
82
83
    def test_commit(self):
84
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
85
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
86
        c.message = "Some message"
87
        c.committer = "Committer"
88
        c.commit_time = 4
89
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
90
        c.commit_timezone = 60 * 5
91
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
92
        c.author = "Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
93
        mapping = BzrGitMappingv1()
94
        rev = mapping.import_commit(c, mapping.revision_id_foreign_to_bzr)
0.200.264 by Jelmer Vernooij
Add more tests.
95
        self.assertEquals("Some message", rev.message)
96
        self.assertEquals("Committer", rev.committer)
97
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
98
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
99
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
100
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
101
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
102
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
103
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
104
    def test_explicit_encoding(self):
105
        c = Commit()
106
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
107
        c.message = "Some message"
108
        c.committer = "Committer"
109
        c.commit_time = 4
110
        c.author_time = 5
111
        c.commit_timezone = 60 * 5
112
        c.author_timezone = 60 * 3
113
        c.author = u"Authér".encode("iso8859-1")
114
        c.encoding = "iso8859-1"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
115
        mapping = BzrGitMappingv1()
116
        rev = mapping.import_commit(c, mapping.revision_id_foreign_to_bzr)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
117
        self.assertEquals(u"Authér", rev.properties['author'])
118
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
119
        self.assertTrue("git-implicit-encoding" not in rev.properties)
120
121
    def test_implicit_encoding_fallback(self):
122
        c = Commit()
123
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
124
        c.message = "Some message"
125
        c.committer = "Committer"
126
        c.commit_time = 4
127
        c.author_time = 5
128
        c.commit_timezone = 60 * 5
129
        c.author_timezone = 60 * 3
130
        c.author = u"Authér".encode("latin1")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
131
        mapping = BzrGitMappingv1()
132
        rev = mapping.import_commit(c, mapping.revision_id_foreign_to_bzr)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
133
        self.assertEquals(u"Authér", rev.properties['author'])
134
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
135
        self.assertTrue("git-explicit-encoding" not in rev.properties)
136
137
    def test_implicit_encoding_utf8(self):
138
        c = Commit()
139
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
140
        c.message = "Some message"
141
        c.committer = "Committer"
142
        c.commit_time = 4
143
        c.author_time = 5
144
        c.commit_timezone = 60 * 5
145
        c.author_timezone = 60 * 3
146
        c.author = u"Authér".encode("utf-8")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
147
        mapping = BzrGitMappingv1()
148
        rev = mapping.import_commit(c, mapping.revision_id_foreign_to_bzr)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
149
        self.assertEquals(u"Authér", rev.properties['author'])
150
        self.assertTrue("git-explicit-encoding" not in rev.properties)
151
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
152
153
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
154
class RoundtripRevisionsFromBazaar(tests.TestCase):
155
156
    def setUp(self):
157
        super(RoundtripRevisionsFromBazaar, self).setUp()
158
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
159
        self._parent_map = {}
160
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
161
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
162
    def assertRoundtripRevision(self, orig_rev):
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
163
        commit = self.mapping.export_commit(orig_rev, "mysha",
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
164
            self._lookup_parent, True)
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
165
        rev = self.mapping.import_commit(commit,
166
            self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
167
        self.assertEquals(orig_rev.revision_id, rev.revision_id)
168
        self.assertEquals(orig_rev.properties, rev.properties)
169
        self.assertEquals(orig_rev.committer, rev.committer)
170
        self.assertEquals(orig_rev.timestamp, rev.timestamp)
171
        self.assertEquals(orig_rev.timezone, rev.timezone)
172
        self.assertEquals(orig_rev.message, rev.message)
173
        self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
174
175
    def test_simple_commit(self):
176
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
177
        r.message = "MyCommitMessage"
178
        r.parent_ids = []
179
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
180
        r.timestamp = 453543543
181
        r.timezone = 0
182
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
183
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
184
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
185
    def test_revision_id(self):
186
        r = Revision("myrevid")
187
        r.message = "MyCommitMessage"
188
        r.parent_ids = []
189
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
190
        r.timestamp = 453543543
191
        r.timezone = 0
192
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
193
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
194
195
    def test_ghost_parent(self):
196
        r = Revision("myrevid")
197
        r.message = "MyCommitMessage"
198
        r.parent_ids = ["iamaghost"]
199
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
200
        r.timestamp = 453543543
201
        r.timezone = 0
202
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
203
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
204
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
205
    def test_custom_property(self):
206
        r = Revision("myrevid")
207
        r.message = "MyCommitMessage"
208
        r.parent_ids = []
209
        r.properties = {"fool": "bar"}
210
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
211
        r.timestamp = 453543543
212
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
213
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
214
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
215
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
216
class RoundtripRevisionsFromGit(tests.TestCase):
217
218
    def setUp(self):
219
        super(RoundtripRevisionsFromGit, self).setUp()
220
        self.mapping = BzrGitMappingv1()
221
222
    def assertRoundtripTree(self, tree):
223
        raise NotImplementedError(self.assertRoundtripTree)
224
225
    def assertRoundtripBlob(self, blob):
226
        raise NotImplementedError(self.assertRoundtripBlob)
227
228
    def assertRoundtripCommit(self, commit1):
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
229
        rev = self.mapping.import_commit(commit1,
230
            self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
231
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
232
            True)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
233
        self.assertEquals(commit1.committer, commit2.committer)
234
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
235
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
236
        self.assertEquals(commit1.author, commit2.author)
237
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
238
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
239
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
240
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
241
242
    def test_commit(self):
243
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
244
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
245
        c.message = "Some message"
246
        c.committer = "Committer <Committer>"
247
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
248
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
249
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
250
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
251
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
252
        self.assertRoundtripCommit(c)
253
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
254
    def test_commit_zero_utc_timezone(self):
255
        c = Commit()
256
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
257
        c.message = "Some message"
258
        c.committer = "Committer <Committer>"
259
        c.commit_time = 4
260
        c.commit_timezone = 0
261
        c._commit_timezone_neg_utc = True
262
        c.author_time = 5
263
        c.author_timezone = 60 * 2
264
        c.author = "Author <author>"
265
        self.assertRoundtripCommit(c)
266
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
267
    def test_commit_encoding(self):
268
        c = Commit()
269
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
270
        c.message = "Some message"
271
        c.committer = "Committer <Committer>"
272
        c.encoding = 'iso8859-1'
273
        c.commit_time = 4
274
        c.commit_timezone = -60 * 3
275
        c.author_time = 5
276
        c.author_timezone = 60 * 2
277
        c.author = "Author <author>"
278
        self.assertRoundtripCommit(c)
279
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
280
281
class DirectoryToTreeTests(tests.TestCase):
282
283
    def test_empty(self):
284
        ie = InventoryDirectory('foo', 'foo', 'foo')
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
285
        t = directory_to_tree(ie, None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
286
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
287
288
    def test_empty_dir(self):
289
        ie = InventoryDirectory('foo', 'foo', 'foo')
290
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
291
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
292
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
293
        self.assertEquals(None, t)
294
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
295
    def test_empty_dir_dummy_files(self):
296
        ie = InventoryDirectory('foo', 'foo', 'foo')
297
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
298
        ie.children['bar'] = child_ie
299
        t = directory_to_tree(ie, lambda x: None, {}, ".mydummy")
300
        self.assertTrue(".mydummy" in t)
301
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
302
    def test_empty_root(self):
303
        ie = InventoryDirectory('foo', 'foo', None)
304
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
305
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
306
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
307
        self.assertEquals(Tree(), t)
308
309
    def test_with_file(self):
310
        ie = InventoryDirectory('foo', 'foo', 'foo')
311
        child_ie = InventoryFile('bar', 'bar', 'bar')
312
        ie.children['bar'] = child_ie
313
        b = Blob.from_string("bla")
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
314
        t1 = directory_to_tree(ie, lambda x: b.id, {}, None)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
315
        t2 = Tree()
316
        t2.add(0100644, "bar", b.id)
317
        self.assertEquals(t1, t2)