/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2005, 2006 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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
#
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for InterRepository implementastions."""
18
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
19
import sys
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
20
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
21
import bzrlib
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
22
import bzrlib.bzrdir as bzrdir
23
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
24
import bzrlib.errors as errors
25
from bzrlib.errors import (FileExists,
26
                           NoSuchRevision,
27
                           NoSuchFile,
28
                           UninitializableFormat,
29
                           NotBranchError,
30
                           )
1731.1.1 by Aaron Bentley
Make root entry an InventoryDirectory, make EmptyTree really empty
31
from bzrlib.inventory import Inventory
2321.2.3 by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format
32
import bzrlib.repofmt.weaverepo as weaverepo
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
33
import bzrlib.repository as repository
1694.2.6 by Martin Pool
[merge] bzr.dev
34
from bzrlib.revision import NULL_REVISION, Revision
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
35
from bzrlib.symbol_versioning import one_two
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
36
from bzrlib.tests import (
37
    TestCase,
38
    TestCaseWithTransport,
39
    TestNotApplicable,
40
    TestSkipped,
41
    )
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
42
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
43
from bzrlib.transport import get_transport
44
45
46
class TestCaseWithInterRepository(TestCaseWithBzrDir):
47
48
    def setUp(self):
49
        super(TestCaseWithInterRepository, self).setUp()
50
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
51
    def make_branch(self, relpath, format=None):
52
        repo = self.make_repository(relpath, format=format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
53
        return repo.bzrdir.create_branch()
54
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
55
    def make_bzrdir(self, relpath, format=None):
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
56
        try:
57
            url = self.get_url(relpath)
58
            segments = url.split('/')
59
            if segments and segments[-1] not in ('', '.'):
60
                parent = '/'.join(segments[:-1])
61
                t = get_transport(parent)
62
                try:
63
                    t.mkdir(segments[-1])
64
                except FileExists:
65
                    pass
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
66
            if format is None:
67
                format = self.repository_format._matchingbzrdir
68
            return format.initialize(url)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
69
        except UninitializableFormat:
1684.1.4 by Martin Pool
(patch) better warnings when tests are skipped (Alexander)
70
            raise TestSkipped("Format %s is not initializable." % format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
71
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
72
    def make_repository(self, relpath, format=None):
73
        made_control = self.make_bzrdir(relpath, format=format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
74
        return self.repository_format.initialize(made_control)
75
76
    def make_to_repository(self, relpath):
77
        made_control = self.make_bzrdir(relpath,
78
            self.repository_format_to._matchingbzrdir)
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
79
        return self.repository_format_to.initialize(made_control)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
80
81
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
82
def check_old_format_lock_error(repository_format):
83
    """Potentially ignore LockError on old formats.
84
85
    On win32, with the old OS locks, we get a failure of double-lock when
86
    we open a object in 2 objects and try to lock both.
87
88
    On new formats, LockError would be invalid, but for old formats
89
    this was not supported on Win32.
