~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robey Pointer
  • Date: 2006-09-08 18:52:17 UTC
  • mfrom: (1993 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1996.
  • Revision ID: robey@lag.net-20060908185217-6a4406e1d41753f5
merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
        deprecated_function,
97
97
        DEPRECATED_PARAMETER,
98
98
        zero_eight,
 
99
        zero_eleven,
99
100
        )
100
101
from bzrlib.trace import mutter, note
101
102
from bzrlib.transform import build_tree
399
400
        If the left most parent is a ghost then the returned tree will be an
400
401
        empty tree - one obtained by calling repository.revision_tree(None).
401
402
        """
402
 
        revision_id = self.last_revision()
403
 
        if revision_id is not None:
 
403
        try:
 
404
            revision_id = self.get_parent_ids()[0]
 
405
        except IndexError:
 
406
            # no parents, return an empty revision tree.
 
407
            # in the future this should return the tree for
 
408
            # 'empty:' - the implicit root empty tree.
 
409
            return self.branch.repository.revision_tree(None)
 
410
        else:
404
411
            try:
405
412
                xml = self.read_basis_inventory()
406
413
                inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
410
417
            if inv is not None and inv.revision_id == revision_id:
411
418
                return bzrlib.tree.RevisionTree(self.branch.repository, inv,
412
419
                                                revision_id)
413
 
        # FIXME? RBC 20060403 should we cache the inventory here ?
 
420
        # No cached copy available, retrieve from the repository.
 
421
        # FIXME? RBC 20060403 should we cache the inventory locally
 
422
        # at this point ?
414
423
        try:
415
424
            return self.branch.repository.revision_tree(revision_id)
416
425
        except errors.RevisionNotPresent:
486
495
        This implementation reads the pending merges list and last_revision
487
496
        value and uses that to decide what the parents list should be.
488
497
        """
489
 
        last_rev = self.last_revision()
 
498
        last_rev = self._last_revision()
490
499
        if last_rev is None:
491
500
            parents = []
492
501
        else:
557
566
        args = (DEPRECATED_PARAMETER, message, ) + args
558
567
        committed_id = Commit().commit( working_tree=self, revprops=revprops,
559
568
            *args, **kwargs)
560
 
        self._set_inventory(self.read_working_inventory())
561
569
        return committed_id
562
570
 
563
571
    def id2abspath(self, file_id):
693
701
            If the revision_id is a ghost, pass None for the tree.
694
702
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
695
703
        """
696
 
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]],
 
704
        parent_ids = self.get_parent_ids() + [parent_tuple[0]]
 
705
        if len(parent_ids) > 1:
 
706
            # the leftmost may have already been a ghost, preserve that if it
 
707
            # was.
 
708
            allow_leftmost_as_ghost = True
 
709
        self.set_parent_ids(parent_ids,
697
710
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
698
711
 
699
712
    @needs_write_lock
710
723
        if updated:
711
724
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
712
725
 
 
726
    @deprecated_method(zero_eleven)
713
727
    @needs_read_lock
714
728
    def pending_merges(self):
715
729
        """Return a list of pending merges.
716
730
 
717
731
        These are revisions that have been merged into the working
718
732
        directory but not yet committed.
 
733
 
 
734
        As of 0.11 this is deprecated. Please see WorkingTree.get_parent_ids()
 
735
        instead - which is available on all tree objects.
719
736
        """
720
737
        return self.get_parent_ids()[1:]
721
738
 
775
792
        my_file = rio_file(stanzas, header)
776
793
        self._control_files.put(filename, my_file)
777
794
 
 
795
    @needs_write_lock
 
796
    def merge_from_branch(self, branch, to_revision=None):
 
797
        """Merge from a branch into this working tree.
 
798
 
 
799
        :param branch: The branch to merge from.
 
800
        :param to_revision: If non-None, the merge will merge to to_revision, but 
 
801
            not beyond it. to_revision does not need to be in the history of
 
802
            the branch when it is supplied. If None, to_revision defaults to
 
803
            branch.last_revision().
 
804
        """
 
805
        from bzrlib.merge import Merger, Merge3Merger
 
806
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
807
        try:
 
808
            merger = Merger(self.branch, this_tree=self, pb=pb)
 
809
            merger.pp = ProgressPhase("Merge phase", 5, pb)
 
810
            merger.pp.next_phase()
 
811
            # check that there are no
 
812
            # local alterations
 
813
            merger.check_basis(check_clean=True, require_commits=False)
 
814
            if to_revision is None:
 
815
                to_revision = branch.last_revision()
 
816
            merger.other_rev_id = to_revision
 
817
            if merger.other_rev_id is None:
 
818
                raise error.NoCommits(branch)
 
819
            self.branch.fetch(branch, last_revision=merger.other_rev_id)
 
820
            merger.other_basis = merger.other_rev_id
 
821
            merger.other_tree = self.branch.repository.revision_tree(
 
822
                merger.other_rev_id)
 
823
            merger.pp.next_phase()
 
824
            merger.find_base()
 
825
            if merger.base_rev_id == merger.other_rev_id:
 
826
                raise errors.PointlessMerge
 
827
            merger.backup_files = False
 
828
            merger.merge_type = Merge3Merger
 
829
            merger.set_interesting_files(None)
 
830
            merger.show_base = False
 
831
            merger.reprocess = False
 
832
            conflicts = merger.do_merge()
 
833
            merger.set_pending()
 
834
        finally:
 
835
            pb.finished()
 
836
        return conflicts
 
837
 
778
838
    @needs_read_lock
779
839
    def merge_modified(self):
780
840
        try:
1044
1104
        for subp in self.extras():
1045
1105
            if not self.is_ignored(subp):
1046
1106
                yield subp
1047
 
 
 
1107
    
 
1108
    @needs_write_lock
 
1109
    def unversion(self, file_ids):
 
1110
        """Remove the file ids in file_ids from the current versioned set.
 
