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