90
    """
91
    if sys.platform != 'win32':
92
        raise
93
94
    description = repository_format.get_format_description()
95
    if description in ("Repository format 4",
96
                       "Weave repository format 5",
97
                       "Weave repository format 6"):
1711.7.30 by John Arbash Meinel
Switch to using TestSkipped for old win32 problems
98
        # jam 20060701
99
        # win32 OS locks are not re-entrant. So one process cannot
100
        # open the same repository twice and lock them both.
101
        raise TestSkipped('%s on win32 cannot open the same'
102
                          ' repository twice in different objects'
103
                          % description)
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
104
    raise
105
106
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
107
def check_repo_format_for_funky_id_on_win32(repo):
2321.2.3 by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format
108
    if (isinstance(repo, (weaverepo.AllInOneRepository,
109
                          weaverepo.WeaveMetaDirRepository))
110
        and sys.platform == 'win32'):
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
111
            raise TestSkipped("funky chars does not permitted"
112
                              " on this platform in repository"
113
                              " %s" % repo.__class__.__name__)
114
115
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
116
class TestInterRepository(TestCaseWithInterRepository):
117
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
118
    def test_interrepository_get_returns_correct_optimiser(self):
119
        # we assume the optimising code paths are triggered
120
        # by the type of the repo not the transport - at this point.
121
        # we may need to update this test if this changes.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
122
        #
123
        # XXX: This code tests that we get an InterRepository when we try to
124
        # convert between the two repositories that it wants to be tested with
125
        # -- but that's not necessarily correct.  So for now this is disabled.
126
        # mbp 20070206
127
        ## source_repo = self.make_repository("source")
128
        ## target_repo = self.make_to_repository("target")
129
        ## interrepo = repository.InterRepository.get(source_repo, target_repo)
130
        ## self.assertEqual(self.interrepo_class, interrepo.__class__)
131
        pass
1534.1.30 by Robert Collins
Test that we get the right optimiser back in the InterRepository tests.
132
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
133
    def test_fetch(self):
134
        tree_a = self.make_branch_and_tree('a')
135
        self.build_tree(['a/foo'])
136
        tree_a.add('foo', 'file1')
137
        tree_a.commit('rev1', rev_id='rev1')
138
        def check_push_rev1(repo):
139
            # ensure the revision is missing.
140
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
141
            # fetch with a limit of NULL_REVISION and an explicit progress bar.
142
            repo.fetch(tree_a.branch.repository,
143
                       revision_id=NULL_REVISION,
144
                       pb=bzrlib.progress.DummyProgress())
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
145
            # nothing should have been pushed
146
            self.assertFalse(repo.has_revision('rev1'))
147
            # fetch with a default limit (grab everything)
148
            repo.fetch(tree_a.branch.repository)
149
            # check that b now has all the data from a's first commit.
150
            rev = repo.get_revision('rev1')
151
            tree = repo.revision_tree('rev1')
2592.3.214 by Robert Collins
Merge bzr.dev.
152
            tree.lock_read()
153
            self.addCleanup(tree.unlock)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
154
            tree.get_file_text('file1')
155
            for file_id in tree:
156
                if tree.inventory[file_id].kind == "file":
157
                    tree.get_file(file_id).read()
158
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
159
        # makes a target version repo 
160
        repo_b = self.make_to_repository('b')
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
161
        check_push_rev1(repo_b)
3035.2.2 by John Arbash Meinel
Add an interrepository test that when we are missing a basis text,
162
163
    def test_fetch_missing_basis_text(self):
164
        """If fetching a delta, we should die if a basis is not present."""
165
        tree = self.make_branch_and_tree('tree')
166
        self.build_tree(['tree/a'])
167
        tree.add(['a'], ['a-id'])
168
        tree.commit('one', rev_id='rev-one')
169
        self.build_tree_contents([('tree/a', 'new contents\n')])
170
        tree.commit('two', rev_id='rev-two')
171
172
        to_repo = self.make_to_repository('to_repo')
173
        # We build a broken revision so that we can test the fetch code dies
174
        # properly. So copy the inventory and revision, but not the text.
175
        to_repo.lock_write()
176
        try:
177
            to_repo.start_write_group()
178
            inv = tree.branch.repository.get_inventory('rev-one')
179
            to_repo.add_inventory('rev-one', inv, [])
180
            rev = tree.branch.repository.get_revision('rev-one')
181
            to_repo.add_revision('rev-one', rev, inv=inv)
182
            to_repo.commit_write_group()
183
        finally:
184
            to_repo.unlock()
185
186
        # Implementations can either copy the missing basis text, or raise an
187
        # exception
188
        try:
189
            to_repo.fetch(tree.branch.repository, 'rev-two')
3035.2.6 by John Arbash Meinel
Suggested by Robert: Move the missing externals check into part of Packer.pack()
190
        except errors.RevisionNotPresent, e:
3035.2.2 by John Arbash Meinel
Add an interrepository test that when we are missing a basis text,
191
            # If an exception is raised, the revision should not be in the
192
            # target.
193
            self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),
194
                              to_repo.revision_tree, 'rev-two')
195
        else:
196
            # If not exception is raised, then the basis text should be
197
            # available.
198
            to_repo.lock_read()
199
            try:
200
                rt = to_repo.revision_tree('rev-one')
201
                self.assertEqual('contents of tree/a\n',
202
                                 rt.get_file_text('a-id'))
203
            finally:
204
                to_repo.unlock()
205
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
206
    def test_fetch_missing_revision_same_location_fails(self):
207
        repo_a = self.make_repository('.')
208
        repo_b = repository.Repository.open('.')
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
209
        try:
210
            self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
211
        except errors.LockError, e:
212
            check_old_format_lock_error(self.repository_format)
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
213
214
    def test_fetch_same_location_trivial_works(self):
215
        repo_a = self.make_repository('.')
216
        repo_b = repository.Repository.open('.')
1711.7.18 by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors
217
        try:
218
            repo_a.fetch(repo_b)
219
        except errors.LockError, e:
220
            check_old_format_lock_error(self.repository_format)
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
221
1694.2.6 by Martin Pool
[merge] bzr.dev
222
    def test_fetch_missing_text_other_location_fails(self):
223
        source_tree = self.make_branch_and_tree('source')
224
        source = source_tree.branch.repository
225
        target = self.make_to_repository('target')
226
    
2592.3.145 by Robert Collins
Fix test_fetch_missing_text_other_location_fails for pack repositories.
227
        # start by adding a file so the data knit for the file exists in
228
        # repositories that have specific files for each fileid.
1694.2.6 by Martin Pool
[merge] bzr.dev
229
        self.build_tree(['source/id'])
230
        source_tree.add(['id'], ['id'])
231
        source_tree.commit('a', rev_id='a')
232
        # now we manually insert a revision with an inventory referencing
233
        # 'id' at revision 'b', but we do not insert revision b.
234
        # this should ensure that the new versions of files are being checked
235
        # for during pull operations
236
        inv = source.get_inventory('a')
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
237
        source.lock_write()
238
        source.start_write_group()
1694.2.6 by Martin Pool
[merge] bzr.dev
239
        inv['id'].revision = 'b'
1740.2.6 by Aaron Bentley
Update test for new interface
240
        inv.revision_id = 'b'
2592.3.119 by Robert Collins
Merge some test fixes from Martin.
241
        sha1 = source.add_inventory('b', inv, ['a'])
1694.2.6 by Martin Pool
[merge] bzr.dev
242
        rev = Revision(timestamp=0,
243
                       timezone=None,
244
                       committer="Foo Bar <foo@example.com>",
245
                       message="Message",
246
                       inventory_sha1=sha1,
247
                       revision_id='b')
248
        rev.parent_ids = ['a']
249
        source.add_revision('b', rev)
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
250
        source.commit_write_group()
251
        source.unlock()
1694.2.6 by Martin Pool
[merge] bzr.dev
252
        self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
253
        self.assertFalse(target.has_revision('b'))
254
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
255
    def test_fetch_funky_file_id(self):
256
        from_tree = self.make_branch_and_tree('tree')
2240.1.3 by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories
257
        if sys.platform == 'win32':
258
            from_repo = from_tree.branch.repository
259
            check_repo_format_for_funky_id_on_win32(from_repo)
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
260
        self.build_tree(['tree/filename'])
261
        from_tree.add('filename', 'funky-chars<>%&;"\'')
262
        from_tree.commit('commit filename')
263
        to_repo = self.make_to_repository('to')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
264
        to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0])
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
265
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
266
267
class TestCaseWithComplexRepository(TestCaseWithInterRepository):
268
269
    def setUp(self):
270
        super(TestCaseWithComplexRepository, self).setUp()
271
        tree_a = self.make_branch_and_tree('a')
272
        self.bzrdir = tree_a.branch.bzrdir
273
        # add a corrupt inventory 'orphan'
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
274
        tree_a.branch.repository.lock_write()
275
        tree_a.branch.repository.start_write_group()
276
        inv_file = tree_a.branch.repository.get_inventory_weave()
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
277
        inv_file.add_lines('orphan', [], [])
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
278
        tree_a.branch.repository.commit_write_group()
279
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
280
        # add a real revision 'rev1'
281
        tree_a.commit('rev1', rev_id='rev1', allow_pointless=True)
282
        # add a real revision 'rev2' based on rev1
283
        tree_a.commit('rev2', rev_id='rev2', allow_pointless=True)
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
284
        # and sign 'rev2'
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
285
        tree_a.branch.repository.lock_write()
286
        tree_a.branch.repository.start_write_group()
287
        tree_a.branch.repository.sign_revision('rev2', bzrlib.gpg.LoopbackGPGStrategy(None))
288
        tree_a.branch.repository.commit_write_group()
289
        tree_a.branch.repository.unlock()
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
290
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
291
    def test_missing_revision_ids_is_deprecated(self):
292
        repo_b = self.make_to_repository('rev1_only')
293
        repo_a = self.bzrdir.open_repository()
294
        repo_b.fetch(repo_a, 'rev1')
295
        # check the test will be valid
296
        self.assertFalse(repo_b.has_revision('rev2'))
297
        self.assertEqual(['rev2'],
298
            self.applyDeprecated(one_two, repo_b.missing_revision_ids, repo_a))
299
        inter = repository.InterRepository.get(repo_a, repo_b)
300
        self.assertEqual(['rev2'],
301
            self.applyDeprecated(one_two, inter.missing_revision_ids, None,
302
                True))
303
304
    def test_search_missing_revision_ids(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
305
        # revision ids in repository A but not B are returned, fake ones
306
        # are stripped. (fake meaning no revision object, but an inventory 
2592.3.146 by Robert Collins
Typo.
307
        # as some formats keyed off inventory data in the past.)
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
308
        # make a repository to compare against that claims to have rev1
309
        repo_b = self.make_to_repository('rev1_only')
310
        repo_a = self.bzrdir.open_repository()
311
        repo_b.fetch(repo_a, 'rev1')
312
        # check the test will be valid
313
        self.assertFalse(repo_b.has_revision('rev2'))
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
314
        result = repo_b.search_missing_revision_ids(repo_a)
315
        self.assertEqual(set(['rev2']), result.get_keys())
316
        self.assertEqual((set(['rev2']), set(['rev1']), 1), result.get_recipe())
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
317
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
318
    def test_search_missing_revision_ids_absent_requested_raises(self):
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
319
        # Asking for missing revisions with a tip that is itself absent in the
320
        # source raises NoSuchRevision.
321
        repo_b = self.make_to_repository('target')
322
        repo_a = self.bzrdir.open_repository()
323
        # No pizza revisions anywhere
324
        self.assertFalse(repo_a.has_revision('pizza'))
325
        self.assertFalse(repo_b.has_revision('pizza'))
326
        # Asking specifically for an absent revision errors.
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
327
        self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
328
            revision_id='pizza', find_ghosts=True)
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
329
        self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
3010.1.5 by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts.
330
            revision_id='pizza', find_ghosts=False)
331
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
332
    def test_search_missing_revision_ids_revision_limited(self):
1534.1.34 by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method.
333
        # revision ids in repository A that are not referenced by the
334
        # requested revision are not returned.
335
        # make a repository to compare against that is empty
336
        repo_b = self.make_to_repository('empty')
337
        repo_a = self.bzrdir.open_repository()
3184.1.8 by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of
338
        result = repo_b.search_missing_revision_ids(repo_a, revision_id='rev1')
339
        self.assertEqual(set(['rev1']), result.get_keys())
340
        self.assertEqual((set(['rev1']), set([NULL_REVISION]), 1),
341
            result.get_recipe())
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
342
        
2592.3.91 by Robert Collins
Incrementally closing in on a correct fetch for packs.
343
    def test_fetch_fetches_signatures_too(self):
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
344
        from_repo = self.bzrdir.open_repository()
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
345
        from_signature = from_repo.get_signature_text('rev2')
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
346
        to_repo = self.make_to_repository('target')
347
        to_repo.fetch(from_repo)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
348
        to_signature = to_repo.get_signature_text('rev2')
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
349
        self.assertEqual(from_signature, to_signature)
350
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
351
352
class TestCaseWithGhosts(TestCaseWithInterRepository):
353
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
354
    def test_fetch_all_fixes_up_ghost(self):
355
        # we want two repositories at this point:
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
356
        # one with a revision that is a ghost in the other
357
        # repository.
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
358
        # 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
359
        # 'references' is present in both repositories, and 'tip' is present
360
        # just in has_ghost.
361
        # has_ghost       missing_ghost
362
        #------------------------------
363
        # 'ghost'             -
364
        # 'references'    'references'
365
        # 'tip'               -
366
        # In this test we fetch 'tip' which should not fetch 'ghost'
367
        has_ghost = self.make_repository('has_ghost')
368
        missing_ghost = self.make_repository('missing_ghost')
369
        if [True, True] != [repo._format.supports_ghosts for repo in
370
            (has_ghost, missing_ghost)]:
371
            raise TestNotApplicable("Need ghost support.")
372
373
        def add_commit(repo, revision_id, parent_ids):
374
            repo.lock_write()
375
            repo.start_write_group()
376
            inv = Inventory(revision_id=revision_id)
377
            inv.root.revision = revision_id
378
            root_id = inv.root.file_id
379
            sha1 = repo.add_inventory(revision_id, inv, parent_ids)
380
            vf = repo.weave_store.get_weave_or_empty(root_id,
381
                repo.get_transaction())
382
            vf.add_lines(revision_id, [], [])
383
            rev = bzrlib.revision.Revision(timestamp=0,
384
                                           timezone=None,
385
                                           committer="Foo Bar <foo@example.com>",
386
                                           message="Message",
387
                                           inventory_sha1=sha1,
388
                                           revision_id=revision_id)
389
            rev.parent_ids = parent_ids
390
            repo.add_revision(revision_id, rev)
391
            repo.commit_write_group()
392
            repo.unlock()
393
        add_commit(has_ghost, 'ghost', [])
394
        add_commit(has_ghost, 'references', ['ghost'])
395
        add_commit(missing_ghost, 'references', ['ghost'])
396
        add_commit(has_ghost, 'tip', ['references'])
397
        missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True)
398
        # missing ghost now has tip and ghost.
399
        rev = missing_ghost.get_revision('tip')
400
        inv = missing_ghost.get_inventory('tip')
401
        rev = missing_ghost.get_revision('ghost')
402
        inv = missing_ghost.get_inventory('ghost')
1570.1.14 by Robert Collins
Enforce repository consistency during 'fetch' operations.
403
        # rev must not be corrupt now
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
404
        self.assertEqual([None, 'ghost', 'references', 'tip'],
405
            missing_ghost.get_ancestry('tip'))
2814.1.1 by Robert Collins
* Pushing, pulling and branching branches with subtree references was not
406
407
408
class TestFetchDependentData(TestCaseWithInterRepository):
409
410
    def test_reference(self):
411
        from_tree = self.make_branch_and_tree('tree')
412
        to_repo = self.make_to_repository('to')
413
        if (not from_tree.supports_tree_reference() or
414
            not from_tree.branch.repository._format.supports_tree_reference or
415
            not to_repo._format.supports_tree_reference):
416
            raise TestNotApplicable("Need subtree support.")
417
        subtree = self.make_branch_and_tree('tree/subtree')
418
        subtree.commit('subrev 1')
419
        from_tree.add_reference(subtree)
420
        tree_rev = from_tree.commit('foo')
421
        # now from_tree has a last-modified of subtree of the rev id of the
422
        # commit for foo, and a reference revision of the rev id of the commit
423
        # for subrev 1
424
        to_repo.fetch(from_tree.branch.repository, tree_rev)
425
        # to_repo should have a file_graph for from_tree.path2id('subtree') and
426
        # revid tree_rev.
2998.2.2 by John Arbash Meinel
implement a faster path for copying from packs back to knits.
427
        to_repo.lock_read()
428
        try:
429
            file_vf = to_repo.weave_store.get_weave(
430
                from_tree.path2id('subtree'), to_repo.get_transaction())
431
            self.assertEqual([tree_rev], file_vf.get_ancestry([tree_rev]))
432
        finally:
433
            to_repo.unlock()