~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Robert Collins
  • Date: 2008-02-13 03:30:01 UTC
  • mfrom: (3221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3224.
  • Revision ID: robertc@robertcollins.net-20080213033001-rw70ul0zb02ph856
Merge to fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
291
291
        """
292
292
        raise NotImplementedError(self.annotate_iter)
293
293
 
294
 
    def plan_file_merge(self, file_id, other):
 
294
    def _get_plan_merge_data(self, file_id, other, base):
 
295
        from bzrlib import merge, versionedfile
 
296
        vf = versionedfile._PlanMergeVersionedFile(file_id)
 
297
        last_revision_a = self._get_file_revision(file_id, vf, 'this:')
 
298
        last_revision_b = other._get_file_revision(file_id, vf, 'other:')
 
299
        if base is None:
 
300
            last_revision_base = None
 
301
        else:
 
302
            last_revision_base = base._get_file_revision(file_id, vf, 'base:')
 
303
        return vf, last_revision_a, last_revision_b, last_revision_base
 
304
 
 
305
    def plan_file_merge(self, file_id, other, base=None):
295
306
        """Generate a merge plan based on annotations.
296
307
 
297
308
        If the file contains uncommitted changes in this tree, they will be
299
310
        uncommitted changes in the other tree, they will be assigned to the
300
311
        'other:' pseudo-revision.
301
312
        """
302
 
        from bzrlib import merge
303
 
        annotated_a = list(self.annotate_iter(file_id,
304
 
                                              _mod_revision.CURRENT_REVISION))
305
 
        annotated_b = list(other.annotate_iter(file_id, 'other:'))
306
 
        ancestors_a = self._get_ancestors(_mod_revision.CURRENT_REVISION)
307
 
        ancestors_b = other._get_ancestors('other:')
308
 
        return merge._plan_annotate_merge(annotated_a, annotated_b,
309
 
                                          ancestors_a, ancestors_b)
 
313
        data = self._get_plan_merge_data(file_id, other, base)
 
314
        vf, last_revision_a, last_revision_b, last_revision_base = data
 
315
        return vf.plan_merge(last_revision_a, last_revision_b,
 
316
                             last_revision_base)
 
317
 
 
318
    def plan_file_lca_merge(self, file_id, other, base=None):
 
319
        """Generate a merge plan based lca-newness.
 
320
 
 
321
        If the file contains uncommitted changes in this tree, they will be
 
322
        attributed to the 'current:' pseudo-revision.  If the file contains
 
323
        uncommitted changes in the other tree, they will be assigned to the
 
324
        'other:' pseudo-revision.
 
325
        """
 
326
        data = self._get_plan_merge_data(file_id, other, base)
 
327
        vf, last_revision_a, last_revision_b, last_revision_base = data
 
328
        return vf.plan_lca_merge(last_revision_a, last_revision_b,
 
329
                                 last_revision_base)
 
330
 
 
331
    def _get_file_revision(self, file_id, vf, tree_revision):
 
332
        def file_revision(revision_tree):
 
333
            revision_tree.lock_read()
 
334
            try:
 
335
                return revision_tree.inventory[file_id].revision
 
336
            finally:
 
337
                revision_tree.unlock()
 
338
 
 
339
        def iter_parent_trees():
 
340
            for revision_id in self.get_parent_ids():
 
341
                try:
 
342
                    yield self.revision_tree(revision_id)
 
343
                except:
 
344
                    yield self.repository.revision_tree(revision_id)
 
345
 
 
346
        if getattr(self, '_get_weave', None) is None:
 
347
            last_revision = tree_revision
 
348
            parent_revisions = [file_revision(t) for t in iter_parent_trees()]
 
349
            vf.add_lines(last_revision, parent_revisions,
 
350
                         self.get_file(file_id).readlines())
 
351
            repo = self.branch.repository
 
352
            transaction = repo.get_transaction()
 
353
            base_vf = repo.weave_store.get_weave(file_id, transaction)
 
354
        else:
 
355
            last_revision = file_revision(self)
 
356
            base_vf = self._get_weave(file_id)
 
357
        vf.fallback_versionedfiles.append(base_vf)
 
358
        return last_revision
310
359
 
311
360
    inventory = property(_get_inventory,
312
361
                         doc="Inventory of this Tree")