/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
1
# Copyright (C) 2009 Canonical Ltd
2
#
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.
7
#
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.
12
#
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
18
from breezy import (
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
19
    branch,
6670.4.3 by Jelmer Vernooij
Fix more imports.
20
    )
21
from breezy.bzr import (
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
22
    vf_search,
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
23
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy.tests.per_repository import TestCaseWithRepository
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
25
26
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
27
class TestFetchBase(TestCaseWithRepository):
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
28
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
29
    def make_source_branch(self):
30
        # It would be nice if there was a way to force this to be memory-only
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
31
        builder = self.make_branch_builder('source')
6883.22.11 by Jelmer Vernooij
merge trunk
32
        content = [b'content lines\n'
33
                   b'for the first revision\n'
34
                   b'which is a marginal amount of content\n'
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
35
                  ]
36
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
37
        builder.build_snapshot(None, [
6855.3.1 by Jelmer Vernooij
Several more fixes.
38
            ('add', ('', b'root-id', 'directory', None)),
39
            ('add', ('a', b'a-id', 'file', ''.join(content))),
40
            ], revision_id=b'A-id')
6883.22.11 by Jelmer Vernooij
merge trunk
41
        content.append(b'and some more lines for B\n')
6855.3.1 by Jelmer Vernooij
Several more fixes.
42
        builder.build_snapshot([b'A-id'], [
6883.22.11 by Jelmer Vernooij
merge trunk
43
            ('modify', ('a', b''.join(content)))],
6855.3.1 by Jelmer Vernooij
Several more fixes.
44
            revision_id=b'B-id')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
45
        content.append('and yet even more content for C\n')
6855.3.1 by Jelmer Vernooij
Several more fixes.
46
        builder.build_snapshot([b'B-id'], [
6883.22.11 by Jelmer Vernooij
merge trunk
47
            ('modify', ('a', b''.join(content)))],
6855.3.1 by Jelmer Vernooij
Several more fixes.
48
            revision_id=b'C-id')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
49
        builder.finish_series()
50
        source_b = builder.get_branch()
51
        source_b.lock_read()
52
        self.addCleanup(source_b.unlock)
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
53
        return content, source_b
54
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
55
56
class TestFetch(TestFetchBase):
57
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
58
    def test_sprout_from_stacked_with_short_history(self):
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
59
        content, source_b = self.make_source_branch()
60
        # Split the generated content into a base branch, and a stacked branch
4343.3.13 by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch
61
        # Use 'make_branch' which gives us a bzr:// branch when appropriate,
62
        # rather than creating a branch-on-disk
63
        stack_b = self.make_branch('stack-on')
64
        stack_b.pull(source_b, stop_revision='B-id')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
65
        target_b = self.make_branch('target')
4343.3.13 by John Arbash Meinel
Update the fetch tests to make sure we are properly testing a smart base branch
66
        target_b.set_stacked_on_url('../stack-on')
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
67
        target_b.pull(source_b, stop_revision='C-id')
68
        # At this point, we should have a target branch, with 1 revision, on
69
        # top of the source.
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
70
        final_b = self.make_branch('final')
71
        final_b.pull(target_b)
4343.3.10 by John Arbash Meinel
Add a per_repository_reference test with real stacked repos.
72
        final_b.lock_read()
73
        self.addCleanup(final_b.unlock)
74
        self.assertEqual('C-id', final_b.last_revision())
75
        text_keys = [('a-id', 'A-id'), ('a-id', 'B-id'), ('a-id', 'C-id')]
76
        stream = final_b.repository.texts.get_record_stream(text_keys,
77
            'unordered', True)
4343.3.36 by John Arbash Meinel
Some review feedback from Andrew.
78
        records = sorted([(r.key, r.get_bytes_as('fulltext')) for r in stream])
79
        self.assertEqual([
80
            (('a-id', 'A-id'), ''.join(content[:-2])),
81
            (('a-id', 'B-id'), ''.join(content[:-1])),
82
            (('a-id', 'C-id'), ''.join(content)),
83
            ], records)
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
84
85
    def test_sprout_from_smart_stacked_with_short_history(self):
86
        content, source_b = self.make_source_branch()
87
        transport = self.make_smart_server('server')
88
        transport.ensure_base()
89
        url = transport.abspath('')
6973.5.2 by Jelmer Vernooij
Add more bees.
90
        stack_b = source_b.controldir.sprout(url + '/stack-on', revision_id=b'B-id')
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
91
        # self.make_branch only takes relative paths, so we do it the 'hard'
92
        # way
93
        target_transport = transport.clone('target')
94
        target_transport.ensure_base()
95
        target_bzrdir = self.bzrdir_format.initialize_on_transport(
96
                            target_transport)
97
        target_bzrdir.create_repository()
98
        target_b = target_bzrdir.create_branch()
99
        target_b.set_stacked_on_url('../stack-on')
100
        target_b.pull(source_b, stop_revision='C-id')
101
        # Now we should be able to branch from the remote location to a local
102
        # location
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
103
        final_b = target_b.controldir.sprout('final').open_branch()
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
104
        self.assertEqual('C-id', final_b.last_revision())
105
106
        # bzrdir.sprout() has slightly different code paths if you supply a
107
        # revision_id versus not. If you supply revision_id, then you get a
108
        # PendingAncestryResult for the search, versus a SearchResult...
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
109
        final2_b = target_b.controldir.sprout('final2',
6973.5.2 by Jelmer Vernooij
Add more bees.
110
                                          revision_id=b'C-id').open_branch()
4343.3.17 by John Arbash Meinel
Finally found a way to write a test case to exercise the code path.
111
        self.assertEqual('C-id', final_b.last_revision())
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
112
113
    def make_source_with_ghost_and_stacked_target(self):
114
        builder = self.make_branch_builder('source')
115
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
116
        builder.build_snapshot(None, [
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
117
            ('add', ('', 'root-id', 'directory', None)),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
118
            ('add', ('file', 'file-id', 'file', 'content\n'))],
6973.5.2 by Jelmer Vernooij
Add more bees.
119
            revision_id=b'A-id')
120
        builder.build_snapshot(['A-id', 'ghost-id'], [], revision_id=b'B-id')
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
121
        builder.finish_series()
122
        source_b = builder.get_branch()
123
        source_b.lock_read()
124
        self.addCleanup(source_b.unlock)
125
        base = self.make_branch('base')
126
        base.pull(source_b, stop_revision='A-id')
127
        stacked = self.make_branch('stacked')
128
        stacked.set_stacked_on_url('../base')
129
        return source_b, base, stacked
130
131
    def test_fetch_with_ghost_stacked(self):
132
        (source_b, base,
133
         stacked) = self.make_source_with_ghost_and_stacked_target()
134
        stacked.pull(source_b, stop_revision='B-id')
135
136
    def test_fetch_into_smart_stacked_with_ghost(self):
137
        (source_b, base,
138
         stacked) = self.make_source_with_ghost_and_stacked_target()
139
        # Now, create a smart server on 'stacked' and re-open to force the
140
        # target to be a smart target
141
        trans = self.make_smart_server('stacked')
142
        stacked = branch.Branch.open(trans.base)
143
        stacked.lock_write()
144
        self.addCleanup(stacked.unlock)
145
        stacked.pull(source_b, stop_revision='B-id')
146
147
    def test_fetch_to_stacked_from_smart_with_ghost(self):
148
        (source_b, base,
149
         stacked) = self.make_source_with_ghost_and_stacked_target()
150
        # Now, create a smart server on 'source' and re-open to force the
151
        # target to be a smart target
152
        trans = self.make_smart_server('source')
153
        source_b = branch.Branch.open(trans.base)
154
        source_b.lock_read()
155
        self.addCleanup(source_b.unlock)
156
        stacked.pull(source_b, stop_revision='B-id')
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
157
158
159
class TestFetchFromRepoWithUnconfiguredFallbacks(TestFetchBase):
160
161
    def make_stacked_source_repo(self):
162
        _, source_b = self.make_source_branch()
163
        # Use 'make_branch' which gives us a bzr:// branch when appropriate,
164
        # rather than creating a branch-on-disk
165
        stack_b = self.make_branch('stack-on')
166
        stack_b.pull(source_b, stop_revision='B-id')
167
        stacked_b = self.make_branch('stacked')
168
        stacked_b.set_stacked_on_url('../stack-on')
169
        stacked_b.pull(source_b, stop_revision='C-id')
170
        return stacked_b.repository
171
172
    def test_fetch_everything_includes_parent_invs(self):
173
        stacked = self.make_stacked_source_repo()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
174
        repo_missing_fallbacks = stacked.controldir.open_repository()
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
175
        self.addCleanup(repo_missing_fallbacks.lock_read().unlock)
176
        target = self.make_repository('target')
177
        self.addCleanup(target.lock_write().unlock)
178
        target.fetch(
179
            repo_missing_fallbacks,
6341.1.4 by Jelmer Vernooij
Move more functionality to vf_search.
180
            fetch_spec=vf_search.EverythingResult(repo_missing_fallbacks))
5539.2.7 by Andrew Bennetts
Add a test, revise a comment.
181
        self.assertEqual(repo_missing_fallbacks.revisions.keys(),
182
            target.revisions.keys())
183
        self.assertEqual(repo_missing_fallbacks.inventories.keys(),
184
            target.inventories.keys())
185
        self.assertEqual(['C-id'],
186
            sorted(k[-1] for k in target.revisions.keys()))
187
        self.assertEqual(['B-id', 'C-id'],
188
            sorted(k[-1] for k in target.inventories.keys()))
189
190
191