~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/interversionedfile_implementations/test_join.py

  • Committer: Martin Pool
  • Date: 2006-03-09 07:59:36 UTC
  • mfrom: (1601 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1602.
  • Revision ID: mbp@sourcefrog.net-20060309075936-c13ae6445966956e
[merge] from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
225
225
        self.assertEqual([], w1.get_parents('a'))
226
226
        self.assertEqual(['a'], w1.get_parents('b'))
227
227
        self.assertEqual(['b'], w1.get_parents('c'))
 
228
        
 
229
    def test_joining_ghosts(self):
 
230
        # some versioned file formats allow lines to be added with parent
 
231
        # information that is > than that in the format. Formats that do
 
232
        # not support this need to raise NotImplementedError on the
 
233
        # add_lines_with_ghosts api.
 
234
        # files with ghost information when joined into a file which
 
235
        # supports that must preserve it, when joined into a file which
 
236
        # does not must discard it, and when filling a ghost for a listed
 
237
        # ghost must reconcile it
 
238
        source = self.get_source()
 
239
        try:
 
240
            source.has_ghost('a')
 
241
            source_ghosts = True
 
242
        except NotImplementedError:
 
243
            source_ghosts = False
 
244
        target = self.get_target()
 
245
        try:
 
246
            target.has_ghost('a')
 
247
            target_ghosts = True
 
248
        except NotImplementedError:
 
249
            target_ghosts = False
 
250
 
 
251
        if not source_ghosts and not target_ghosts:
 
252
            # nothing to do
 
253
            return
 
254
        if source_ghosts and not target_ghosts:
 
255
            # switch source and target so source is ghostless
 
256
            t = source
 
257
            source = target
 
258
            target = source
 
259
            source_ghosts = False
 
260
            target_ghosts = True
 
261
        # now target always supports ghosts.
 
262
 
 
263
        # try filling target with ghosts and filling in reverse -  
 
264
        target.add_lines_with_ghosts('notbase', ['base'], [])
 
265
        source.join(target)
 
266
        # legacy apis should behave
 
267
        self.assertEqual(['notbase'], source.get_ancestry(['notbase']))
 
268
        self.assertEqual([], source.get_parents('notbase'))
 
269
        self.assertEqual({'notbase':[]}, source.get_graph())
 
270
        self.assertFalse(source.has_version('base'))
 
271
        if source_ghosts:
 
272
            # ghost data should have been preserved
 
273
            self.assertEqual(['base', 'notbase'], source.get_ancestry_with_ghosts(['notbase']))
 
274
            self.assertEqual(['base'], source.get_parents_with_ghosts('notbase'))
 
275
            self.assertEqual({'notbase':['base']}, source.get_graph_with_ghosts())
 
276
            self.assertTrue(source.has_ghost('base'))
 
277
 
 
278
        # if we add something that is fills out what is a ghost, then 
 
279
        # when joining into a ghost aware join it should flesh out the ghosts.
 
280
        source.add_lines('base', [], [])
 
281
        target.join(source, version_ids=['base']) 
 
282
        self.assertEqual(['base', 'notbase'], target.get_ancestry(['notbase']))
 
283
        self.assertEqual(['base'], target.get_parents('notbase'))
 
284
        self.assertEqual({'base':[],
 
285
                          'notbase':['base'],
 
286
                          },
 
287
                         target.get_graph())
 
288
        self.assertTrue(target.has_version('base'))
 
289
        # we have _with_ghost apis to give us ghost information.
 
290
        self.assertEqual(['base', 'notbase'], target.get_ancestry_with_ghosts(['notbase']))
 
291
        self.assertEqual(['base'], target.get_parents_with_ghosts('notbase'))
 
292
        self.assertEqual({'base':[],
 
293
                          'notbase':['base'],
 
294
                          },
 
295
                         target.get_graph_with_ghosts())
 
296
        self.assertFalse(target.has_ghost('base'))