/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()
0.200.920 by Jelmer Vernooij
Fix some more tests.
58
        if mapping.roundtripping:
59
            self.assertTrue(mapping.is_control_file(".bzrdummy"))
60
            self.assertTrue(mapping.is_control_file(".bzrfileids"))
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
61
        self.assertFalse(mapping.is_control_file(".bzrfoo"))
62
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
63
    def test_generate_file_id(self):
64
        mapping = BzrGitMappingv1()
65
        self.assertIsInstance(mapping.generate_file_id("la"), str)
66
        self.assertIsInstance(mapping.generate_file_id(u"é"), str)
67
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
68
69
class FileidTests(tests.TestCase):
70
71
    def test_escape_space(self):
72
        self.assertEquals("bla_s", escape_file_id("bla "))
73
74
    def test_escape_underscore(self):
75
        self.assertEquals("bla__", escape_file_id("bla_"))
76
77
    def test_escape_underscore_space(self):
78
        self.assertEquals("bla___s", escape_file_id("bla_ "))
79
80
    def test_unescape_underscore(self):
81
        self.assertEquals("bla ", unescape_file_id("bla_s"))
82
83
    def test_unescape_underscore_space(self):
84
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
85
86
87
class TestImportCommit(tests.TestCase):
88
89
    def test_commit(self):
90
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
91
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
92
        c.message = "Some message"
93
        c.committer = "Committer"
94
        c.commit_time = 4
95
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
96
        c.commit_timezone = 60 * 5
97
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
98
        c.author = "Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
99
        mapping = BzrGitMappingv1()
100
        rev = mapping.import_commit(c, mapping.revision_id_foreign_to_bzr)
0.200.264 by Jelmer Vernooij
Add more tests.
101
        self.assertEquals("Some message", rev.message)
102
        self.assertEquals("Committer", rev.committer)
103
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
104
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
105
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
106
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
107
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
108
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
109
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
110
    def test_explicit_encoding(self):
111
        c = Commit()
112
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
113
        c.message = "Some message"
114
        c.committer = "Committer"
115
        c.commit_time = 4
116
        c.author_time = 5
117
        c.commit_timezone = 60 * 5
118
        c.author_timezone = 60 * 3
119
        c.author = u"Authér".encode("iso8859-1")
120
        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.
121
        mapping = BzrGitMappingv1()
122
        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
123
        self.assertEquals(u"Authér", rev.properties['author'])
124
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
125
        self.assertTrue("git-implicit-encoding" not in rev.properties)
126
127
    def test_implicit_encoding_fallback(self):
128
        c = Commit()
129
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
130
        c.message = "Some message"
131
        c.committer = "Committer"
132
        c.commit_time = 4
133
        c.author_time = 5
134
        c.commit_timezone = 60 * 5
135
        c.author_timezone = 60 * 3
136
        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.
137
        mapping = BzrGitMappingv1()
138
        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
139
        self.assertEquals(u"Authér", rev.properties['author'])
140
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
141
        self.assertTrue("git-explicit-encoding" not in rev.properties)
142
143
    def test_implicit_encoding_utf8(self):
144
        c = Commit()
145
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
146
        c.message = "Some message"
147
        c.committer = "Committer"
148
        c.commit_time = 4
149
        c.author_time = 5
150
        c.commit_timezone = 60 * 5
151
        c.author_timezone = 60 * 3
152
        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.
153
        mapping = BzrGitMappingv1()
154
        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
155
        self.assertEquals(u"Authér", rev.properties['author'])
156
        self.assertTrue("git-explicit-encoding" not in rev.properties)
157
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
158
159
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
160
class RoundtripRevisionsFromBazaar(tests.TestCase):
161
162
    def setUp(self):
163
        super(RoundtripRevisionsFromBazaar, self).setUp()
164
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
165
        self._parent_map = {}
