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