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