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