166
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
167
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
168
    def assertRoundtripRevision(self, orig_rev):
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
169
        commit = self.mapping.export_commit(orig_rev, "mysha",
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
170
            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.
171
        rev = self.mapping.import_commit(commit,
172
            self.mapping.revision_id_foreign_to_bzr)
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
173
        if self.mapping.roundtripping:
174
            self.assertEquals(orig_rev.revision_id, rev.revision_id)
175
            self.assertEquals(orig_rev.properties, rev.properties)
176
            self.assertEquals(orig_rev.committer, rev.committer)
177
            self.assertEquals(orig_rev.timestamp, rev.timestamp)
178
            self.assertEquals(orig_rev.timezone, rev.timezone)
179
            self.assertEquals(orig_rev.message, rev.message)
180
            self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
181
182
    def test_simple_commit(self):
183
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
184
        r.message = "MyCommitMessage"
185
        r.parent_ids = []
186
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
187
        r.timestamp = 453543543
188
        r.timezone = 0
189
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
190
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
191
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
192
    def test_revision_id(self):
193
        r = Revision("myrevid")
194
        r.message = "MyCommitMessage"
195
        r.parent_ids = []
196
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
197
        r.timestamp = 453543543
198
        r.timezone = 0
199
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
200
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
201
202
    def test_ghost_parent(self):
203
        r = Revision("myrevid")
204
        r.message = "MyCommitMessage"
205
        r.parent_ids = ["iamaghost"]
206
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
207
        r.timestamp = 453543543
208
        r.timezone = 0
209
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
210
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
211
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
212
    def test_custom_property(self):
213
        r = Revision("myrevid")
214
        r.message = "MyCommitMessage"
215
        r.parent_ids = []
216
        r.properties = {"fool": "bar"}
217
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
218
        r.timestamp = 453543543
219
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
220
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
221
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
222
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
223
class RoundtripRevisionsFromGit(tests.TestCase):
224
225
    def setUp(self):
226
        super(RoundtripRevisionsFromGit, self).setUp()
227
        self.mapping = BzrGitMappingv1()
228
229
    def assertRoundtripTree(self, tree):
230
        raise NotImplementedError(self.assertRoundtripTree)
231
232
    def assertRoundtripBlob(self, blob):
233
        raise NotImplementedError(self.assertRoundtripBlob)
234
235
    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.
236
        rev = self.mapping.import_commit(commit1,
237
            self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
238
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
239
            True)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
240
        self.assertEquals(commit1.committer, commit2.committer)
241
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
242
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
243
        self.assertEquals(commit1.author, commit2.author)
244
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
245
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
246
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
247
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
248
249
    def test_commit(self):
250
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
251
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
252
        c.message = "Some message"
253
        c.committer = "Committer <Committer>"
254
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
255
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
256
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
257
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
258
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
259
        self.assertRoundtripCommit(c)
260
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
261
    def test_commit_zero_utc_timezone(self):
262
        c = Commit()
263
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
264
        c.message = "Some message"
265
        c.committer = "Committer <Committer>"
266
        c.commit_time = 4
267
        c.commit_timezone = 0
268
        c._commit_timezone_neg_utc = True
269
        c.author_time = 5
270
        c.author_timezone = 60 * 2
271
        c.author = "Author <author>"
272
        self.assertRoundtripCommit(c)
273
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
274
    def test_commit_encoding(self):
275
        c = Commit()
276
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
277
        c.message = "Some message"
278
        c.committer = "Committer <Committer>"
279
        c.encoding = 'iso8859-1'
280
        c.commit_time = 4
281
        c.commit_timezone = -60 * 3
282
        c.author_time = 5
283
        c.author_timezone = 60 * 2
284
        c.author = "Author <author>"
285
        self.assertRoundtripCommit(c)
286
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
287
288
class DirectoryToTreeTests(tests.TestCase):
289
290
    def test_empty(self):
291
        ie = InventoryDirectory('foo', 'foo', 'foo')
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
292
        t = directory_to_tree(ie, None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
293
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
294
295
    def test_empty_dir(self):
296
        ie = InventoryDirectory('foo', 'foo', 'foo')
297
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
298
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
299
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
300
        self.assertEquals(None, t)
301
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
302
    def test_empty_dir_dummy_files(self):
303
        ie = InventoryDirectory('foo', 'foo', 'foo')
304
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
305
        ie.children['bar'] = child_ie
306
        t = directory_to_tree(ie, lambda x: None, {}, ".mydummy")
307
        self.assertTrue(".mydummy" in t)
308
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
309
    def test_empty_root(self):
310
        ie = InventoryDirectory('foo', 'foo', None)
311
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
312
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
313
        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.
314
        self.assertEquals(Tree(), t)
315
316
    def test_with_file(self):
317
        ie = InventoryDirectory('foo', 'foo', 'foo')
318
        child_ie = InventoryFile('bar', 'bar', 'bar')
319
        ie.children['bar'] = child_ie
320
        b = Blob.from_string("bla")
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
321
        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.
322
        t2 = Tree()
323
        t2.add(0100644, "bar", b.id)
324
        self.assertEquals(t1, t2)