/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.200.912 by Jelmer Vernooij
Merge roundtrip support.
167
        if self.mapping.roundtripping:
168
            self.assertEquals(orig_rev.revision_id, rev.revision_id)
169
            self.assertEquals(orig_rev.properties, rev.properties)
170
            self.assertEquals(orig_rev.committer, rev.committer)
171
            self.assertEquals(orig_rev.timestamp, rev.timestamp)
172
            self.assertEquals(orig_rev.timezone, rev.timezone)
173
            self.assertEquals(orig_rev.message, rev.message)
174
            self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
175
176
    def test_simple_commit(self):
177
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
178
        r.message = "MyCommitMessage"
179
        r.parent_ids = []
180
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
181
        r.timestamp = 453543543
182
        r.timezone = 0
183
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
184
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
185
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
186
    def test_revision_id(self):
187
        r = Revision("myrevid")
188
        r.message = "MyCommitMessage"
189
        r.parent_ids = []
190
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
191
        r.timestamp = 453543543
192
        r.timezone = 0
193
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
194
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
195
196
    def test_ghost_parent(self):
197
        r = Revision("myrevid")
198
        r.message = "MyCommitMessage"
199
        r.parent_ids = ["iamaghost"]
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.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
205
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
206
    def test_custom_property(self):
207
        r = Revision("myrevid")
208
        r.message = "MyCommitMessage"
209
        r.parent_ids = []
210
        r.properties = {"fool": "bar"}
211
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
212
        r.timestamp = 453543543
213
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
214
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
215
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
216
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
217
class RoundtripRevisionsFromGit(tests.TestCase):
218
219
    def setUp(self):
220
        super(RoundtripRevisionsFromGit, self).setUp()
221
        self.mapping = BzrGitMappingv1()
222
223
    def assertRoundtripTree(self, tree):
224
        raise NotImplementedError(self.assertRoundtripTree)
225
226
    def assertRoundtripBlob(self, blob):
227
        raise NotImplementedError(self.assertRoundtripBlob)
228
229
    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.
230
        rev = self.mapping.import_commit(commit1,
231
            self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
232
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
233
            True)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
234
        self.assertEquals(commit1.committer, commit2.committer)
235
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
236
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
237
        self.assertEquals(commit1.author, commit2.author)
238
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
239
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
240
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
241
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
242
243
    def test_commit(self):
244
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
245
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
246
        c.message = "Some message"
247
        c.committer = "Committer <Committer>"
248
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
249
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
250
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
251
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
252
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
253
        self.assertRoundtripCommit(c)
254
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
255
    def test_commit_zero_utc_timezone(self):
256
        c = Commit()
257
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
258
        c.message = "Some message"
259
        c.committer = "Committer <Committer>"
260
        c.commit_time = 4
261
        c.commit_timezone = 0
262
        c._commit_timezone_neg_utc = True
263
        c.author_time = 5
264
        c.author_timezone = 60 * 2
265
        c.author = "Author <author>"
266
        self.assertRoundtripCommit(c)
267
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
268
    def test_commit_encoding(self):
269
        c = Commit()
270
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
271
        c.message = "Some message"
272
        c.committer = "Committer <Committer>"
273
        c.encoding = 'iso8859-1'
274
        c.commit_time = 4
275
        c.commit_timezone = -60 * 3
276
        c.author_time = 5
277
        c.author_timezone = 60 * 2
278
        c.author = "Author <author>"
279
        self.assertRoundtripCommit(c)
280
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
281
282
class DirectoryToTreeTests(tests.TestCase):
283
284
    def test_empty(self):
285
        ie = InventoryDirectory('foo', 'foo', 'foo')
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
286
        t = directory_to_tree(ie, None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
287
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
288
289
    def test_empty_dir(self):
290
        ie = InventoryDirectory('foo', 'foo', 'foo')
291
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
292
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
293
        t = directory_to_tree(ie, lambda x: None, {}, None)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
294
        self.assertEquals(None, t)
295
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
296
    def test_empty_dir_dummy_files(self):
297
        ie = InventoryDirectory('foo', 'foo', 'foo')
298
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
299
        ie.children['bar'] = child_ie
300
        t = directory_to_tree(ie, lambda x: None, {}, ".mydummy")
301
        self.assertTrue(".mydummy" in t)
302
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
303
    def test_empty_root(self):
304
        ie = InventoryDirectory('foo', 'foo', None)
305
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
306
        ie.children['bar'] = child_ie
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
307
        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.
308
        self.assertEquals(Tree(), t)
309
310
    def test_with_file(self):
311
        ie = InventoryDirectory('foo', 'foo', 'foo')
312
        child_ie = InventoryFile('bar', 'bar', 'bar')
313
        ie.children['bar'] = child_ie
314
        b = Blob.from_string("bla")
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
315
        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.
316
        t2 = Tree()
317
        t2.add(0100644, "bar", b.id)
318
        self.assertEquals(t1, t2)