/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_fetch.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:04:39 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4405.
  • Revision ID: jelmer@samba.org-20090528160439-4z0xlrk5nejobm7q
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    bzrdir,
21
21
    errors,
22
22
    gpg,
 
23
    graph,
 
24
    remote,
23
25
    repository,
24
26
    )
 
27
from bzrlib.inventory import ROOT_ID
25
28
from bzrlib.tests import TestSkipped
26
29
from bzrlib.tests.per_repository import TestCaseWithRepository
27
30
from bzrlib.transport import get_transport
99
102
        rev2_tree = knit3_repo.revision_tree('rev2')
100
103
        self.assertEqual('rev1', rev2_tree.inventory.root.revision)
101
104
 
 
105
    def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
 
106
        snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
 
107
        """Assert that result is the parents of 'tip' after fetching snapshots.
 
108
 
 
109
        This helper constructs a 1.9 format source, and a test-format target
 
110
        and fetches the result of building snapshots in the source, then
 
111
        asserts that the parents of tip are result.
 
112
 
 
113
        :param result: A parents list for the inventories.get_parent_map call.
 
114
        :param snapshots: An iterable of snapshot parameters for
 
115
            BranchBuilder.build_snapshot.
 
116
        '"""
 
117
        # This overlaps slightly with the tests for commit builder about graph
 
118
        # consistency.
 
119
        # Cases:
 
120
        repo = self.make_repository('target')
 
121
        remote_format = isinstance(repo, remote.RemoteRepository)
 
122
        if not repo._format.rich_root_data and not remote_format:
 
123
            return # not relevant
 
124
        builder = self.make_branch_builder('source', format='1.9')
 
125
        builder.start_series()
 
126
        for revision_id, parent_ids, actions in snapshots:
 
127
            builder.build_snapshot(revision_id, parent_ids, actions,
 
128
            allow_leftmost_as_ghost=allow_lefthand_ghost)
 
129
        builder.finish_series()
 
130
        source = builder.get_branch()
 
131
        if remote_format and not repo._format.rich_root_data:
 
132
            # use a manual rich root format to ensure the code path is tested.
 
133
            repo = self.make_repository('remote-target',
 
134
                format='1.9-rich-root')
 
135
        repo.lock_write()
 
136
        self.addCleanup(repo.unlock)
 
137
        repo.fetch(source.repository)
 
138
        self.assertEqual(result,
 
139
            repo.texts.get_parent_map([(root_id, 'tip')])[(root_id, 'tip')])
 
140
 
 
141
    def test_fetch_to_rich_root_set_parent_no_parents(self):
 
142
        # No parents rev -> No parents
 
143
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
 
144
            [('tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
145
            ])
 
146
 
 
147
    def test_fetch_to_rich_root_set_parent_1_parent(self):
 
148
        # 1 parent rev -> 1 parent 
 
149
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
150
            ((ROOT_ID, 'base'),),
 
151
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
152
             ('tip', None, []),
 
153
            ])
 
154
 
 
155
    def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
 
156
        # 1 ghost parent -> No parents
 
157
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
 
158
            [('tip', ['ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
 
159
            ], allow_lefthand_ghost=True)
 
160
 
 
161
    def test_fetch_to_rich_root_set_parent_2_head_parents(self):
 
162
        # 2 parents both heads -> 2 parents
 
163
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
164
            ((ROOT_ID, 'left'), (ROOT_ID, 'right')),
 
165
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
166
             ('left', None, []),
 
167
             ('right', ['base'], []),
 
168
             ('tip', ['left', 'right'], []),
 
169
            ])
 
170
 
 
171
    def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
 
172
        # 2 parents one head -> 1 parent
 
173
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
174
            ((ROOT_ID, 'right'),),
 
175
            [('left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
176
             ('right', None, []),
 
177
             ('tip', ['left', 'right'], []),
 
178
            ])
 
179
 
 
180
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
 
181
        # 1 parent different fileid, ours missing -> no parents
 
