/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
16
6973.7.10 by Jelmer Vernooij
More fixes.
17
import bz2
18
from io import BytesIO
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
19
import os
6621.25.1 by Martin
Adapt to SocketServer module name change
20
try:
21
    import socketserver
22
except ImportError:
23
    import SocketServer as socketserver
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
24
import sys
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
25
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
26
from .. import (
4241.14.13 by Vincent Ladeuil
Some more cleanup.
27
    diff,
1996.3.20 by John Arbash Meinel
[merge] bzr.dev 2063
28
    errors,
4241.14.13 by Vincent Ladeuil
Some more cleanup.
29
    merge,
3638.3.2 by Vincent Ladeuil
Fix all calls to tempfile.mkdtemp to osutils.mkdtemp.
30
    osutils,
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
31
    revision as _mod_revision,
4241.14.13 by Vincent Ladeuil
Some more cleanup.
32
    tests,
1910.2.64 by Aaron Bentley
Changes from review
33
    treebuilder,
34
    )
6670.4.1 by Jelmer Vernooij
Update imports.
35
from ..bzr import (
36
    bzrdir,
37
    inventory,
38
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
39
from ..bundle import read_mergeable_from_url
40
from ..bundle.apply_bundle import install_bundle, merge_bundle
41
from ..bundle.bundle_data import BundleTree
42
from ..directory_service import directories
43
from ..bundle.serializer import write_bundle, read_bundle, v09, v4
44
from ..bundle.serializer.v08 import BundleSerializerV08
45
from ..bundle.serializer.v09 import BundleSerializerV09
46
from ..bundle.serializer.v4 import BundleSerializerV4
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
47
from ..bzr import knitrepo
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
48
from . import (
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
49
    features,
50
    test_commit,
3251.4.11 by Aaron Bentley
Fix wrong local lookups
51
    test_read_bundle,
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
52
    test_server,
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
53
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
54
from ..transform import TreeTransform
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
55
1185.82.90 by Aaron Bentley
Reorganized test suite
56
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
57
def get_text(vf, key):
58
    """Get the fulltext for a given revision id that is present in the vf"""
59
    stream = vf.get_record_stream([key], 'unordered', True)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
60
    record = next(stream)
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
61
    return record.get_bytes_as('fulltext')
62
63
64
def get_inventory_text(repo, revision_id):
65
    """Get the fulltext for the inventory at revision id"""
66
    repo.lock_read()
67
    try:
68
        return get_text(repo.inventories, (revision_id,))
69
    finally:
70
        repo.unlock()
71
72
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
73
class MockTree(object):
5837.2.5 by Jelmer Vernooij
Fix two warnings.
74
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
75
    def __init__(self):
6670.4.3 by Jelmer Vernooij
Fix more imports.
76
        from ..bzr.inventory import InventoryDirectory, ROOT_ID
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
77
        object.__init__(self)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
78
        self.paths = {ROOT_ID: ""}
79
        self.ids = {"": ROOT_ID}
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
80
        self.contents = {}
1731.1.4 by Aaron Bentley
merge from bzr.dev
81
        self.root = InventoryDirectory(ROOT_ID, '', None)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
82
83
    inventory = property(lambda x:x)
6405.2.9 by Jelmer Vernooij
More test fixes.
84
    root_inventory = property(lambda x:x)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
85
6405.2.10 by Jelmer Vernooij
Fix more tests.
86
    def get_root_id(self):
87
        return self.root.file_id
88
5837.2.5 by Jelmer Vernooij
Fix two warnings.
89
    def all_file_ids(self):
90
        return set(self.paths.keys())
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
91
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
92
    def all_versioned_paths(self):
93
        return set(self.paths.values())
94
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
95
    def is_executable(self, path, file_id):
6445.2.6 by Jelmer Vernooij
Review feedback.
96
        # Not all the files are executable.
6405.2.9 by Jelmer Vernooij
More test fixes.
97
        return False
98
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
99
    def __getitem__(self, file_id):
100
        if file_id == self.root.file_id:
101
            return self.root
102
        else:
103
            return self.make_entry(file_id, self.paths[file_id])
104
105
    def parent_id(self, file_id):
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
106
        parent_dir = os.path.dirname(self.paths[file_id])
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
107
        if parent_dir == "":
108
            return None
109
        return self.ids[parent_dir]
110
111
    def iter_entries(self):
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
112
        for path, file_id in self.ids.items():
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
113
            yield path, self[file_id]
114
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
115
    def kind(self, path, file_id=None):
116
        if file_id is None:
117
            file_id = self.path2id(path)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
118
        if file_id in self.contents:
119
            kind = 'file'
120
        else:
121
            kind = 'directory'
122
        return kind
123
124
    def make_entry(self, file_id, path):
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
125
        from ..bzr.inventory import (InventoryFile, InventoryDirectory,
6468.2.8 by Jelmer Vernooij
Fix remaining test.
126
            InventoryLink)
1711.7.27 by John Arbash Meinel
Investigating why test_bundle fails, something isn't transmitting properly.
127
        name = os.path.basename(path)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
128
        kind = self.kind(path, file_id)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
129
        parent_id = self.parent_id(file_id)
6809.4.9 by Jelmer Vernooij
Fix some more tests.
130
        text_sha_1, text_size = self.contents_stats(path, file_id)
0.5.119 by John Arbash Meinel
Recreated the factory. We really need InventoryEntry.create()
131
        if kind == 'directory':
132
            ie = InventoryDirectory(file_id, name, parent_id)
133
        elif kind == 'file':
134
            ie = InventoryFile(file_id, name, parent_id)
5365.2.2 by Andrew Bennetts
Fix test failures for bundles and upgrades.
135
            ie.text_sha1 = text_sha_1
136
            ie.text_size = text_size
0.5.119 by John Arbash Meinel
Recreated the factory. We really need InventoryEntry.create()
137
        elif kind == 'symlink':
138
            ie = InventoryLink(file_id, name, parent_id)
139
        else:
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
140
            raise errors.BzrError('unknown kind %r' % kind)
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
141
        return ie
142
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
143
    def add_dir(self, file_id, path):
144
        self.paths[file_id] = path
145
        self.ids[path] = file_id
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
146
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
147
    def add_file(self, file_id, path, contents):
148
        self.add_dir(file_id, path)
149
        self.contents[file_id] = contents
150
151
    def path2id(self, path):
152
        return self.ids.get(path)
153
154
    def id2path(self, file_id):
155
        return self.paths.get(file_id)
156
157
    def has_id(self, file_id):
158
        return self.id2path(file_id) is not None
159
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
160
    def get_file(self, path, file_id=None):
161
        if file_id is None:
162
            file_id = self.path2id(path)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
163
        result = BytesIO()
6809.4.9 by Jelmer Vernooij
Fix some more tests.
164
        try:
165
            result.write(self.contents[file_id])
166
        except KeyError:
167
            raise errors.NoSuchFile(path)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
168
        result.seek(0, 0)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
169
        return result
170
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
171
    def get_file_revision(self, path, file_id=None):
172
        if file_id is None:
173
            file_id = self.path2id(path)
5793.2.6 by Jelmer Vernooij
Add MockTree.get_file_revision.
174
        return self.inventory[file_id].revision
175
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
176
    def get_file_size(self, path, file_id=None):
177
        if file_id is None:
178
            file_id = self.path2id(path)
6468.2.8 by Jelmer Vernooij
Fix remaining test.
179
        return self.inventory[file_id].text_size
180
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
181
    def get_file_sha1(self, path, file_id=None):
182
        if file_id is None:
183
            file_id = self.path2id(path)
6468.2.8 by Jelmer Vernooij
Fix remaining test.
184
        return self.inventory[file_id].text_sha1
185
6809.4.9 by Jelmer Vernooij
Fix some more tests.
186
    def contents_stats(self, path, file_id):
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
187
        if file_id not in self.contents:
188
            return None, None
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
189
        text_sha1 = osutils.sha_file(self.get_file(path, file_id))
0.6.1 by Aaron Bentley
Fleshed out MockTree, fixed all test failures
190
        return text_sha1, len(self.contents[file_id])
191
192
4241.14.13 by Vincent Ladeuil
Some more cleanup.
193
class BTreeTester(tests.TestCase):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
194
    """A simple unittest tester for the BundleTree class."""
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
195
196
    def make_tree_1(self):
197
        mtree = MockTree()
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
198
        mtree.add_dir(b"a", "grandparent")
199
        mtree.add_dir(b"b", "grandparent/parent")
6973.7.10 by Jelmer Vernooij
More fixes.
200
        mtree.add_file(b"c", "grandparent/parent/file", b"Hello\n")
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
201
        mtree.add_dir(b"d", "grandparent/alt_parent")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
202
        return BundleTree(mtree, ''), mtree
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
203
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
204
    def test_renames(self):
205
        """Ensure that file renames have the proper effect on children"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
206
        btree = self.make_tree_1()[0]
207
        self.assertEqual(btree.old_path("grandparent"), "grandparent")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
208
        self.assertEqual(btree.old_path("grandparent/parent"),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
209
                         "grandparent/parent")
210
        self.assertEqual(btree.old_path("grandparent/parent/file"),
211
                         "grandparent/parent/file")
212
6855.4.1 by Jelmer Vernooij
Yet more bees.
213
        self.assertEqual(btree.id2path(b"a"), "grandparent")
214
        self.assertEqual(btree.id2path(b"b"), "grandparent/parent")
215
        self.assertEqual(btree.id2path(b"c"), "grandparent/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
216
6855.4.1 by Jelmer Vernooij
Yet more bees.
217
        self.assertEqual(btree.path2id("grandparent"), b"a")
218
        self.assertEqual(btree.path2id("grandparent/parent"), b"b")
219
        self.assertEqual(btree.path2id("grandparent/parent/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
220
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
221
        self.assertIs(btree.path2id("grandparent2"), None)
222
        self.assertIs(btree.path2id("grandparent2/parent"), None)
223
        self.assertIs(btree.path2id("grandparent2/parent/file"), None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
224
225
        btree.note_rename("grandparent", "grandparent2")
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
226
        self.assertIs(btree.old_path("grandparent"), None)
227
        self.assertIs(btree.old_path("grandparent/parent"), None)
228
        self.assertIs(btree.old_path("grandparent/parent/file"), None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
229
6855.4.1 by Jelmer Vernooij
Yet more bees.
230
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
231
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent")
232
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
233
6855.4.1 by Jelmer Vernooij
Yet more bees.
234
        self.assertEqual(btree.path2id("grandparent2"), b"a")
235
        self.assertEqual(btree.path2id("grandparent2/parent"), b"b")
236
        self.assertEqual(btree.path2id("grandparent2/parent/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
237
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
238
        self.assertTrue(btree.path2id("grandparent") is None)
239
        self.assertTrue(btree.path2id("grandparent/parent") is None)
240
        self.assertTrue(btree.path2id("grandparent/parent/file") is None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
241
242
        btree.note_rename("grandparent/parent", "grandparent2/parent2")
6855.4.1 by Jelmer Vernooij
Yet more bees.
243
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
244
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
245
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
246
6855.4.1 by Jelmer Vernooij
Yet more bees.
247
        self.assertEqual(btree.path2id("grandparent2"), b"a")
248
        self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
249
        self.assertEqual(btree.path2id("grandparent2/parent2/file"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
250
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
251
        self.assertTrue(btree.path2id("grandparent2/parent") is None)
252
        self.assertTrue(btree.path2id("grandparent2/parent/file") is None)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
253
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
254
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
255
                          "grandparent2/parent2/file2")
6855.4.1 by Jelmer Vernooij
Yet more bees.
256
        self.assertEqual(btree.id2path(b"a"), "grandparent2")
257
        self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
258
        self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file2")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
259
6855.4.1 by Jelmer Vernooij
Yet more bees.
260
        self.assertEqual(btree.path2id("grandparent2"), b"a")
261
        self.assertEqual(btree.path2id("grandparent2/parent2"), b"b")
262
        self.assertEqual(btree.path2id("grandparent2/parent2/file2"), b"c")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
263
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
264
        self.assertTrue(btree.path2id("grandparent2/parent2/file") is None)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
265
266
    def test_moves(self):
267
        """Ensure that file moves have the proper effect on children"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
268
        btree = self.make_tree_1()[0]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
269
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
270
                          "grandparent/alt_parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
271
        self.assertEqual(btree.id2path(b"c"), "grandparent/alt_parent/file")
272
        self.assertEqual(btree.path2id("grandparent/alt_parent/file"), b"c")
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
273
        self.assertTrue(btree.path2id("grandparent/parent/file") is None)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
274
275
    def unified_diff(self, old, new):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
276
        out = BytesIO()
7045.2.14 by Jelmer Vernooij
Fix some bundle tests.:
277
        diff.internal_diff("old", old, "new", new, out)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
278
        out.seek(0, 0)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
279
        return out.read()
280
281
    def make_tree_2(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
282
        btree = self.make_tree_1()[0]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
283
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
284
                          "grandparent/alt_parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
285
        self.assertTrue(btree.id2path(b"e") is None)
6973.7.10 by Jelmer Vernooij
More fixes.
286
        self.assertFalse(btree.is_versioned("grandparent/parent/file"))
287
        btree.note_id(b"e", "grandparent/parent/file")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
288
        return btree
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
289
290
    def test_adds(self):
291
        """File/inventory adds"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
292
        btree = self.make_tree_2()
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
293
        add_patch = self.unified_diff([], [b"Extra cheese\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
294
        btree.note_patch("grandparent/parent/file", add_patch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
295
        btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
296
        btree.note_target('grandparent/parent/symlink', 'venus')
297
        self.adds_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
298
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
299
    def adds_test(self, btree):
6855.4.1 by Jelmer Vernooij
Yet more bees.
300
        self.assertEqual(btree.id2path(b"e"), "grandparent/parent/file")
301
        self.assertEqual(btree.path2id("grandparent/parent/file"), b"e")
6973.7.10 by Jelmer Vernooij
More fixes.
302
        with btree.get_file("grandparent/parent/file") as f:
303
            self.assertEqual(f.read(), b"Extra cheese\n")
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
304
        self.assertEqual(
305
            btree.get_symlink_target('grandparent/parent/symlink'), 'venus')
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
306
307
    def test_adds2(self):
308
        """File/inventory adds, with patch-compatibile renames"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
309
        btree = self.make_tree_2()
310
        btree.contents_by_id = False
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
311
        add_patch = self.unified_diff([b"Hello\n"], [b"Extra cheese\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
312
        btree.note_patch("grandparent/parent/file", add_patch)
6973.7.10 by Jelmer Vernooij
More fixes.
313
        btree.note_id(b'f', 'grandparent/parent/symlink', kind='symlink')
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
314
        btree.note_target('grandparent/parent/symlink', 'venus')
315
        self.adds_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
316
317
    def make_tree_3(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
318
        btree, mtree = self.make_tree_1()
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
319
        mtree.add_file("e", "grandparent/parent/topping", "Anchovies\n")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
320
        btree.note_rename("grandparent/parent/file",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
321
                          "grandparent/alt_parent/file")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
322
        btree.note_rename("grandparent/parent/topping",
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
323
                          "grandparent/alt_parent/stopping")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
324
        return btree
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
325
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
326
    def get_file_test(self, btree):
6973.7.10 by Jelmer Vernooij
More fixes.
327
        with btree.get_file(btree.id2path(b"e")) as f:
328
            self.assertEqual(f.read(), b"Lemon\n")
329
        with btree.get_file(btree.id2path(b"c")) as f:
330
            self.assertEqual(f.read(), b"Hello\n")
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
331
332
    def test_get_file(self):
333
        """Get file contents"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
334
        btree = self.make_tree_3()
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
335
        mod_patch = self.unified_diff([b"Anchovies\n"], [b"Lemon\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
336
        btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
337
        self.get_file_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
338
339
    def test_get_file2(self):
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
340
        """Get file contents, with patch-compatible renames"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
341
        btree = self.make_tree_3()
342
        btree.contents_by_id = False
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
343
        mod_patch = self.unified_diff([], [b"Lemon\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
344
        btree.note_patch("grandparent/alt_parent/stopping", mod_patch)
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
345
        mod_patch = self.unified_diff([], [b"Hello\n"])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
346
        btree.note_patch("grandparent/alt_parent/file", mod_patch)
347
        self.get_file_test(btree)
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
348
349
    def test_delete(self):
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
350
        "Deletion by bundle"
351
        btree = self.make_tree_1()[0]
6973.7.10 by Jelmer Vernooij
More fixes.
352
        with btree.get_file(btree.id2path(b"c")) as f:
353
            self.assertEqual(f.read(), b"Hello\n")
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
354
        btree.note_deletion("grandparent/parent/file")
6855.4.1 by Jelmer Vernooij
Yet more bees.
355
        self.assertTrue(btree.id2path(b"c") is None)
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
356
        self.assertFalse(btree.is_versioned("grandparent/parent/file"))
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
357
358
    def sorted_ids(self, tree):
6619.3.18 by Jelmer Vernooij
Run 2to3 idioms fixer.
359
        ids = sorted(tree.all_file_ids())
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
360
        return ids
361
362
    def test_iteration(self):
363
        """Ensure that iteration through ids works properly"""
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
364
        btree = self.make_tree_1()[0]
1852.6.3 by Robert Collins
Make iter(Tree) consistent for all tree types.
365
        self.assertEqual(self.sorted_ids(btree),
6973.7.10 by Jelmer Vernooij
More fixes.
366
            [inventory.ROOT_ID, b'a', b'b', b'c', b'd'])
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
367
        btree.note_deletion("grandparent/parent/file")
6973.7.10 by Jelmer Vernooij
More fixes.
368
        btree.note_id(b"e", "grandparent/alt_parent/fool", kind="directory")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
369
        btree.note_last_changed("grandparent/alt_parent/fool",
1185.82.95 by Aaron Bentley
Restore path-orientation of ChangesetTree
370
                                "revisionidiguess")
1852.6.3 by Robert Collins
Make iter(Tree) consistent for all tree types.
371
        self.assertEqual(self.sorted_ids(btree),
6973.7.10 by Jelmer Vernooij
More fixes.
372
            [inventory.ROOT_ID, b'a', b'b', b'd', b'e'])
0.5.66 by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None)
373
1185.82.7 by John Arbash Meinel
Adding patches.py into bzrlib, including the tests into the test suite.
374
4241.14.13 by Vincent Ladeuil
Some more cleanup.
375
class BundleTester1(tests.TestCaseWithTransport):
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
376
377
    def test_mismatched_bundle(self):
378
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
379
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
380
        serializer = BundleSerializerV08('0.8')
381
        b = self.make_branch('.', format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
382
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
383
                          b.repository, [], {}, BytesIO())
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
384
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
385
    def test_matched_bundle(self):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
386
        """Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
387
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
388
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
389
        serializer = BundleSerializerV09('0.9')
390
        b = self.make_branch('.', format=format)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
391
        serializer.write(b.repository, [], {}, BytesIO())
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
392
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
393
    def test_mismatched_model(self):
394
        """Try copying a bundle from knit2 to knit1"""
395
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
396
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
397
        source = self.make_branch_and_tree('source', format=format)
6855.4.1 by Jelmer Vernooij
Yet more bees.
398
        source.commit('one', rev_id=b'one-id')
399
        source.commit('two', rev_id=b'two-id')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
400
        text = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
401
        write_bundle(source.branch.repository, b'two-id', b'null:', text,
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
402
                     format='0.9')
403
        text.seek(0)
404
405
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
406
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
407
        target = self.make_branch('target', format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
408
        self.assertRaises(errors.IncompatibleRevision, install_bundle,
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
409
                          target.repository, read_bundle(text))
410
1910.2.51 by Aaron Bentley
Bundles now corrupt repositories
411
2520.4.43 by Aaron Bentley
Fix test suite
412
class BundleTester(object):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
413
414
    def bzrdir_format(self):
415
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
416
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
417
        return format
418
419
    def make_branch_and_tree(self, path, format=None):
420
        if format is None:
421
            format = self.bzrdir_format()
4241.14.13 by Vincent Ladeuil
Some more cleanup.
422
        return tests.TestCaseWithTransport.make_branch_and_tree(
423
            self, path, format)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
424
425
    def make_branch(self, path, format=None):
426
        if format is None:
427
            format = self.bzrdir_format()
4241.14.13 by Vincent Ladeuil
Some more cleanup.
428
        return tests.TestCaseWithTransport.make_branch(self, path, format)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
429
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
430
    def create_bundle_text(self, base_rev_id, rev_id):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
431
        bundle_txt = BytesIO()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
432
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
433
                               bundle_txt, format=self.format)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
434
        bundle_txt.seek(0)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
435
        self.assertEqual(bundle_txt.readline(),
6973.7.10 by Jelmer Vernooij
More fixes.
436
                         b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
437
        self.assertEqual(bundle_txt.readline(), b'#\n')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
438
1185.82.14 by Aaron Bentley
API updates
439
        rev = self.b1.repository.get_revision(rev_id)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
440
        self.assertEqual(bundle_txt.readline().decode('utf-8'),
441
                         u'# message:\n')
442
        bundle_txt.seek(0)
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
443
        return bundle_txt, rev_ids
444
445
    def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
446
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
447
        Make sure that the text generated is valid, and that it
448
        can be applied against the base, and generate the same information.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
449
450
        :return: The in-memory bundle
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
451
        """
452
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
453
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
454
        # This should also validate the generated bundle
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
455
        bundle = read_bundle(bundle_txt)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
456
        repository = self.b1.repository
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
457
        for bundle_rev in bundle.real_revisions:
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
458
            # These really should have already been checked when we read the
459
            # bundle, since it computes the sha1 hash for the revision, which
460
            # only will match if everything is okay, but lets be explicit about
461
            # it
462
            branch_rev = repository.get_revision(bundle_rev.revision_id)
1185.82.33 by Aaron Bentley
Strengthen tests
463
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
464
                      'timestamp', 'timezone', 'message', 'committer',
1185.82.33 by Aaron Bentley
Strengthen tests
465
                      'parent_ids', 'properties'):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
466
                self.assertEqual(getattr(branch_rev, a),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
467
                                 getattr(bundle_rev, a))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
468
            self.assertEqual(len(branch_rev.parent_ids),
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
469
                             len(bundle_rev.parent_ids))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
470
        self.assertEqual(rev_ids,
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
471
                         [r.revision_id for r in bundle.real_revisions])
7029.2.1 by Jelmer Vernooij
don't make assumptions about the order in which revision ids are returned by write_bundle.
472
        self.valid_apply_bundle(base_rev_id, bundle, checkout_dir=checkout_dir)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
473
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
474
        return bundle
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
475
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
476
    def get_invalid_bundle(self, base_rev_id, rev_id):
477
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
478
        Munge the text so that it's invalid.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
479
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
480
        :return: The in-memory bundle
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
481
        """
1793.3.1 by John Arbash Meinel
Clean up the bundle tests a little bit.
482
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
483
        new_text = bundle_txt.getvalue().replace('executable:no',
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
484
                                               'executable:yes')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
485
        bundle_txt = BytesIO(new_text)
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
486
        bundle = read_bundle(bundle_txt)
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
487
        self.valid_apply_bundle(base_rev_id, bundle)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
488
        return bundle
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
489
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
490
    def test_non_bundle(self):
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
491
        self.assertRaises(errors.NotABundle,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
492
                          read_bundle, BytesIO(b'#!/bin/sh\n'))
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
493
1793.2.7 by Aaron Bentley
Fix reporting of malformed, (especially, crlf) bundles
494
    def test_malformed(self):
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
495
        self.assertRaises(errors.BadBundle, read_bundle,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
496
                          BytesIO(b'# Bazaar revision bundle v'))
1793.2.7 by Aaron Bentley
Fix reporting of malformed, (especially, crlf) bundles
497
498
    def test_crlf_bundle(self):
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
499
        try:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
500
            read_bundle(BytesIO(b'# Bazaar revision bundle v0.8\r\n'))
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
501
        except errors.BadBundle:
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
502
            # It is currently permitted for bundles with crlf line endings to
503
            # make read_bundle raise a BadBundle, but this should be fixed.
1793.2.10 by Aaron Bentley
Whitespace/comment fix
504
            # Anything else, especially NotABundle, is an error.
1793.2.9 by Aaron Bentley
Don't use assertNotRaises-- instead, catch BadBundle and pass
505
            pass
506
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
507
    def get_checkout(self, rev_id, checkout_dir=None):
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
508
        """Get a new tree, with the specified revision in it.
509
        """
510
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
511
        if checkout_dir is None:
3638.3.2 by Vincent Ladeuil
Fix all calls to tempfile.mkdtemp to osutils.mkdtemp.
512
            checkout_dir = osutils.mkdtemp(prefix='test-branch-', dir='.')
0.5.89 by John Arbash Meinel
Updating for explicitly defined directories.
513
        else:
514
            if not os.path.exists(checkout_dir):
515
                os.mkdir(checkout_dir)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
516
        tree = self.make_branch_and_tree(checkout_dir)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
517
        s = BytesIO()
6973.7.8 by Jelmer Vernooij
Fix more tests.
518
        ancestors = write_bundle(self.b1.repository, rev_id, b'null:', s,
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
519
                                 format=self.format)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
520
        s.seek(0)
6973.7.10 by Jelmer Vernooij
More fixes.
521
        self.assertIsInstance(s.getvalue(), bytes)
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
522
        install_bundle(tree.branch.repository, read_bundle(s))
1185.82.41 by Aaron Bentley
More work on installing changesets
523
        for ancestor in ancestors:
524
            old = self.b1.repository.revision_tree(ancestor)
525
            new = tree.branch.repository.revision_tree(ancestor)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
526
            old.lock_read()
527
            new.lock_read()
528
            try:
529
                # Check that there aren't any inventory level changes
530
                delta = new.changes_from(old)
531
                self.assertFalse(delta.has_changed(),
532
                                 'Revision %s not copied correctly.'
533
                                 % (ancestor,))
534
535
                # Now check that the file contents are all correct
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
536
                for path in old.all_versioned_paths():
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
537
                    try:
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
538
                        old_file = old.get_file(path)
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
539
                    except errors.NoSuchFile:
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
540
                        continue
6809.4.21 by Jelmer Vernooij
Fix long lines.
541
                    self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
542
                            old_file.read(), new.get_file(path).read())
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
543
            finally:
544
                new.unlock()
545
                old.unlock()
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
546
        if not _mod_revision.is_null(rev_id):
6165.4.19 by Jelmer Vernooij
Avoid all iter_reverse_revision_history calls.
547
            tree.branch.generate_revision_history(rev_id)
1185.82.44 by Aaron Bentley
Switch to merge_changeset in test suite
548
            tree.update()
1852.10.3 by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib.
549
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
550
            self.assertFalse(delta.has_changed(),
2255.10.5 by John Arbash Meinel
Fix a small bug when we have a symlink that does not need to be re-read.
551
                             'Working tree has modifications: %s' % delta)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
552
        return tree
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
553
1793.2.2 by Aaron Bentley
Move BundleReader into v07 serializer
554
    def valid_apply_bundle(self, base_rev_id, info, checkout_dir=None):
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
555
        """Get the base revision, apply the changes, and make
556
        sure everything matches the builtin branch.
557
        """
1185.82.17 by Aaron Bentley
More API updates
558
        to_tree = self.get_checkout(base_rev_id, checkout_dir=checkout_dir)
3146.4.11 by Aaron Bentley
Fix lock errors in bundle tests
559
        to_tree.lock_write()
560
        try:
561
            self._valid_apply_bundle(base_rev_id, info, to_tree)
562
        finally:
563
            to_tree.unlock()
564
565
    def _valid_apply_bundle(self, base_rev_id, info, to_tree):
1908.6.4 by Robert Collins
Update to replaced parent checking api bzrlib/merge.py
566
        original_parents = to_tree.get_parent_ids()
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
567
        repository = to_tree.branch.repository
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
568
        original_parents = to_tree.get_parent_ids()
1185.82.41 by Aaron Bentley
More work on installing changesets
569
        self.assertIs(repository.has_revision(base_rev_id), True)
1185.82.40 by Aaron Bentley
Started work on testing install_revisions/handling empty changesets
570
        for rev in info.real_revisions:
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
571
            self.assertTrue(not repository.has_revision(rev.revision_id),
572
                            'Revision {%s} present before applying bundle'
573
                            % rev.revision_id)
4241.14.13 by Vincent Ladeuil
Some more cleanup.
574
        merge_bundle(info, to_tree, True, merge.Merge3Merger, False, False)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
575
576
        for rev in info.real_revisions:
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
577
            self.assertTrue(repository.has_revision(rev.revision_id),
578
                            'Missing revision {%s} after applying bundle'
579
                            % rev.revision_id)
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
580
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
581
        self.assertTrue(to_tree.branch.repository.has_revision(info.target))
0.5.117 by John Arbash Meinel
Almost there. Just need to track down a few remaining bugs.
582
        # Do we also want to verify that all the texts have been added?
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
583
1908.6.4 by Robert Collins
Update to replaced parent checking api bzrlib/merge.py
584
        self.assertEqual(original_parents + [info.target],
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
585
                         to_tree.get_parent_ids())
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
586
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
587
        rev = info.real_revisions[-1]
1185.82.17 by Aaron Bentley
More API updates
588
        base_tree = self.b1.repository.revision_tree(rev.revision_id)
589
        to_tree = to_tree.branch.repository.revision_tree(rev.revision_id)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
590
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
591
        # TODO: make sure the target tree is identical to base tree
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
592
        #       we might also check the working tree.
593
594
        base_files = list(base_tree.list_files())
595
        to_files = list(to_tree.list_files())
596
        self.assertEqual(len(base_files), len(to_files))
1185.82.66 by Aaron Bentley
Handle new executable files
597
        for base_file, to_file in zip(base_files, to_files):
598
            self.assertEqual(base_file, to_file)
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
599
0.5.117 by John Arbash Meinel
Almost there. Just need to track down a few remaining bugs.
600
        for path, status, kind, fileid, entry in base_files:
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
601
            # Check that the meta information is the same
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
602
            self.assertEqual(base_tree.get_file_size(path, fileid),
603
                    to_tree.get_file_size(to_tree.id2path(fileid)))
604
            self.assertEqual(base_tree.get_file_sha1(path, fileid),
605
                    to_tree.get_file_sha1(to_tree.id2path(fileid)))
0.5.86 by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing.
606
            # Check that the contents are the same
607
            # This is pretty expensive
608
            # self.assertEqual(base_tree.get_file(fileid).read(),
609
            #         to_tree.get_file(fileid).read())
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
610
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
611
    def test_bundle(self):
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
612
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.14 by Aaron Bentley
API updates
613
        self.b1 = self.tree1.branch
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
614
6855.3.1 by Jelmer Vernooij
Several more fixes.
615
        self.build_tree_contents([('b1/one', b'one\n')])
6855.4.1 by Jelmer Vernooij
Yet more bees.
616
        self.tree1.add('one', b'one-id')
617
        self.tree1.set_root_id(b'root-id')
618
        self.tree1.commit('add one', rev_id=b'a@cset-0-1')
0.5.78 by John Arbash Meinel
Working on test cases, starting with the empty project issues.
619
6973.7.8 by Jelmer Vernooij
Fix more tests.
620
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-1')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
621
622
        # Make sure we can handle files with spaces, tabs, other
623
        # bogus characters
0.5.82 by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids
624
        self.build_tree([
0.5.84 by John Arbash Meinel
(broken) problem with removes.
625
                'b1/with space.txt'
626
                , 'b1/dir/'
627
                , 'b1/dir/filein subdir.c'
628
                , 'b1/dir/WithCaps.txt'
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
629
                , 'b1/dir/ pre space'
0.5.84 by John Arbash Meinel
(broken) problem with removes.
630
                , 'b1/sub/'
631
                , 'b1/sub/sub/'
632
                , 'b1/sub/sub/nonempty.txt'
0.5.82 by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids
633
                ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
634
        self.build_tree_contents([('b1/sub/sub/emptyfile.txt', b''),
635
                                  ('b1/dir/nolastnewline.txt', b'bloop')])
1185.82.66 by Aaron Bentley
Handle new executable files
636
        tt = TreeTransform(self.tree1)
6973.7.10 by Jelmer Vernooij
More fixes.
637
        tt.new_file('executable', tt.root, [b'#!/bin/sh\n'], b'exe-1', True)
1185.82.66 by Aaron Bentley
Handle new executable files
638
        tt.apply()
2520.4.84 by Aaron Bentley
Fix heisenbug record-rewriting test
639
        # have to fix length of file-id so that we can predictably rewrite
640
        # a (length-prefixed) record containing it later.
6855.4.1 by Jelmer Vernooij
Yet more bees.
641
        self.tree1.add('with space.txt', b'withspace-id')
1185.82.14 by Aaron Bentley
API updates
642
        self.tree1.add([
2520.4.84 by Aaron Bentley
Fix heisenbug record-rewriting test
643
                  'dir'
0.5.84 by John Arbash Meinel
(broken) problem with removes.
644
                , 'dir/filein subdir.c'
645
                , 'dir/WithCaps.txt'
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
646
                , 'dir/ pre space'
0.5.94 by Aaron Bentley
Switched to native patch application, added tests for terminating newlines
647
                , 'dir/nolastnewline.txt'
0.5.84 by John Arbash Meinel
(broken) problem with removes.
648
                , 'sub'
649
                , 'sub/sub'
650
                , 'sub/sub/nonempty.txt'
651
                , 'sub/sub/emptyfile.txt'
0.5.82 by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids
652
                ])
6855.4.1 by Jelmer Vernooij
Yet more bees.
653
        self.tree1.commit('add whitespace', rev_id=b'a@cset-0-2')
0.5.80 by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go.
654
6973.7.8 by Jelmer Vernooij
Fix more tests.
655
        bundle = self.get_valid_bundle(b'a@cset-0-1', b'a@cset-0-2')
0.5.117 by John Arbash Meinel
Almost there. Just need to track down a few remaining bugs.
656
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
657
        # Check a rollup bundle
6973.7.10 by Jelmer Vernooij
More fixes.
658
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-2')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
659
660
        # Now delete entries
1185.82.21 by Aaron Bentley
Stop using deprecated function
661
        self.tree1.remove(
0.5.118 by John Arbash Meinel
Got most of test_changeset to work. Still needs work for Aaron's test code.
662
                ['sub/sub/nonempty.txt'
0.5.84 by John Arbash Meinel
(broken) problem with removes.
663
                , 'sub/sub/emptyfile.txt'
0.5.118 by John Arbash Meinel
Got most of test_changeset to work. Still needs work for Aaron's test code.
664
                , 'sub/sub'
665
                ])
1185.82.68 by Aaron Bentley
Handle execute bit on modified files
666
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
667
        trans_id = tt.trans_id_tree_path('executable')
1185.82.68 by Aaron Bentley
Handle execute bit on modified files
668
        tt.set_executability(False, trans_id)
669
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
670
        self.tree1.commit('removed', rev_id=b'a@cset-0-3')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
671
6973.7.8 by Jelmer Vernooij
Fix more tests.
672
        bundle = self.get_valid_bundle(b'a@cset-0-2', b'a@cset-0-3')
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
673
        self.assertRaises((errors.TestamentMismatch,
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
674
            errors.VersionedFileInvalidChecksum,
675
            errors.BadBundle), self.get_invalid_bundle,
6973.7.8 by Jelmer Vernooij
Fix more tests.
676
            b'a@cset-0-2', b'a@cset-0-3')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
677
        # Check a rollup bundle
6973.7.8 by Jelmer Vernooij
Fix more tests.
678
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-3')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
679
680
        # Now move the directory
1185.82.19 by Aaron Bentley
More API updates
681
        self.tree1.rename_one('dir', 'sub/dir')
6855.4.1 by Jelmer Vernooij
Yet more bees.
682
        self.tree1.commit('rename dir', rev_id=b'a@cset-0-4')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
683
6973.7.8 by Jelmer Vernooij
Fix more tests.
684
        bundle = self.get_valid_bundle(b'a@cset-0-3', b'a@cset-0-4')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
685
        # Check a rollup bundle
6973.7.8 by Jelmer Vernooij
Fix more tests.
686
        bundle = self.get_valid_bundle(b'null:', b'a@cset-0-4')
0.5.84 by John Arbash Meinel
(broken) problem with removes.
687
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
688
        # Modified files
6973.7.5 by Jelmer Vernooij
s/file/open.
689
        with open('b1/sub/dir/WithCaps.txt', 'ab') as f: f.write(b'\nAdding some text\n')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
690
        with open('b1/sub/dir/ pre space', 'ab') as f: f.write(
6973.7.5 by Jelmer Vernooij
s/file/open.
691
             b'\r\nAdding some\r\nDOS format lines\r\n')
692
        with open('b1/sub/dir/nolastnewline.txt', 'ab') as f: f.write(b'\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
693
        self.tree1.rename_one('sub/dir/ pre space',
1711.7.32 by John Arbash Meinel
Switch from a trailing space to a beginning space, which is supported everywhere.
694
                              'sub/ start space')
6855.4.1 by Jelmer Vernooij
Yet more bees.
695
        self.tree1.commit('Modified files', rev_id=b'a@cset-0-5')
6973.7.8 by Jelmer Vernooij
Fix more tests.
696
        bundle = self.get_valid_bundle(b'a@cset-0-4', b'a@cset-0-5')
0.5.87 by John Arbash Meinel
Handling international characters, added more test cases.
697
1185.82.70 by Aaron Bentley
Handle renamed files better
698
        self.tree1.rename_one('sub/dir/WithCaps.txt', 'temp')
699
        self.tree1.rename_one('with space.txt', 'WithCaps.txt')
700
        self.tree1.rename_one('temp', 'with space.txt')
6855.4.1 by Jelmer Vernooij
Yet more bees.
701
        self.tree1.commit(u'swap filenames', rev_id=b'a@cset-0-6',
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
702
                          verbose=False)
6973.7.8 by Jelmer Vernooij
Fix more tests.
703
        bundle = self.get_valid_bundle(b'a@cset-0-5', b'a@cset-0-6')
704
        other = self.get_checkout(b'a@cset-0-5')
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
705
        tree1_inv = get_inventory_text(self.tree1.branch.repository,
6973.7.8 by Jelmer Vernooij
Fix more tests.
706
                                       b'a@cset-0-5')
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
707
        tree2_inv = get_inventory_text(other.branch.repository,
6973.7.8 by Jelmer Vernooij
Fix more tests.
708
                                       b'a@cset-0-5')
1910.2.54 by Aaron Bentley
Implement testament format 3 strict
709
        self.assertEqualDiff(tree1_inv, tree2_inv)
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
710
        other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
6855.4.1 by Jelmer Vernooij
Yet more bees.
711
        other.commit('rename file', rev_id=b'a@cset-0-6b')
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
712
        self.tree1.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
713
        self.tree1.commit(u'Merge', rev_id=b'a@cset-0-7',
1185.82.70 by Aaron Bentley
Handle renamed files better
714
                          verbose=False)
6973.7.8 by Jelmer Vernooij
Fix more tests.
715
        bundle = self.get_valid_bundle(b'a@cset-0-6', b'a@cset-0-7')
1185.82.72 by Aaron Bentley
Always use leftmost base for changesets
716
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
717
    def _test_symlink_bundle(self, link_name, link_target, new_link_target):
6973.7.8 by Jelmer Vernooij
Fix more tests.
718
        link_id = b'link-1'
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
719
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
720
        self.requireFeature(features.SymlinkFeature)
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
721
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.87 by Aaron Bentley
Got symlink adding working
722
        self.b1 = self.tree1.branch
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
723
1185.82.87 by Aaron Bentley
Got symlink adding working
724
        tt = TreeTransform(self.tree1)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
725
        tt.new_symlink(link_name, tt.root, link_target, link_id)
1185.82.87 by Aaron Bentley
Got symlink adding working
726
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
727
        self.tree1.commit('add symlink', rev_id=b'l@cset-0-1')
6973.7.8 by Jelmer Vernooij
Fix more tests.
728
        bundle = self.get_valid_bundle(b'null:', b'l@cset-0-1')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
729
        if getattr(bundle, 'revision_tree', None) is not None:
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
730
            # Not all bundle formats supports revision_tree
6973.7.8 by Jelmer Vernooij
Fix more tests.
731
            bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-1')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
732
            self.assertEqual(link_target, bund_tree.get_symlink_target(link_name))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
733
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
734
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
735
        trans_id = tt.trans_id_tree_path(link_name)
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
736
        tt.adjust_path('link2', tt.root, trans_id)
737
        tt.delete_contents(trans_id)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
738
        tt.create_symlink(new_link_target, trans_id)
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
739
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
740
        self.tree1.commit('rename and change symlink', rev_id=b'l@cset-0-2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
741
        bundle = self.get_valid_bundle(b'l@cset-0-1', b'l@cset-0-2')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
742
        if getattr(bundle, 'revision_tree', None) is not None:
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
743
            # Not all bundle formats supports revision_tree
6973.7.8 by Jelmer Vernooij
Fix more tests.
744
            bund_tree = bundle.revision_tree(self.b1.repository, b'l@cset-0-2')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
745
            self.assertEqual(new_link_target,
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
746
                             bund_tree.get_symlink_target('link2'))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
747
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
748
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
749
        trans_id = tt.trans_id_tree_path('link2')
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
750
        tt.delete_contents(trans_id)
751
        tt.create_symlink('jupiter', trans_id)
752
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
753
        self.tree1.commit('just change symlink target', rev_id=b'l@cset-0-3')
6973.7.8 by Jelmer Vernooij
Fix more tests.
754
        bundle = self.get_valid_bundle(b'l@cset-0-2', b'l@cset-0-3')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
755
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
756
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
757
        trans_id = tt.trans_id_tree_path('link2')
1185.82.88 by Aaron Bentley
Get symlink modification, renames and deletion under test
758
        tt.delete_contents(trans_id)
759
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
760
        self.tree1.commit('Delete symlink', rev_id=b'l@cset-0-4')
6973.7.8 by Jelmer Vernooij
Fix more tests.
761
        bundle = self.get_valid_bundle(b'l@cset-0-3', b'l@cset-0-4')
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
762
763
    def test_symlink_bundle(self):
764
        self._test_symlink_bundle('link', 'bar/foo', 'mars')
765
766
    def test_unicode_symlink_bundle(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
767
        self.requireFeature(features.UnicodeFilenameFeature)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
768
        self._test_symlink_bundle(u'\N{Euro Sign}link',
769
                                  u'bar/\N{Euro Sign}foo',
770
                                  u'mars\N{Euro Sign}')
1185.82.96 by Aaron Bentley
Got first binary test passing
771
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
772
    def test_binary_bundle(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
773
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.96 by Aaron Bentley
Got first binary test passing
774
        self.b1 = self.tree1.branch
775
        tt = TreeTransform(self.tree1)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
776
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
777
        # Add
6973.7.10 by Jelmer Vernooij
More fixes.
778
        tt.new_file('file', tt.root, [b'\x00\n\x00\r\x01\n\x02\r\xff'], b'binary-1')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
779
        tt.new_file('file2', tt.root, [b'\x01\n\x02\r\x03\n\x04\r\xff'],
6973.7.10 by Jelmer Vernooij
More fixes.
780
            b'binary-2')
1185.82.96 by Aaron Bentley
Got first binary test passing
781
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
782
        self.tree1.commit('add binary', rev_id=b'b@cset-0-1')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
783
        self.get_valid_bundle(b'null:', b'b@cset-0-1')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
784
785
        # Delete
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
786
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
787
        trans_id = tt.trans_id_tree_path('file')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
788
        tt.delete_contents(trans_id)
789
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
790
        self.tree1.commit('delete binary', rev_id=b'b@cset-0-2')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
791
        self.get_valid_bundle(b'b@cset-0-1', b'b@cset-0-2')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
792
793
        # Rename & modify
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
794
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
795
        trans_id = tt.trans_id_tree_path('file2')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
796
        tt.adjust_path('file3', tt.root, trans_id)
797
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
798
        tt.create_file([b'file\rcontents\x00\n\x00'], trans_id)
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
799
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
800
        self.tree1.commit('rename and modify binary', rev_id=b'b@cset-0-3')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
801
        self.get_valid_bundle(b'b@cset-0-2', b'b@cset-0-3')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
802
803
        # Modify
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
804
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
805
        trans_id = tt.trans_id_tree_path('file3')
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
806
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
807
        tt.create_file([b'\x00file\rcontents'], trans_id)
1185.82.97 by Aaron Bentley
Got binary files working for adds, renames, modifications
808
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
809
        self.tree1.commit('just modify binary', rev_id=b'b@cset-0-4')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
810
        self.get_valid_bundle(b'b@cset-0-3', b'b@cset-0-4')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
811
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
812
        # Rollup
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
813
        self.get_valid_bundle(b'null:', b'b@cset-0-4')
1848.1.1 by John Arbash Meinel
fix bug in bundle handling of binary files with just '\r' in them.
814
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
815
    def test_last_modified(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
816
        self.tree1 = self.make_branch_and_tree('b1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
817
        self.b1 = self.tree1.branch
818
        tt = TreeTransform(self.tree1)
6973.7.10 by Jelmer Vernooij
More fixes.
819
        tt.new_file('file', tt.root, [b'file'], b'file')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
820
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
821
        self.tree1.commit('create file', rev_id=b'a@lmod-0-1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
822
823
        tt = TreeTransform(self.tree1)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
824
        trans_id = tt.trans_id_tree_path('file')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
825
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
826
        tt.create_file([b'file2'], trans_id)
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
827
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
828
        self.tree1.commit('modify text', rev_id=b'a@lmod-0-2a')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
829
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
830
        other = self.get_checkout(b'a@lmod-0-1')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
831
        tt = TreeTransform(other)
6885.1.1 by Jelmer Vernooij
Get rid of TreeTransform.trans_id_tree_file_id.
832
        trans_id = tt.trans_id_tree_path('file2')
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
833
        tt.delete_contents(trans_id)
6973.7.10 by Jelmer Vernooij
More fixes.
834
        tt.create_file([b'file2'], trans_id)
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
835
        tt.apply()
6855.4.1 by Jelmer Vernooij
Yet more bees.
836
        other.commit('modify text in another tree', rev_id=b'a@lmod-0-2b')
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
837
        self.tree1.merge_from_branch(other.branch)
6855.4.1 by Jelmer Vernooij
Yet more bees.
838
        self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-3',
1185.82.115 by Aaron Bentley
Add test for last-changed special cases
839
                          verbose=False)
6855.4.1 by Jelmer Vernooij
Yet more bees.
840
        self.tree1.commit(u'Merge', rev_id=b'a@lmod-0-4')
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
841
        bundle = self.get_valid_bundle(b'a@lmod-0-2a', b'a@lmod-0-4')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
842
843
    def test_hide_history(self):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
844
        self.tree1 = self.make_branch_and_tree('b1')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
845
        self.b1 = self.tree1.branch
846
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
847
        with open('b1/one', 'wb') as f: f.write(b'one\n')
1185.84.3 by Aaron Bentley
Hide diffs for old revisions in bundles
848
        self.tree1.add('one')
6855.4.1 by Jelmer Vernooij
Yet more bees.
849
        self.tree1.commit('add file', rev_id=b'a@cset-0-1')
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
850
        with open('b1/one', 'wb') as f: f.write(b'two\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
851
        self.tree1.commit('modify', rev_id=b'a@cset-0-2')
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
852
        with open('b1/one', 'wb') as f: f.write(b'three\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
853
        self.tree1.commit('modify', rev_id=b'a@cset-0-3')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
854
        bundle_file = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
855
        rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-3',
856
                               b'a@cset-0-1', bundle_file, format=self.format)
857
        self.assertNotContainsRe(bundle_file.getvalue(), b'\btwo\b')
858
        self.assertContainsRe(self.get_raw(bundle_file), b'one')
859
        self.assertContainsRe(self.get_raw(bundle_file), b'three')
2520.4.32 by Aaron Bentley
Fix test case
860
2520.4.75 by Aaron Bentley
Fix traceback on empty bundles.
861
    def test_bundle_same_basis(self):
862
        """Ensure using the basis as the target doesn't cause an error"""
863
        self.tree1 = self.make_branch_and_tree('b1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
864
        self.tree1.commit('add file', rev_id=b'a@cset-0-1')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
865
        bundle_file = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
866
        rev_ids = write_bundle(self.tree1.branch.repository, b'a@cset-0-1',
867
                               b'a@cset-0-1', bundle_file)
2520.4.75 by Aaron Bentley
Fix traceback on empty bundles.
868
2520.4.32 by Aaron Bentley
Fix test case
869
    @staticmethod
870
    def get_raw(bundle_file):
871
        return bundle_file.getvalue()
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
872
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
873
    def test_unicode_bundle(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
874
        self.requireFeature(features.UnicodeFilenameFeature)
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
875
        # Handle international characters
876
        os.mkdir('b1')
4241.14.13 by Vincent Ladeuil
Some more cleanup.
877
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
878
879
        self.tree1 = self.make_branch_and_tree('b1')
880
        self.b1 = self.tree1.branch
881
882
        f.write((u'A file\n'
883
            u'With international man of mystery\n'
884
            u'William Dod\xe9\n').encode('utf-8'))
885
        f.close()
886
6855.4.1 by Jelmer Vernooij
Yet more bees.
887
        self.tree1.add([u'with Dod\N{Euro Sign}'], [b'withdod-id'])
2386.1.1 by John Arbash Meinel
Update test_unicode_bundle, since we know how it fails on Mac OSX
888
        self.tree1.commit(u'i18n commit from William Dod\xe9',
6855.4.1 by Jelmer Vernooij
Yet more bees.
889
                          rev_id=b'i18n-1', committer=u'William Dod\xe9')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
890
891
        # Add
6973.7.10 by Jelmer Vernooij
More fixes.
892
        bundle = self.get_valid_bundle(b'null:', b'i18n-1')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
893
894
        # Modified
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
895
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
896
        f.write(u'Modified \xb5\n'.encode('utf8'))
897
        f.close()
6855.4.1 by Jelmer Vernooij
Yet more bees.
898
        self.tree1.commit(u'modified', rev_id=b'i18n-2')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
899
6973.7.10 by Jelmer Vernooij
More fixes.
900
        bundle = self.get_valid_bundle(b'i18n-1', b'i18n-2')
3638.3.16 by Vincent Ladeuil
Remove XFAIL from test_unicode_bundle.
901
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
902
        # Renamed
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
903
        self.tree1.rename_one(u'with Dod\N{Euro Sign}', u'B\N{Euro Sign}gfors')
6855.4.1 by Jelmer Vernooij
Yet more bees.
904
        self.tree1.commit(u'renamed, the new i18n man', rev_id=b'i18n-3',
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
905
                          committer=u'Erik B\xe5gfors')
906
6973.7.10 by Jelmer Vernooij
More fixes.
907
        bundle = self.get_valid_bundle(b'i18n-2', b'i18n-3')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
908
909
        # Removed
3638.3.18 by Vincent Ladeuil
Fixed as per jam's review.
910
        self.tree1.remove([u'B\N{Euro Sign}gfors'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
911
        self.tree1.commit(u'removed', rev_id=b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
912
6973.7.10 by Jelmer Vernooij
More fixes.
913
        bundle = self.get_valid_bundle(b'i18n-3', b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
914
915
        # Rollup
6973.7.10 by Jelmer Vernooij
More fixes.
916
        bundle = self.get_valid_bundle(b'null:', b'i18n-4')
1711.7.35 by John Arbash Meinel
Factor out i18n bundle tests, so we don't always skip.
917
918
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
919
    def test_whitespace_bundle(self):
920
        if sys.platform in ('win32', 'cygwin'):
4241.14.13 by Vincent Ladeuil
Some more cleanup.
921
            raise tests.TestSkipped('Windows doesn\'t support filenames'
922
                                    ' with tabs or trailing spaces')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
923
        self.tree1 = self.make_branch_and_tree('b1')
924
        self.b1 = self.tree1.branch
925
926
        self.build_tree(['b1/trailing space '])
927
        self.tree1.add(['trailing space '])
928
        # TODO: jam 20060701 Check for handling files with '\t' characters
929
        #       once we actually support them
930
931
        # Added
6855.4.1 by Jelmer Vernooij
Yet more bees.
932
        self.tree1.commit('funky whitespace', rev_id=b'white-1')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
933
6973.7.10 by Jelmer Vernooij
More fixes.
934
        bundle = self.get_valid_bundle(b'null:', b'white-1')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
935
936
        # Modified
6973.7.5 by Jelmer Vernooij
s/file/open.
937
        with open('b1/trailing space ', 'ab') as f: f.write(b'add some text\n')
6855.4.1 by Jelmer Vernooij
Yet more bees.
938
        self.tree1.commit('add text', rev_id=b'white-2')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
939
6973.7.10 by Jelmer Vernooij
More fixes.
940
        bundle = self.get_valid_bundle(b'white-1', b'white-2')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
941
942
        # Renamed
943
        self.tree1.rename_one('trailing space ', ' start and end space ')
6855.4.1 by Jelmer Vernooij
Yet more bees.
944
        self.tree1.commit('rename', rev_id=b'white-3')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
945
6973.7.10 by Jelmer Vernooij
More fixes.
946
        bundle = self.get_valid_bundle(b'white-2', b'white-3')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
947
948
        # Removed
949
        self.tree1.remove([' start and end space '])
6855.4.1 by Jelmer Vernooij
Yet more bees.
950
        self.tree1.commit('removed', rev_id=b'white-4')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
951
6973.7.10 by Jelmer Vernooij
More fixes.
952
        bundle = self.get_valid_bundle(b'white-3', b'white-4')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
953
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
954
        # Now test a complet roll-up
6973.7.10 by Jelmer Vernooij
More fixes.
955
        bundle = self.get_valid_bundle(b'null:', b'white-4')
1711.7.34 by John Arbash Meinel
Include a test to ensure bundles handle trailing whitespace.
956
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
957
    def test_alt_timezone_bundle(self):
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
958
        self.tree1 = self.make_branch_and_memory_tree('b1')
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
959
        self.b1 = self.tree1.branch
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
960
        builder = treebuilder.TreeBuilder()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
961
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
962
        self.tree1.lock_write()
963
        builder.start_tree(self.tree1)
964
        builder.build(['newfile'])
965
        builder.finish_tree()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
966
967
        # Asia/Colombo offset = 5 hours 30 minutes
6855.4.1 by Jelmer Vernooij
Yet more bees.
968
        self.tree1.commit('non-hour offset timezone', rev_id=b'tz-1',
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
969
                          timezone=19800, timestamp=1152544886.0)
970
6973.7.10 by Jelmer Vernooij
More fixes.
971
        bundle = self.get_valid_bundle(b'null:', b'tz-1')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
972
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
973
        rev = bundle.revisions[0]
974
        self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
975
        self.assertEqual(19800, rev.timezone)
976
        self.assertEqual(1152544886.0, rev.timestamp)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
977
        self.tree1.unlock()
1793.3.9 by John Arbash Meinel
Add a test to timezone for non integer tz offsets
978
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
979
    def test_bundle_root_id(self):
980
        self.tree1 = self.make_branch_and_tree('b1')
981
        self.b1 = self.tree1.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
982
        self.tree1.commit('message', rev_id=b'revid1')
6973.7.8 by Jelmer Vernooij
Fix more tests.
983
        bundle = self.get_valid_bundle(b'null:', b'revid1')
984
        tree = self.get_bundle_tree(bundle, b'revid1')
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
985
        root_revision = tree.get_file_revision(u'', tree.get_root_id())
6973.7.10 by Jelmer Vernooij
More fixes.
986
        self.assertEqual(b'revid1', root_revision)
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
987
1551.14.9 by Aaron Bentley
rename get_target_revision to install_revisions
988
    def test_install_revisions(self):
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
989
        self.tree1 = self.make_branch_and_tree('b1')
990
        self.b1 = self.tree1.branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
991
        self.tree1.commit('message', rev_id=b'rev2a')
6973.5.2 by Jelmer Vernooij
Add more bees.
992
        bundle = self.get_valid_bundle(b'null:', b'rev2a')
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
993
        branch2 = self.make_branch('b2')
6973.5.2 by Jelmer Vernooij
Add more bees.
994
        self.assertFalse(branch2.repository.has_revision(b'rev2a'))
1551.14.9 by Aaron Bentley
rename get_target_revision to install_revisions
995
        target_revision = bundle.install_revisions(branch2.repository)
6973.5.2 by Jelmer Vernooij
Add more bees.
996
        self.assertTrue(branch2.repository.has_revision(b'rev2a'))
997
        self.assertEqual(b'rev2a', target_revision)
1551.14.4 by Aaron Bentley
Change bundle reader and merge directive to both be 'mergeables'
998
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
999
    def test_bundle_empty_property(self):
1000
        """Test serializing revision properties with an empty value."""
1001
        tree = self.make_branch_and_memory_tree('tree')
1002
        tree.lock_write()
1003
        self.addCleanup(tree.unlock)
6973.5.2 by Jelmer Vernooij
Add more bees.
1004
        tree.add([''], [b'TREE_ROOT'])
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1005
        tree.commit('One', revprops={u'one': 'two', u'empty': ''}, rev_id=b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1006
        self.b1 = tree.branch
6973.5.2 by Jelmer Vernooij
Add more bees.
1007
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1008
        bundle = read_bundle(bundle_sio)
1009
        revision_info = bundle.revisions[0]
6973.5.2 by Jelmer Vernooij
Add more bees.
1010
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1011
        rev = revision_info.as_revision()
1012
        self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
1013
                         rev.properties)
1014
1015
    def test_bundle_sorted_properties(self):
1016
        """For stability the writer should write properties in sorted order."""
1017
        tree = self.make_branch_and_memory_tree('tree')
1018
        tree.lock_write()
1019
        self.addCleanup(tree.unlock)
1020
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1021
        tree.add([''], [b'TREE_ROOT'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1022
        tree.commit('One', rev_id=b'rev1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1023
                    revprops={u'a':'4', u'b':'3', u'c':'2', u'd':'1'})
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1024
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1025
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1026
        bundle = read_bundle(bundle_sio)
1027
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1028
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1029
        rev = revision_info.as_revision()
1030
        self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
1031
                          'd':'1'}, rev.properties)
1032
1033
    def test_bundle_unicode_properties(self):
1034
        """We should be able to round trip a non-ascii property."""
1035
        tree = self.make_branch_and_memory_tree('tree')
1036
        tree.lock_write()
1037
        self.addCleanup(tree.unlock)
1038
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1039
        tree.add([''], [b'TREE_ROOT'])
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1040
        # Revisions themselves do not require anything about revision property
1041
        # keys, other than that they are a basestring, and do not contain
1042
        # whitespace.
1043
        # However, Testaments assert than they are str(), and thus should not
1044
        # be Unicode.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1045
        tree.commit('One', rev_id=b'rev1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1046
                    revprops={u'omega':u'\u03a9', u'alpha':u'\u03b1'})
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1047
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1048
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1049
        bundle = read_bundle(bundle_sio)
1050
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1051
        self.assertEqual(b'rev1', revision_info.revision_id)
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1052
        rev = revision_info.as_revision()
1053
        self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1054
                          'alpha':u'\u03b1'}, rev.properties)
1055
2520.4.43 by Aaron Bentley
Fix test suite
1056
    def test_bundle_with_ghosts(self):
1057
        tree = self.make_branch_and_tree('tree')
1058
        self.b1 = tree.branch
6855.3.1 by Jelmer Vernooij
Several more fixes.
1059
        self.build_tree_contents([('tree/file', b'content1')])
2520.4.43 by Aaron Bentley
Fix test suite
1060
        tree.add(['file'])
1061
        tree.commit('rev1')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1062
        self.build_tree_contents([('tree/file', b'content2')])
1063
        tree.add_parent_tree_id(b'ghost')
1064
        tree.commit('rev2', rev_id=b'rev2')
1065
        bundle = self.get_valid_bundle(b'null:', b'rev2')
2520.4.43 by Aaron Bentley
Fix test suite
1066
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1067
    def make_simple_tree(self, format=None):
1068
        tree = self.make_branch_and_tree('b1', format=format)
1069
        self.b1 = tree.branch
1070
        self.build_tree(['b1/file'])
1071
        tree.add('file')
1072
        return tree
1073
1074
    def test_across_serializers(self):
1075
        tree = self.make_simple_tree('knit')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1076
        tree.commit('hello', rev_id=b'rev1')
1077
        tree.commit('hello', rev_id=b'rev2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1078
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1079
        repo = self.make_repository('repo', format='dirstate-with-subtree')
1080
        bundle.install_revisions(repo)
6973.7.10 by Jelmer Vernooij
More fixes.
1081
        inv_text = repo._get_inventory_xml(b'rev2')
1082
        self.assertNotContainsRe(inv_text, b'format="5"')
1083
        self.assertContainsRe(inv_text, b'format="7"')
2520.4.99 by Aaron Bentley
Test conversion across models
1084
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1085
    def make_repo_with_installed_revisions(self):
1086
        tree = self.make_simple_tree('knit')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1087
        tree.commit('hello', rev_id=b'rev1')
1088
        tree.commit('hello', rev_id=b'rev2')
6973.5.2 by Jelmer Vernooij
Add more bees.
1089
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1090
        repo = self.make_repository('repo', format='dirstate-with-subtree')
1091
        bundle.install_revisions(repo)
1092
        return repo
1093
2520.4.99 by Aaron Bentley
Test conversion across models
1094
    def test_across_models(self):
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1095
        repo = self.make_repo_with_installed_revisions()
6973.5.2 by Jelmer Vernooij
Add more bees.
1096
        inv = repo.get_inventory(b'rev2')
1097
        self.assertEqual(b'rev2', inv.root.revision)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1098
        root_id = inv.root.file_id
1099
        repo.lock_read()
1100
        self.addCleanup(repo.unlock)
6973.5.2 by Jelmer Vernooij
Add more bees.
1101
        self.assertEqual({(root_id, b'rev1'):(),
1102
            (root_id, b'rev2'):((root_id, b'rev1'),)},
1103
            repo.texts.get_parent_map([(root_id, b'rev1'), (root_id, b'rev2')]))
2520.4.99 by Aaron Bentley
Test conversion across models
1104
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1105
    def test_inv_hash_across_serializers(self):
1106
        repo = self.make_repo_with_installed_revisions()
6973.5.2 by Jelmer Vernooij
Add more bees.
1107
        recorded_inv_sha1 = repo.get_revision(b'rev2').inventory_sha1
1108
        xml = repo._get_inventory_xml(b'rev2')
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1109
        self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
3380.1.8 by Aaron Bentley
Test that the stored inventory hash is correct when bundles are used
1110
2520.4.99 by Aaron Bentley
Test conversion across models
1111
    def test_across_models_incompatible(self):
1112
        tree = self.make_simple_tree('dirstate-with-subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1113
        tree.commit('hello', rev_id=b'rev1')
1114
        tree.commit('hello', rev_id=b'rev2')
2520.4.99 by Aaron Bentley
Test conversion across models
1115
        try:
6973.7.8 by Jelmer Vernooij
Fix more tests.
1116
            bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.4.99 by Aaron Bentley
Test conversion across models
1117
        except errors.IncompatibleBundleFormat:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1118
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
2520.4.99 by Aaron Bentley
Test conversion across models
1119
        repo = self.make_repository('repo', format='knit')
1120
        bundle.install_revisions(repo)
1121
6973.7.8 by Jelmer Vernooij
Fix more tests.
1122
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev2')[0])
2520.4.99 by Aaron Bentley
Test conversion across models
1123
        self.assertRaises(errors.IncompatibleRevision,
1124
                          bundle.install_revisions, repo)
2520.4.97 by Aaron Bentley
Hack in support for inventory conversion
1125
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1126
    def test_get_merge_request(self):
1127
        tree = self.make_simple_tree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
1128
        tree.commit('hello', rev_id=b'rev1')
1129
        tree.commit('hello', rev_id=b'rev2')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1130
        bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1131
        result = bundle.get_merge_request(tree.branch.repository)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1132
        self.assertEqual((None, b'rev1', 'inapplicable'), result)
2520.4.109 by Aaron Bentley
start work on directive cherry-picking
1133
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1134
    def test_with_subtree(self):
1135
        tree = self.make_branch_and_tree('tree',
1136
                                         format='dirstate-with-subtree')
1137
        self.b1 = tree.branch
1138
        subtree = self.make_branch_and_tree('tree/subtree',
1139
                                            format='dirstate-with-subtree')
1140
        tree.add('subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1141
        tree.commit('hello', rev_id=b'rev1')
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1142
        try:
6973.7.8 by Jelmer Vernooij
Fix more tests.
1143
            bundle = read_bundle(self.create_bundle_text(b'null:', b'rev1')[0])
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1144
        except errors.IncompatibleBundleFormat:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1145
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1146
        if isinstance(bundle, v09.BundleInfo09):
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1147
            raise tests.TestSkipped("Format 0.9 doesn't work with subtrees")
2520.5.1 by Aaron Bentley
Test installing revisions with subtrees
1148
        repo = self.make_repository('repo', format='knit')
1149
        self.assertRaises(errors.IncompatibleRevision,
1150
                          bundle.install_revisions, repo)
1151
        repo2 = self.make_repository('repo2', format='dirstate-with-subtree')
1152
        bundle.install_revisions(repo2)
1153
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1154
    def test_revision_id_with_slash(self):
1155
        self.tree1 = self.make_branch_and_tree('tree')
1156
        self.b1 = self.tree1.branch
1157
        try:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1158
            self.tree1.commit('Revision/id/with/slashes', rev_id=b'rev/id')
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1159
        except ValueError:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1160
            raise tests.TestSkipped(
1161
                "Repository doesn't support revision ids with slashes")
6973.7.8 by Jelmer Vernooij
Fix more tests.
1162
        bundle = self.get_valid_bundle(b'null:', b'rev/id')
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1163
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1164
    def test_skip_file(self):
1165
        """Make sure we don't accidentally write to the wrong versionedfile"""
1166
        self.tree1 = self.make_branch_and_tree('tree')
1167
        self.b1 = self.tree1.branch
1168
        # rev1 is not present in bundle, done by fetch
6855.4.1 by Jelmer Vernooij
Yet more bees.
1169
        self.build_tree_contents([('tree/file2', b'contents1')])
1170
        self.tree1.add('file2', b'file2-id')
1171
        self.tree1.commit('rev1', rev_id=b'reva')
1172
        self.build_tree_contents([('tree/file3', b'contents2')])
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1173
        # rev2 is present in bundle, and done by fetch
1174
        # having file1 in the bunle causes file1's versionedfile to be opened.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1175
        self.tree1.add('file3', b'file3-id')
7058.3.5 by Jelmer Vernooij
Fix flappy skip_file test.
1176
        rev2 = self.tree1.commit('rev2')
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1177
        # Updating file2 should not cause an attempt to add to file1's vf
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1178
        target = self.tree1.controldir.sprout('target').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
1179
        self.build_tree_contents([('tree/file2', b'contents3')])
1180
        self.tree1.commit('rev3', rev_id=b'rev3')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1181
        bundle = self.get_valid_bundle(b'reva', b'rev3')
2520.6.5 by Aaron Bentley
Skip for bundle formats that don't provide get_bundle_reader
1182
        if getattr(bundle, 'get_bundle_reader', None) is None:
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1183
            raise tests.TestSkipped('Bundle format cannot provide reader')
7058.3.5 by Jelmer Vernooij
Fix flappy skip_file test.
1184
        file_ids = set(
1185
            (f, r) for b, m, k, r, f in bundle.get_bundle_reader().iter_records()
1186
            if f is not None)
1187
        self.assertEqual({(b'file2-id', b'rev3'), (b'file3-id', rev2)}, file_ids)
2520.6.2 by Aaron Bentley
Fix bundle installation wrong-versionedfile bug
1188
        bundle.install_revisions(target.branch.repository)
1189
2520.4.43 by Aaron Bentley
Fix test suite
1190
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1191
class V08BundleTester(BundleTester, tests.TestCaseWithTransport):
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1192
1193
    format = '0.8'
1194
1195
    def test_bundle_empty_property(self):
1196
        """Test serializing revision properties with an empty value."""
1197
        tree = self.make_branch_and_memory_tree('tree')
1198
        tree.lock_write()
1199
        self.addCleanup(tree.unlock)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1200
        tree.add([''], [b'TREE_ROOT'])
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1201
        tree.commit('One', revprops={u'one':'two', u'empty':''}, rev_id=b'rev1')
2520.4.33 by Aaron Bentley
remove test dependencies on serialization minutia
1202
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1203
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1204
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1205
                              b'# properties:\n'
1206
                              b'#   branch-nick: tree\n'
1207
                              b'#   empty: \n'
1208
                              b'#   one: two\n'
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1209
                             )
1210
        bundle = read_bundle(bundle_sio)
1211
        revision_info = bundle.revisions[0]
7045.2.14 by Jelmer Vernooij
Fix some bundle tests.:
1212
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1213
        rev = revision_info.as_revision()
1214
        self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
1215
                         rev.properties)
1216
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1217
    def get_bundle_tree(self, bundle, revision_id):
1218
        repository = self.make_repository('repo')
6973.7.8 by Jelmer Vernooij
Fix more tests.
1219
        return bundle.revision_tree(repository, b'revid1')
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1220
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1221
    def test_bundle_empty_property_alt(self):
2447.1.3 by John Arbash Meinel
Change the default serializer to include a trailing whitespace for empty properties.
1222
        """Test serializing revision properties with an empty value.
1223
1224
        Older readers had a bug when reading an empty property.
1225
        They assumed that all keys ended in ': \n'. However they would write an
1226
        empty value as ':\n'. This tests make sure that all newer bzr versions
1227
        can handle th second form.
1228
        """
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1229
        tree = self.make_branch_and_memory_tree('tree')
1230
        tree.lock_write()
1231
        self.addCleanup(tree.unlock)
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1232
        tree.add([''], [b'TREE_ROOT'])
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1233
        tree.commit('One', revprops={u'one':'two', u'empty':''}, rev_id=b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1234
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1235
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1236
        txt = bundle_sio.getvalue()
6973.7.10 by Jelmer Vernooij
More fixes.
1237
        loc = txt.find(b'#   empty: ') + len(b'#   empty:')
2447.1.3 by John Arbash Meinel
Change the default serializer to include a trailing whitespace for empty properties.
1238
        # Create a new bundle, which strips the trailing space after empty
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1239
        bundle_sio = BytesIO(txt[:loc] + txt[loc+1:])
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1240
1241
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1242
                              b'# properties:\n'
1243
                              b'#   branch-nick: tree\n'
1244
                              b'#   empty:\n'
1245
                              b'#   one: two\n'
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1246
                             )
1247
        bundle = read_bundle(bundle_sio)
1248
        revision_info = bundle.revisions[0]
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
1249
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.2 by John Arbash Meinel
Add tests that we handle empty values whether they end in ': \n' or ':\n'.
1250
        rev = revision_info.as_revision()
1251
        self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
1252
                         rev.properties)
1253
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1254
    def test_bundle_sorted_properties(self):
1255
        """For stability the writer should write properties in sorted order."""
1256
        tree = self.make_branch_and_memory_tree('tree')
1257
        tree.lock_write()
1258
        self.addCleanup(tree.unlock)
1259
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1260
        tree.add([''], [b'TREE_ROOT'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1261
        tree.commit('One', rev_id=b'rev1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1262
                    revprops={u'a':'4', u'b':'3', u'c':'2', u'd':'1'})
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1263
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1264
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1265
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1266
                              b'# properties:\n'
1267
                              b'#   a: 4\n'
1268
                              b'#   b: 3\n'
1269
                              b'#   branch-nick: tree\n'
1270
                              b'#   c: 2\n'
1271
                              b'#   d: 1\n'
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1272
                             )
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1273
        bundle = read_bundle(bundle_sio)
1274
        revision_info = bundle.revisions[0]
7031.1.1 by Jelmer Vernooij
Fix breezy.tests.test_diff.
1275
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1276
        rev = revision_info.as_revision()
1277
        self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
1278
                          'd':'1'}, rev.properties)
1279
1280
    def test_bundle_unicode_properties(self):
1281
        """We should be able to round trip a non-ascii property."""
1282
        tree = self.make_branch_and_memory_tree('tree')
1283
        tree.lock_write()
1284
        self.addCleanup(tree.unlock)
1285
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
1286
        tree.add([''], [b'TREE_ROOT'])
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1287
        # Revisions themselves do not require anything about revision property
1288
        # keys, other than that they are a basestring, and do not contain
1289
        # whitespace.
1290
        # However, Testaments assert than they are str(), and thus should not
1291
        # be Unicode.
6855.4.1 by Jelmer Vernooij
Yet more bees.
1292
        tree.commit('One', rev_id=b'rev1',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1293
                    revprops={u'omega':u'\u03a9', u'alpha':u'\u03b1'})
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1294
        self.b1 = tree.branch
6973.7.8 by Jelmer Vernooij
Fix more tests.
1295
        bundle_sio, revision_ids = self.create_bundle_text(b'null:', b'rev1')
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1296
        self.assertContainsRe(bundle_sio.getvalue(),
6973.7.10 by Jelmer Vernooij
More fixes.
1297
                              b'# properties:\n'
1298
                              b'#   alpha: \xce\xb1\n'
1299
                              b'#   branch-nick: tree\n'
1300
                              b'#   omega: \xce\xa9\n'
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1301
                             )
1302
        bundle = read_bundle(bundle_sio)
1303
        revision_info = bundle.revisions[0]
6973.7.10 by Jelmer Vernooij
More fixes.
1304
        self.assertEqual(b'rev1', revision_info.revision_id)
2447.1.4 by John Arbash Meinel
Add a test that we properly round-trip unicode properties.
1305
        rev = revision_info.as_revision()
1306
        self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1307
                          'alpha':u'\u03b1'}, rev.properties)
2447.1.1 by John Arbash Meinel
For stability and ease of testing, write properties in sorted order.
1308
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1309
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1310
class V09BundleKnit2Tester(V08BundleTester):
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
1311
1312
    format = '0.9'
1313
1314
    def bzrdir_format(self):
1315
        format = bzrdir.BzrDirMetaFormat1()
2255.2.211 by Robert Collins
Remove knit2 repository format- it has never been supported.
1316
        format.repository_format = knitrepo.RepositoryFormatKnit3()
1910.2.50 by Aaron Bentley
start work on format 0.9 serializer
1317
        return format
1318
1319
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1320
class V09BundleKnit1Tester(V08BundleTester):
1321
1322
    format = '0.9'
1323
1324
    def bzrdir_format(self):
1325
        format = bzrdir.BzrDirMetaFormat1()
2241.1.6 by Martin Pool
Move Knit repositories into the submodule bzrlib.repofmt.knitrepo and
1326
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1910.2.59 by Aaron Bentley
Test 0.9 bundles for knit format1 and knit format2
1327
        return format
1328
1329
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1330
class V4BundleTester(BundleTester, tests.TestCaseWithTransport):
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1331
2520.4.136 by Aaron Bentley
Fix format strings
1332
    format = '4'
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1333
1334
    def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
1335
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1336
        Make sure that the text generated is valid, and that it
1337
        can be applied against the base, and generate the same information.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1338
1339
        :return: The in-memory bundle
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1340
        """
1341
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1342
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1343
        # This should also validate the generated bundle
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1344
        bundle = read_bundle(bundle_txt)
1345
        repository = self.b1.repository
1346
        for bundle_rev in bundle.real_revisions:
1347
            # These really should have already been checked when we read the
1348
            # bundle, since it computes the sha1 hash for the revision, which
1349
            # only will match if everything is okay, but lets be explicit about
1350
            # it
1351
            branch_rev = repository.get_revision(bundle_rev.revision_id)
1352
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1353
                      'timestamp', 'timezone', 'message', 'committer',
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1354
                      'parent_ids', 'properties'):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1355
                self.assertEqual(getattr(branch_rev, a),
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1356
                                 getattr(bundle_rev, a))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1357
            self.assertEqual(len(branch_rev.parent_ids),
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1358
                             len(bundle_rev.parent_ids))
2520.4.29 by Aaron Bentley
Reactivate some testing, fix topo_iter
1359
        self.assertEqual(set(rev_ids),
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
1360
                         {r.revision_id for r in bundle.real_revisions})
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1361
        self.valid_apply_bundle(base_rev_id, bundle,
1362
                                   checkout_dir=checkout_dir)
1363
1364
        return bundle
1365
2520.4.34 by Aaron Bentley
Add signature support
1366
    def get_invalid_bundle(self, base_rev_id, rev_id):
1367
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1368
        Munge the text so that it's invalid.
1369
1370
        :return: The in-memory bundle
1371
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1372
        from ..bundle import serializer
2520.4.34 by Aaron Bentley
Add signature support
1373
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1374
        new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
6973.7.10 by Jelmer Vernooij
More fixes.
1375
        new_text = new_text.replace(b'<file file_id="exe-1"',
1376
                                    b'<file executable="y" file_id="exe-1"')
1377
        new_text = new_text.replace(b'B260', b'B275')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1378
        bundle_txt = BytesIO()
2520.4.136 by Aaron Bentley
Fix format strings
1379
        bundle_txt.write(serializer._get_bundle_header('4'))
6973.7.5 by Jelmer Vernooij
s/file/open.
1380
        bundle_txt.write(b'\n')
6973.7.10 by Jelmer Vernooij
More fixes.
1381
        bundle_txt.write(bz2.compress(new_text))
2520.4.34 by Aaron Bentley
Add signature support
1382
        bundle_txt.seek(0)
1383
        bundle = read_bundle(bundle_txt)
1384
        self.valid_apply_bundle(base_rev_id, bundle)
1385
        return bundle
1386
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1387
    def create_bundle_text(self, base_rev_id, rev_id):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1388
        bundle_txt = BytesIO()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1389
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1390
                               bundle_txt, format=self.format)
1391
        bundle_txt.seek(0)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1392
        self.assertEqual(bundle_txt.readline(),
6973.7.8 by Jelmer Vernooij
Fix more tests.
1393
                         b'# Bazaar revision bundle v%s\n' % self.format.encode('ascii'))
1394
        self.assertEqual(bundle_txt.readline(), b'#\n')
2520.4.14 by Aaron Bentley
Get most tests passing, use format header
1395
        rev = self.b1.repository.get_revision(rev_id)
1396
        bundle_txt.seek(0)
1397
        return bundle_txt, rev_ids
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1398
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1399
    def get_bundle_tree(self, bundle, revision_id):
1400
        repository = self.make_repository('repo')
1401
        bundle.install_revisions(repository)
1402
        return repository.revision_tree(revision_id)
1403
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1404
    def test_creation(self):
1405
        tree = self.make_branch_and_tree('tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1406
        self.build_tree_contents([('tree/file', b'contents1\nstatic\n')])
6973.5.2 by Jelmer Vernooij
Add more bees.
1407
        tree.add('file', b'fileid-2')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1408
        tree.commit('added file', rev_id=b'rev1')
1409
        self.build_tree_contents([('tree/file', b'contents2\nstatic\n')])
1410
        tree.commit('changed file', rev_id=b'rev2')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1411
        s = BytesIO()
2520.4.72 by Aaron Bentley
Rename format to 4alpha
1412
        serializer = BundleSerializerV4('1.0')
7029.2.2 by Jelmer Vernooij
Fix two tests.
1413
        with tree.lock_read():
1414
            serializer.write_bundle(tree.branch.repository, b'rev2', b'null:', s)
2520.4.5 by Aaron Bentley
Start work on reading mpbundles
1415
        s.seek(0)
2520.4.6 by Aaron Bentley
Get installation started
1416
        tree2 = self.make_branch_and_tree('target')
1417
        target_repo = tree2.branch.repository
1418
        install_bundle(target_repo, serializer.read(s))
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1419
        target_repo.lock_read()
1420
        self.addCleanup(target_repo.unlock)
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1421
        # Turn the 'iterators_of_bytes' back into simple strings for comparison
6973.7.10 by Jelmer Vernooij
More fixes.
1422
        repo_texts = dict((i, b''.join(content)) for i, content
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1423
                          in target_repo.iter_files_bytes(
6973.5.2 by Jelmer Vernooij
Add more bees.
1424
                                [(b'fileid-2', b'rev1', '1'),
1425
                                 (b'fileid-2', b'rev2', '2')]))
1426
        self.assertEqual({'1':b'contents1\nstatic\n',
1427
                          '2':b'contents2\nstatic\n'},
4202.1.1 by John Arbash Meinel
Update Repository.iter_files_bytes() to return an iterable of bytestrings.
1428
                         repo_texts)
6973.5.2 by Jelmer Vernooij
Add more bees.
1429
        rtree = target_repo.revision_tree(b'rev2')
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1430
        inventory_vf = target_repo.inventories
1431
        # If the inventory store has a graph, it must match the revision graph.
1432
        self.assertSubset(
6973.5.2 by Jelmer Vernooij
Add more bees.
1433
            [inventory_vf.get_parent_map([(b'rev2',)])[(b'rev2',)]],
1434
            [None, ((b'rev1',),)])
2520.4.10 by Aaron Bentley
Enable installation of revisions
1435
        self.assertEqual('changed file',
6973.5.2 by Jelmer Vernooij
Add more bees.
1436
                         target_repo.get_revision(b'rev2').message)
2520.4.6 by Aaron Bentley
Get installation started
1437
2520.4.32 by Aaron Bentley
Fix test case
1438
    @staticmethod
1439
    def get_raw(bundle_file):
1440
        bundle_file.seek(0)
2520.4.70 by Aaron Bentley
Yank patch-handling functionality
1441
        line = bundle_file.readline()
1442
        line = bundle_file.readline()
2520.4.32 by Aaron Bentley
Fix test case
1443
        lines = bundle_file.readlines()
6973.7.10 by Jelmer Vernooij
More fixes.
1444
        return bz2.decompress(b''.join(lines))
2520.4.32 by Aaron Bentley
Fix test case
1445
2520.4.34 by Aaron Bentley
Add signature support
1446
    def test_copy_signatures(self):
1447
        tree_a = self.make_branch_and_tree('tree_a')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1448
        import breezy.gpg
1449
        import breezy.commit as commit
1450
        oldstrategy = breezy.gpg.GPGStrategy
2520.4.34 by Aaron Bentley
Add signature support
1451
        branch = tree_a.branch
1452
        repo_a = branch.repository
6855.4.1 by Jelmer Vernooij
Yet more bees.
1453
        tree_a.commit("base", allow_pointless=True, rev_id=b'A')
6973.7.10 by Jelmer Vernooij
More fixes.
1454
        self.assertFalse(branch.repository.has_signature_for_revision_id(b'A'))
2520.4.34 by Aaron Bentley
Add signature support
1455
        try:
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1456
            from ..testament import Testament
2520.4.34 by Aaron Bentley
Add signature support
1457
            # monkey patch gpg signing mechanism
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1458
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
6393.1.1 by Vincent Ladeuil
Provides MemoryStack to simplify configuration setup in tests
1459
            new_config = test_commit.MustSignConfig()
6351.3.3 by Jelmer Vernooij
Convert more stuff to use config stacks.
1460
            commit.Commit(config_stack=new_config).commit(message="base",
2520.4.34 by Aaron Bentley
Add signature support
1461
                                                    allow_pointless=True,
6855.4.1 by Jelmer Vernooij
Yet more bees.
1462
                                                    rev_id=b'B',
2520.4.34 by Aaron Bentley
Add signature support
1463
                                                    working_tree=tree_a)
1464
            def sign(text):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1465
                return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
6973.7.10 by Jelmer Vernooij
More fixes.
1466
            self.assertTrue(repo_a.has_signature_for_revision_id(b'B'))
2520.4.34 by Aaron Bentley
Add signature support
1467
        finally:
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1468
            breezy.gpg.GPGStrategy = oldstrategy
2520.4.34 by Aaron Bentley
Add signature support
1469
        tree_b = self.make_branch_and_tree('tree_b')
1470
        repo_b = tree_b.branch.repository
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1471
        s = BytesIO()
2520.4.136 by Aaron Bentley
Fix format strings
1472
        serializer = BundleSerializerV4('4')
7029.2.2 by Jelmer Vernooij
Fix two tests.
1473
        with tree_a.lock_read():
1474
            serializer.write_bundle(tree_a.branch.repository, b'B', b'null:', s)
2520.4.34 by Aaron Bentley
Add signature support
1475
        s.seek(0)
1476
        install_bundle(repo_b, serializer.read(s))
6973.7.10 by Jelmer Vernooij
More fixes.
1477
        self.assertTrue(repo_b.has_signature_for_revision_id(b'B'))
1478
        self.assertEqual(repo_b.get_signature_text(b'B'),
1479
                         repo_a.get_signature_text(b'B'))
2520.4.100 by Aaron Bentley
Fix repeat signature installs
1480
        s.seek(0)
1481
        # ensure repeat installs are harmless
1482
        install_bundle(repo_b, serializer.read(s))
2520.4.34 by Aaron Bentley
Add signature support
1483
2520.4.4 by Aaron Bentley
Get basis support for a new bundle format in place
1484
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1485
class V4_2aBundleTester(V4BundleTester):
1486
1487
    def bzrdir_format(self):
1488
        return '2a'
1489
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1490
    def get_invalid_bundle(self, base_rev_id, rev_id):
1491
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1492
        Munge the text so that it's invalid.
1493
1494
        :return: The in-memory bundle
1495
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1496
        from ..bundle import serializer
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1497
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1498
        new_text = self.get_raw(BytesIO(b''.join(bundle_txt)))
4543.2.9 by John Arbash Meinel
Down to 2 failing tests.
1499
        # We are going to be replacing some text to set the executable bit on a
1500
        # file. Make sure the text replacement actually works correctly.
6973.7.10 by Jelmer Vernooij
More fixes.
1501
        self.assertContainsRe(new_text, b'(?m)B244\n\ni 1\n<inventory')
1502
        new_text = new_text.replace(b'<file file_id="exe-1"',
1503
                                    b'<file executable="y" file_id="exe-1"')
1504
        new_text = new_text.replace(b'B244', b'B259')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1505
        bundle_txt = BytesIO()
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1506
        bundle_txt.write(serializer._get_bundle_header('4'))
6973.7.5 by Jelmer Vernooij
s/file/open.
1507
        bundle_txt.write(b'\n')
6973.7.10 by Jelmer Vernooij
More fixes.
1508
        bundle_txt.write(bz2.compress(new_text))
4543.2.8 by John Arbash Meinel
Add a custom get_invalid_bundle and allow BadBundle to be
1509
        bundle_txt.seek(0)
1510
        bundle = read_bundle(bundle_txt)
1511
        self.valid_apply_bundle(base_rev_id, bundle)
1512
        return bundle
1513
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1514
    def make_merged_branch(self):
4543.2.6 by John Arbash Meinel
redefinning self.bzrdir_format() automatically sets the default format.
1515
        builder = self.make_branch_builder('source')
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1516
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1517
        builder.build_snapshot(None, [
6973.7.10 by Jelmer Vernooij
More fixes.
1518
            ('add', ('', b'root-id', 'directory', None)),
1519
            ('add', ('file', b'file-id', 'file', b'original content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1520
            ], revision_id=b'a@cset-0-1')
6973.7.10 by Jelmer Vernooij
More fixes.
1521
        builder.build_snapshot([b'a@cset-0-1'], [
1522
            ('modify', ('file', b'new-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1523
            ], revision_id=b'a@cset-0-2a')
6973.7.10 by Jelmer Vernooij
More fixes.
1524
        builder.build_snapshot([b'a@cset-0-1'], [
1525
            ('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1526
            ], revision_id=b'a@cset-0-2b')
6973.7.10 by Jelmer Vernooij
More fixes.
1527
        builder.build_snapshot([b'a@cset-0-2a', b'a@cset-0-2b'], [
1528
            ('add', ('other-file', b'file2-id', 'file', b'file2-content\n')),
6973.5.2 by Jelmer Vernooij
Add more bees.
1529
            ], revision_id=b'a@cset-0-3')
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1530
        builder.finish_series()
1531
        self.b1 = builder.get_branch()
1532
        self.b1.lock_read()
1533
        self.addCleanup(self.b1.unlock)
1534
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1535
    def make_bundle_just_inventories(self, base_revision_id,
1536
                                     target_revision_id,
1537
                                     revision_ids):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1538
        sio = BytesIO()
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1539
        writer = v4.BundleWriteOperation(base_revision_id, target_revision_id,
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1540
                                         self.b1.repository, sio)
1541
        writer.bundle.begin()
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1542
        writer._add_inventory_mpdiffs_from_serializer(revision_ids)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1543
        writer.bundle.end()
1544
        sio.seek(0)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1545
        return sio
1546
1547
    def test_single_inventory_multiple_parents_as_xml(self):
1548
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1549
        sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
1550
                                                [b'a@cset-0-3'])
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1551
        reader = v4.BundleReader(sio, stream_input=False)
1552
        records = list(reader.iter_records())
1553
        self.assertEqual(1, len(records))
1554
        (bytes, metadata, repo_kind, revision_id,
1555
         file_id) = records[0]
1556
        self.assertIs(None, file_id)
6973.7.10 by Jelmer Vernooij
More fixes.
1557
        self.assertEqual(b'a@cset-0-3', revision_id)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1558
        self.assertEqual('inventory', repo_kind)
6973.7.10 by Jelmer Vernooij
More fixes.
1559
        self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1560
                          b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1561
                          b'storage_kind': b'mpdiff',
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1562
                         }, metadata)
1563
        # We should have an mpdiff that takes some lines from both parents.
1564
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1565
            b'i 1\n'
1566
            b'<inventory format="10" revision_id="a@cset-0-3">\n'
1567
            b'\n'
1568
            b'c 0 1 1 2\n'
1569
            b'c 1 3 3 2\n', bytes)
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1570
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1571
    def test_single_inv_no_parents_as_xml(self):
1572
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1573
        sio = self.make_bundle_just_inventories(b'null:', b'a@cset-0-1',
1574
                                                [b'a@cset-0-1'])
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1575
        reader = v4.BundleReader(sio, stream_input=False)
1576
        records = list(reader.iter_records())
1577
        self.assertEqual(1, len(records))
1578
        (bytes, metadata, repo_kind, revision_id,
1579
         file_id) = records[0]
1580
        self.assertIs(None, file_id)
6973.7.10 by Jelmer Vernooij
More fixes.
1581
        self.assertEqual(b'a@cset-0-1', revision_id)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1582
        self.assertEqual('inventory', repo_kind)
6973.7.10 by Jelmer Vernooij
More fixes.
1583
        self.assertEqual({b'parents': [],
1584
                          b'sha1': b'a13f42b142d544aac9b085c42595d304150e31a2',
1585
                          b'storage_kind': b'mpdiff',
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1586
                         }, metadata)
1587
        # We should have an mpdiff that takes some lines from both parents.
1588
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1589
            b'i 4\n'
1590
            b'<inventory format="10" revision_id="a@cset-0-1">\n'
1591
            b'<directory file_id="root-id" name=""'
1592
                b' revision="a@cset-0-1" />\n'
1593
            b'<file file_id="file-id" name="file" parent_id="root-id"'
1594
                b' revision="a@cset-0-1"'
1595
                b' text_sha1="09c2f8647e14e49e922b955c194102070597c2d1"'
1596
                b' text_size="17" />\n'
1597
            b'</inventory>\n'
1598
            b'\n', bytes)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1599
1600
    def test_multiple_inventories_as_xml(self):
1601
        self.make_merged_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1602
        sio = self.make_bundle_just_inventories(b'a@cset-0-1', b'a@cset-0-3',
1603
            [b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'])
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1604
        reader = v4.BundleReader(sio, stream_input=False)
1605
        records = list(reader.iter_records())
1606
        self.assertEqual(3, len(records))
1607
        revision_ids = [rev_id for b, m, k, rev_id, f in records]
6973.7.10 by Jelmer Vernooij
More fixes.
1608
        self.assertEqual([b'a@cset-0-2a', b'a@cset-0-2b', b'a@cset-0-3'],
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1609
                         revision_ids)
1610
        metadata_2a = records[0][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1611
        self.assertEqual({b'parents': [b'a@cset-0-1'],
1612
                          b'sha1': b'1e105886d62d510763e22885eec733b66f5f09bf',
1613
                          b'storage_kind': b'mpdiff',
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1614
                         }, metadata_2a)
1615
        metadata_2b = records[1][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1616
        self.assertEqual({b'parents': [b'a@cset-0-1'],
1617
                          b'sha1': b'f03f12574bdb5ed2204c28636c98a8547544ccd8',
1618
                          b'storage_kind': b'mpdiff',
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1619
                         }, metadata_2b)
1620
        metadata_3 = records[2][1]
6973.7.10 by Jelmer Vernooij
More fixes.
1621
        self.assertEqual({b'parents': [b'a@cset-0-2a', b'a@cset-0-2b'],
1622
                          b'sha1': b'09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1623
                          b'storage_kind': b'mpdiff',
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1624
                         }, metadata_3)
1625
        bytes_2a = records[0][0]
1626
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1627
            b'i 1\n'
1628
            b'<inventory format="10" revision_id="a@cset-0-2a">\n'
1629
            b'\n'
1630
            b'c 0 1 1 1\n'
1631
            b'i 1\n'
1632
            b'<file file_id="file-id" name="file" parent_id="root-id"'
1633
                b' revision="a@cset-0-2a"'
1634
                b' text_sha1="50f545ff40e57b6924b1f3174b267ffc4576e9a9"'
1635
                b' text_size="12" />\n'
1636
            b'\n'
1637
            b'c 0 3 3 1\n', bytes_2a)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1638
        bytes_2b = records[1][0]
1639
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1640
            b'i 1\n'
1641
            b'<inventory format="10" revision_id="a@cset-0-2b">\n'
1642
            b'\n'
1643
            b'c 0 1 1 2\n'
1644
            b'i 1\n'
1645
            b'<file file_id="file2-id" name="other-file" parent_id="root-id"'
1646
                b' revision="a@cset-0-2b"'
1647
                b' text_sha1="b46c0c8ea1e5ef8e46fc8894bfd4752a88ec939e"'
1648
                b' text_size="14" />\n'
1649
            b'\n'
1650
            b'c 0 3 4 1\n', bytes_2b)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1651
        bytes_3 = records[2][0]
1652
        self.assertEqualDiff(
6973.7.10 by Jelmer Vernooij
More fixes.
1653
            b'i 1\n'
1654
            b'<inventory format="10" revision_id="a@cset-0-3">\n'
1655
            b'\n'
1656
            b'c 0 1 1 2\n'
1657
            b'c 1 3 3 2\n', bytes_3)
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1658
1659
    def test_creating_bundle_preserves_chk_pages(self):
1660
        self.make_merged_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1661
        target = self.b1.controldir.sprout('target',
6973.5.2 by Jelmer Vernooij
Add more bees.
1662
                                       revision_id=b'a@cset-0-2a').open_branch()
6973.7.10 by Jelmer Vernooij
More fixes.
1663
        bundle_txt, rev_ids = self.create_bundle_text(b'a@cset-0-2a',
1664
                                                      b'a@cset-0-3')
7029.2.1 by Jelmer Vernooij
don't make assumptions about the order in which revision ids are returned by write_bundle.
1665
        self.assertEqual(set([b'a@cset-0-2b', b'a@cset-0-3']), set(rev_ids))
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1666
        bundle = read_bundle(bundle_txt)
1667
        target.lock_write()
1668
        self.addCleanup(target.unlock)
1669
        install_bundle(target.repository, bundle)
7018.3.10 by Jelmer Vernooij
Consistent return values in PreviewTree.list_files.
1670
        inv1 = next(self.b1.repository.inventories.get_record_stream([
1671
            (b'a@cset-0-3',)], 'unordered',
1672
            True)).get_bytes_as('fulltext')
1673
        inv2 = next(target.repository.inventories.get_record_stream([
1674
            (b'a@cset-0-3',)], 'unordered',
1675
            True)).get_bytes_as('fulltext')
4543.2.7 by John Arbash Meinel
It turns out CHKSerializer was inheriting from xml5
1676
        self.assertEqualDiff(inv1, inv2)
4543.2.5 by John Arbash Meinel
Fix issues with keys/ids and ghost handling.
1677
4543.2.4 by John Arbash Meinel
Start working on code that will use Repository._serializer.write_inventory_to_strig.
1678
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1679
class MungedBundleTester(object):
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1680
1681
    def build_test_bundle(self):
1682
        wt = self.make_branch_and_tree('b1')
1683
1684
        self.build_tree(['b1/one'])
1685
        wt.add('one')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1686
        wt.commit('add one', rev_id=b'a@cset-0-1')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1687
        self.build_tree(['b1/two'])
1688
        wt.add('two')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1689
        wt.commit('add two', rev_id=b'a@cset-0-2',
6973.12.5 by Jelmer Vernooij
Add some u's for revision property names.
1690
                  revprops={u'branch-nick':'test'})
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1691
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1692
        bundle_txt = BytesIO()
6973.7.10 by Jelmer Vernooij
More fixes.
1693
        rev_ids = write_bundle(wt.branch.repository, b'a@cset-0-2',
1694
                               b'a@cset-0-1', bundle_txt, self.format)
1695
        self.assertEqual({b'a@cset-0-2'}, set(rev_ids))
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1696
        bundle_txt.seek(0, 0)
1697
        return bundle_txt
1698
1699
    def check_valid(self, bundle):
1700
        """Check that after whatever munging, the final object is valid."""
6973.7.10 by Jelmer Vernooij
More fixes.
1701
        self.assertEqual([b'a@cset-0-2'],
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1702
            [r.revision_id for r in bundle.real_revisions])
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1703
1704
    def test_extra_whitespace(self):
1705
        bundle_txt = self.build_test_bundle()
1706
1707
        # Seek to the end of the file
1708
        # Adding one extra newline used to give us
1709
        # TypeError: float() argument must be a string or a number
1710
        bundle_txt.seek(0, 2)
6973.7.5 by Jelmer Vernooij
s/file/open.
1711
        bundle_txt.write(b'\n')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1712
        bundle_txt.seek(0)
1713
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1714
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1715
        self.check_valid(bundle)
1716
1717
    def test_extra_whitespace_2(self):
1718
        bundle_txt = self.build_test_bundle()
1719
1720
        # Seek to the end of the file
1721
        # Adding two extra newlines used to give us
1722
        # MalformedPatches: The first line of all patches should be ...
1723
        bundle_txt.seek(0, 2)
6973.7.5 by Jelmer Vernooij
s/file/open.
1724
        bundle_txt.write(b'\n\n')
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1725
        bundle_txt.seek(0)
1726
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1727
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1728
        self.check_valid(bundle)
1729
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1730
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1731
class MungedBundleTesterV09(tests.TestCaseWithTransport, MungedBundleTester):
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1732
1733
    format = '0.9'
1734
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1735
    def test_missing_trailing_whitespace(self):
1736
        bundle_txt = self.build_test_bundle()
1737
1738
        # Remove a trailing newline, it shouldn't kill the parser
1739
        raw = bundle_txt.getvalue()
1740
        # The contents of the bundle don't have to be this, but this
1741
        # test is concerned with the exact case where the serializer
1742
        # creates a blank line at the end, and fails if that
1743
        # line is stripped
6973.7.10 by Jelmer Vernooij
More fixes.
1744
        self.assertEqual(b'\n\n', raw[-2:])
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1745
        bundle_txt = BytesIO(raw[:-1])
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1746
1793.3.4 by John Arbash Meinel
[merge] bzr.dev 1804 and fix conflicts.
1747
        bundle = read_bundle(bundle_txt)
1793.3.2 by John Arbash Meinel
(failing) add some tests which munge trailing whitespace
1748
        self.check_valid(bundle)
1793.3.14 by John Arbash Meinel
Actually fix the bug with missing trailing newline bug #49182
1749
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1750
    def test_opening_text(self):
1751
        bundle_txt = self.build_test_bundle()
1752
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1753
        bundle_txt = BytesIO(
1754
            b"Some random\nemail comments\n" + bundle_txt.getvalue())
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1755
1756
        bundle = read_bundle(bundle_txt)
1757
        self.check_valid(bundle)
1758
1759
    def test_trailing_text(self):
1760
        bundle_txt = self.build_test_bundle()
1761
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1762
        bundle_txt = BytesIO(
1763
            bundle_txt.getvalue() + b"Some trailing\nrandom\ntext\n")
1793.3.16 by John Arbash Meinel
Add tests to ensure that we gracefully handle opening and trailing non-bundle text.
1764
1765
        bundle = read_bundle(bundle_txt)
1766
        self.check_valid(bundle)
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1767
1768
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1769
class MungedBundleTesterV4(tests.TestCaseWithTransport, MungedBundleTester):
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1770
2520.4.136 by Aaron Bentley
Fix format strings
1771
    format = '4'
2520.4.79 by Aaron Bentley
Fixed up not-really-relevant munging tests
1772
1773
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1774
class TestBundleWriterReader(tests.TestCase):
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1775
1776
    def test_roundtrip_record(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1777
        fileobj = BytesIO()
2520.4.72 by Aaron Bentley
Rename format to 4alpha
1778
        writer = v4.BundleWriter(fileobj)
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1779
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1780
        writer.add_info_record({b'foo': b'bar'})
1781
        writer._add_record("Record body", {b'parents': [b'1', b'3'],
1782
            b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
2520.4.56 by Aaron Bentley
Begin adding support for arbitrary metadata
1783
        writer.end()
1784
        fileobj.seek(0)
2520.4.148 by Aaron Bentley
Updates from review
1785
        reader = v4.BundleReader(fileobj, stream_input=True)
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1786
        record_iter = reader.iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1787
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1788
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1789
            'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1790
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1791
        self.assertEqual(("Record body", {b'storage_kind': b'fulltext',
1792
                          b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1793
                          record)
1794
1795
    def test_roundtrip_record_memory_hungry(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1796
        fileobj = BytesIO()
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1797
        writer = v4.BundleWriter(fileobj)
1798
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1799
        writer.add_info_record({b'foo': b'bar'})
1800
        writer._add_record("Record body", {b'parents': [b'1', b'3'],
1801
            b'storage_kind': b'fulltext'}, 'file', b'revid', b'fileid')
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1802
        writer.end()
1803
        fileobj.seek(0)
2520.4.148 by Aaron Bentley
Updates from review
1804
        reader = v4.BundleReader(fileobj, stream_input=False)
2520.4.145 by Aaron Bentley
Add memory_friendly toggle, be memory-unfriendly for merge directives
1805
        record_iter = reader.iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1806
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1807
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
2520.4.95 by Aaron Bentley
Add support for header/info records
1808
            'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1809
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1810
        self.assertEqual(("Record body", {b'storage_kind': b'fulltext',
6973.7.10 by Jelmer Vernooij
More fixes.
1811
                          b'parents': [b'1', b'3']}, 'file', b'revid', b'fileid'),
2520.4.95 by Aaron Bentley
Add support for header/info records
1812
                          record)
1813
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1814
    def test_encode_name(self):
6973.7.8 by Jelmer Vernooij
Fix more tests.
1815
        self.assertEqual(b'revision/rev1',
6973.7.10 by Jelmer Vernooij
More fixes.
1816
            v4.BundleWriter.encode_name('revision', b'rev1'))
6973.7.8 by Jelmer Vernooij
Fix more tests.
1817
        self.assertEqual(b'file/rev//1/file-id-1',
6973.7.10 by Jelmer Vernooij
More fixes.
1818
            v4.BundleWriter.encode_name('file', b'rev/1', b'file-id-1'))
6973.7.8 by Jelmer Vernooij
Fix more tests.
1819
        self.assertEqual(b'info',
2520.4.95 by Aaron Bentley
Add support for header/info records
1820
            v4.BundleWriter.encode_name('info', None, None))
1821
2520.4.127 by Aaron Bentley
Fix up name encoding to handle revision-ids with slashes
1822
    def test_decode_name(self):
6973.7.8 by Jelmer Vernooij
Fix more tests.
1823
        self.assertEqual(('revision', b'rev1', None),
1824
            v4.BundleReader.decode_name(b'revision/rev1'))
1825
        self.assertEqual(('file', b'rev/1', b'file-id-1'),
1826
            v4.BundleReader.decode_name(b'file/rev//1/file-id-1'))
2520.4.95 by Aaron Bentley
Add support for header/info records
1827
        self.assertEqual(('info', None, None),
6973.7.8 by Jelmer Vernooij
Fix more tests.
1828
                         v4.BundleReader.decode_name(b'info'))
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1829
1830
    def test_too_many_names(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1831
        fileobj = BytesIO()
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1832
        writer = v4.BundleWriter(fileobj)
1833
        writer.begin()
6973.7.8 by Jelmer Vernooij
Fix more tests.
1834
        writer.add_info_record({b'foo': b'bar'})
6973.7.10 by Jelmer Vernooij
More fixes.
1835
        writer._container.add_bytes_record(b'blah', [b'two', b'names'])
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1836
        writer.end()
1837
        fileobj.seek(0)
1838
        record_iter = v4.BundleReader(fileobj).iter_records()
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1839
        record = next(record_iter)
6973.7.8 by Jelmer Vernooij
Fix more tests.
1840
        self.assertEqual((None, {b'foo': b'bar', b'storage_kind': b'header'},
2520.4.131 by Aaron Bentley
Raise BadBundle for records with wrong number of names
1841
            'info', None, None), record)
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1842
        self.assertRaises(errors.BadBundle, next, record_iter)
3251.4.11 by Aaron Bentley
Fix wrong local lookups
1843
1844
4241.14.13 by Vincent Ladeuil
Some more cleanup.
1845
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
3251.4.11 by Aaron Bentley
Fix wrong local lookups
1846
1847
    def test_read_mergeable_skips_local(self):
1848
        """A local bundle named like the URL should not be read.
1849
        """
1850
        out, wt = test_read_bundle.create_bundle_file(self)
1851
        class FooService(object):
1852
            """A directory service that always returns source"""
1853
1854
            def look_up(self, name, url):
1855
                return 'source'
3251.4.12 by Aaron Bentley
Updates from review
1856
        directories.register('foo:', FooService, 'Testing directory service')
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
1857
        self.addCleanup(directories.remove, 'foo:')
3251.4.11 by Aaron Bentley
Fix wrong local lookups
1858
        self.build_tree_contents([('./foo:bar', out.getvalue())])
1859
        self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1860
                          'foo:bar')
3703.2.1 by Andrew Bennetts
Allow ConnectionReset to propagate from read_mergeable_from_url.
1861
4547.2.2 by Andrew Bennetts
Add test for read_mergeable_from_transport raising NotABundle when TooManyRedirections happens.
1862
    def test_infinite_redirects_are_not_a_bundle(self):
1863
        """If a URL causes TooManyRedirections then NotABundle is raised.
1864
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1865
        from .blackbox.test_push import RedirectingMemoryServer
4547.2.2 by Andrew Bennetts
Add test for read_mergeable_from_transport raising NotABundle when TooManyRedirections happens.
1866
        server = RedirectingMemoryServer()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
1867
        self.start_server(server)
4547.2.2 by Andrew Bennetts
Add test for read_mergeable_from_transport raising NotABundle when TooManyRedirections happens.
1868
        url = server.get_url() + 'infinite-loop'
1869
        self.assertRaises(errors.NotABundle, read_mergeable_from_url, url)
1870
3703.2.1 by Andrew Bennetts
Allow ConnectionReset to propagate from read_mergeable_from_url.
1871
    def test_smart_server_connection_reset(self):
1872
        """If a smart server connection fails during the attempt to read a
1873
        bundle, then the ConnectionReset error should be propagated.
1874
        """
1875
        # Instantiate a server that will provoke a ConnectionReset
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
1876
        sock_server = DisconnectingServer()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
1877
        self.start_server(sock_server)
3750.1.3 by Vincent Ladeuil
Cleanups.
1878
        # We don't really care what the url is since the server will close the
1879
        # connection without interpreting it
3703.2.1 by Andrew Bennetts
Allow ConnectionReset to propagate from read_mergeable_from_url.
1880
        url = sock_server.get_url()
1881
        self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
1882
1883
6621.25.1 by Martin
Adapt to SocketServer module name change
1884
class DisconnectingHandler(socketserver.BaseRequestHandler):
6206.1.9 by Vincent Ladeuil
Simpler fix for test_smart_server_connection_reset re-using more of the existing test server infrastructure.
1885
    """A request handler that immediately closes any connection made to it."""
1886
1887
    def handle(self):
1888
        self.request.close()
1889
1890
1891
class DisconnectingServer(test_server.TestingTCPServerInAThread):
1892
1893
    def __init__(self):
1894
        super(DisconnectingServer, self).__init__(
1895
            ('127.0.0.1', 0),
1896
            test_server.TestingTCPServer,
1897
            DisconnectingHandler)
1898
1899
    def get_url(self):
1900
        """Return the url of the server"""
1901
        return "bzr://%s:%d/" % self.server.server_address