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