182
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
183
            (),
 
184
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
185
             ('tip', None, [('unversion', ROOT_ID),
 
186
                            ('add', ('', 'my-root', 'directory', '')),
 
187
                            ]),
 
188
            ], root_id='my-root')
 
189
 
 
190
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
 
191
        # 1 parent different fileid, ours moved -> 1 parent
 
192
        # (and that parent honours the changing revid of the other location)
 
193
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
194
            (('my-root', 'origin'),),
 
195
            [('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
 
196
                             ('add', ('child', 'my-root', 'directory', ''))]),
 
197
             ('base', None, []),
 
198
             ('tip', None, [('unversion', 'my-root'),
 
199
                            ('unversion', ROOT_ID),
 
200
                            ('add', ('', 'my-root', 'directory', '')),
 
201
                            ]),
 
202
            ], root_id='my-root')
 
203
 
 
204
    def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
 
205
        # 2 parents, 1 different fileid, our second missing -> 1 parent
 
206
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
207
            (('my-root', 'right'),),
 
208
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
209
             ('right', None, [('unversion', ROOT_ID),
 
210
                              ('add', ('', 'my-root', 'directory', ''))]),
 
211
             ('tip', ['base', 'right'], [('unversion', ROOT_ID),
 
212
                            ('add', ('', 'my-root', 'directory', '')),
 
213
                            ]),
 
214
            ], root_id='my-root')
 
215
 
 
216
    def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
 
217
        # 2 parents, 1 different fileid, our second moved -> 2 parent
 
218
        # (and that parent honours the changing revid of the other location)
 
219
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
 
220
            (('my-root', 'right'),),
 
221
            # 'my-root' at 'child'.
 
222
            [('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
 
223
                             ('add', ('child', 'my-root', 'directory', ''))]),
 
224
             ('base', None, []),
 
225
            # 'my-root' at root
 
226
             ('right', None, [('unversion', 'my-root'),
 
227
                              ('unversion', ROOT_ID),
 
228
                              ('add', ('', 'my-root', 'directory', ''))]),
 
229
             ('tip', ['base', 'right'], [('unversion', 'my-root'),
 
230
                            ('unversion', ROOT_ID),
 
231
                            ('add', ('', 'my-root', 'directory', '')),
 
232
                            ]),
 
233
            ], root_id='my-root')
 
234
 
102
235
    def test_fetch_all_from_self(self):
103
236
        tree = self.make_branch_and_tree('.')
104
237
        rev_id = tree.commit('one')
166
299
        revision_id = tree.commit('test')
167
300
        repo.fetch(tree.branch.repository)
168
301
        repo.fetch(tree.branch.repository)
 
302
 
 
303
 
 
304
class TestSource(TestCaseWithRepository):
 
305
    """Tests for/about the results of Repository._get_source."""
 
306
 
 
307
    def test_no_absent_records_in_stream_with_ghosts(self):
 
308
        # XXX: Arguably should be in interrepository_implementations but
 
309
        # doesn't actually gain coverage there; need a specific set of
 
310
        # permutations to cover it.
 
311
        # bug lp:376255 was reported about this.
 
312
        builder = self.make_branch_builder('repo')
 
313
        builder.start_series()
 
314
        builder.build_snapshot('tip', ['ghost'],
 
315
            [('add', ('', 'ROOT_ID', 'directory', ''))],
 
316
            allow_leftmost_as_ghost=True)
 
317
        builder.finish_series()
 
318
        b = builder.get_branch()
 
319
        b.lock_read()
 
320
        self.addCleanup(b.unlock)
 
321
        repo = b.repository
 
322
        source = repo._get_source(repo._format)
 
323
        search = graph.PendingAncestryResult(['tip'], repo)
 
324
        stream = source.get_stream(search)
 
325
        for substream_type, substream in stream:
 
326
            for record in substream:
 
327
                self.assertNotEqual('absent', record.storage_kind,
 
328
                    "Absent record for %s" % (((substream_type,) + record.key),))