1111
 
 
1112
        When a file_id is unversioned, all of its children are automatically
 
1113
        unversioned.
 
1114
 
 
1115
        :param file_ids: The file ids to stop versioning.
 
1116
        :raises: NoSuchId if any fileid is not currently versioned.
 
1117
        """
 
1118
        for file_id in file_ids:
 
1119
            if self._inventory.has_id(file_id):
 
1120
                self._inventory.remove_recursive_id(file_id)
 
1121
            else:
 
1122
                raise errors.NoSuchId(self, file_id)
 
1123
        if len(file_ids):
 
1124
            # in the future this should just set a dirty bit to wait for the 
 
1125
            # final unlock. However, until all methods of workingtree start
 
1126
            # with the current in -memory inventory rather than triggering 
 
1127
            # a read, it is more complex - we need to teach read_inventory
 
1128
            # to know when to read, and when to not read first... and possibly
 
1129
            # to save first when the in memory one may be corrupted.
 
1130
            # so for now, we just only write it if it is indeed dirty.
 
1131
            # - RBC 20060907
 
1132
            self._write_inventory(self._inventory)
 
1133
    
1048
1134
    @deprecated_method(zero_eight)
1049
1135
    def iter_conflicts(self):
1050
1136
        """List all files in the tree that have text or content conflicts.
1272
1358
    def kind(self, file_id):
1273
1359
        return file_kind(self.id2abspath(file_id))
1274
1360
 
1275
 
    @needs_read_lock
1276
1361
    def last_revision(self):
1277
1362
        """Return the last revision id of this working tree.
1278
1363
 
1279
 
        In early branch formats this was == the branch last_revision,
 
1364
        In early branch formats this was the same as the branch last_revision,
1280
1365
        but that cannot be relied upon - for working tree operations,
1281
 
        always use tree.last_revision().
 
1366
        always use tree.last_revision(). This returns the left most parent id,
 
1367
        or None if there are no parents.
 
1368
 
 
1369
        This was deprecated as of 0.11. Please use get_parent_ids instead.
1282
1370
        """
 
1371
        return self._last_revision()
 
1372
 
 
1373
    @needs_read_lock
 
1374
    def _last_revision(self):
 
1375
        """helper for get_parent_ids."""
1283
1376
        return self.branch.last_revision()
1284
1377
 
1285
1378
    def is_locked(self):
1512
1605
        # local work is unreferenced and will appear to have been lost.
1513
1606
        # 
1514
1607
        result = 0
1515
 
        if self.last_revision() != self.branch.last_revision():
 
1608
        try:
 
1609
            last_rev = self.get_parent_ids()[0]
 
1610
        except IndexError:
 
1611
            last_rev = None
 
1612
        if last_rev != self.branch.last_revision():
1516
1613
            # merge tree state up to new branch tip.
1517
1614
            basis = self.basis_tree()
1518
1615
            to_tree = self.branch.basis_tree()
1536
1633
                parent_trees.append(
1537
1634
                    (old_tip, self.branch.repository.revision_tree(old_tip)))
1538
1635
            self.set_parent_trees(parent_trees)
 
1636
            last_rev = parent_trees[0][0]
1539
1637
        else:
1540
1638
            # the working tree had the same last-revision as the master
1541
1639
            # branch did. We may still have pivot local work from the local
1542
1640
            # branch into old_tip:
1543
1641
            if old_tip is not None:
1544
1642
                self.add_parent_tree_id(old_tip)
1545
 
        if old_tip and old_tip != self.last_revision():
 
1643
        if old_tip and old_tip != last_rev:
1546
1644
            # our last revision was not the prior branch last revision
1547
1645
            # and we have converted that last revision to a pending merge.
1548
1646
            # base is somewhere between the branch tip now
1634
1732
    """
1635
1733
 
1636
1734
    @needs_read_lock
1637
 
    def last_revision(self):
1638
 
        """See WorkingTree.last_revision."""
 
1735
    def _last_revision(self):
 
1736
        """See WorkingTree._last_revision."""
1639
1737
        try:
1640
1738
            return self._control_files.get_utf8('last-revision').read()
1641
1739
        except NoSuchFile: