/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/workingtree.py

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:
558
567
        args = (DEPRECATED_PARAMETER, message, ) + args
559
568
        committed_id = Commit().commit( working_tree=self, revprops=revprops,
560
569
            *args, **kwargs)
561
 
        self._set_inventory(self.read_working_inventory())
562
570
        return committed_id
563
571
 
564
572
    def id2abspath(self, file_id):
694
702
            If the revision_id is a ghost, pass None for the tree.
695
703
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
696
704
        """
697
 
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]],
 
705
        parent_ids = self.get_parent_ids() + [parent_tuple[0]]
 
706
        if len(parent_ids) > 1:
 
707
            # the leftmost may have already been a ghost, preserve that if it
 
708
            # was.
 
709
            allow_leftmost_as_ghost = True
 
710
        self.set_parent_ids(parent_ids,
698
711
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
699
712
 
700
713
    @needs_write_lock
711
724
        if updated:
712
725
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
713
726
 
 
727
    @deprecated_method(zero_eleven)
714
728
    @needs_read_lock
715
729
    def pending_merges(self):
716
730
        """Return a list of pending merges.
717
731
 
718
732
        These are revisions that have been merged into the working
719
733
        directory but not yet committed.
 
734
 
 
735
        As of 0.11 this is deprecated. Please see WorkingTree.get_parent_ids()
 
736
        instead - which is available on all tree objects.
720
737
        """
721
738
        return self.get_parent_ids()[1:]
722
739
 
776
793
        my_file = rio_file(stanzas, header)
777
794
        self._control_files.put(filename, my_file)
778
795
 
 
796
    @needs_write_lock
 
797
    def merge_from_branch(self, branch, to_revision=None):
 
798
        """Merge from a branch into this working tree.
 
799
 
 
800
        :param branch: The branch to merge from.
 
801
        :param to_revision: If non-None, the merge will merge to to_revision, but 
 
802
            not beyond it. to_revision does not need to be in the history of
 
803
            the branch when it is supplied. If None, to_revision defaults to
 
804
            branch.last_revision().
 
805
        """
 
806
        from bzrlib.merge import Merger, Merge3Merger
 
807
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
808
        try:
 
809
            merger = Merger(self.branch, this_tree=self, pb=pb)
 
810
            merger.pp = ProgressPhase("Merge phase", 5, pb)
 
811
            merger.pp.next_phase()
 
812
            # check that there are no
 
813
            # local alterations
 
814
            merger.check_basis(check_clean=True, require_commits=False)
 
815
            if to_revision is None:
 
816
                to_revision = branch.last_revision()
 
817
            merger.other_rev_id = to_revision
 
818
            if merger.other_rev_id is None:
 
819
                raise error.NoCommits(branch)
 
820
            self.branch.fetch(branch, last_revision=merger.other_rev_id)
 
821
            merger.other_basis = merger.other_rev_id
 
822
            merger.other_tree = self.branch.repository.revision_tree(
 
823
                merger.other_rev_id)
 
824
            merger.pp.next_phase()
 
825
            merger.find_base()
 
826
            if merger.base_rev_id == merger.other_rev_id:
 
827
                raise errors.PointlessMerge
 
828
            merger.backup_files = False
 
829
            merger.merge_type = Merge3Merger
 
830
            merger.set_interesting_files(None)
 
831
            merger.show_base = False
 
832
            merger.reprocess = False
 
833
            conflicts = merger.do_merge()
 
834
            merger.set_pending()
 
835
        finally:
 
836
            pb.finished()
 
837
        return conflicts
 
838
 
779
839
    @needs_read_lock
780
840
    def merge_modified(self):
781
841
        try:
945
1005
        if not self.has_filename(to_name):
946
1006
            raise BzrError("destination %r not in working directory" % to_abs)
947
1007
        to_dir_id = inv.path2id(to_name)
948
 
        if to_dir_id == None and to_name != '':
 
1008
        if to_dir_id is None and to_name != '':
949
1009
            raise BzrError("destination %r is not a versioned directory" % to_name)
950
1010
        to_dir_ie = inv[to_dir_id]
951
1011
        if to_dir_ie.kind != 'directory':
957
1017
            if not self.has_filename(f):
958
1018
                raise BzrError("%r does not exist in working tree" % f)
959
1019
            f_id = inv.path2id(f)
960
 
            if f_id == None:
 
1020
            if f_id is None:
961
1021
                raise BzrError("%r is not versioned" % f)
962
1022
            name_tail = splitpath(f)[-1]
963
1023
            dest_path = pathjoin(to_name, name_tail)
1002
1062
            raise BzrError("can't rename: new working file %r already exists" % to_rel)
1003
1063
 
1004
1064
        file_id = inv.path2id(from_rel)
1005
 
        if file_id == None:
 
1065
        if file_id is None:
1006
1066
            raise BzrError("can't rename: old name %r is not versioned" % from_rel)
1007
1067
 
1008
1068
        entry = inv[file_id]
1014
1074
 
1015
1075
        to_dir, to_tail = os.path.split(to_rel)
1016
1076
        to_dir_id = inv.path2id(to_dir)
1017
 
        if to_dir_id == None and to_dir != '':
 
1077
        if to_dir_id is None and to_dir != '':
1018
1078
            raise BzrError("can't determine destination directory id for %r" % to_dir)
1019
1079
 
1020
1080
        mutter("rename_one:")
1047
1107
        for subp in self.extras():
1048
1108
            if not self.is_ignored(subp):
1049
1109
                yield subp
1050
 
 
 
1110
    
 
1111
    @needs_write_lock
 
1112
    def unversion(self, file_ids):
 
1113
        """Remove the file ids in file_ids from the current versioned set.
 
1114
 
 
1115
        When a file_id is unversioned, all of its children are automatically
 
1116
        unversioned.
 
1117
 
 
1118
        :param file_ids: The file ids to stop versioning.
 
1119
        :raises: NoSuchId if any fileid is not currently versioned.
 
1120
        """
 
1121
        for file_id in file_ids:
 
1122
            if self._inventory.has_id(file_id):
 
1123
                self._inventory.remove_recursive_id(file_id)
 
1124
            else:
 
1125
                raise errors.NoSuchId(self, file_id)
 
1126
        if len(file_ids):
 
1127
            # in the future this should just set a dirty bit to wait for the 
 
1128
            # final unlock. However, until all methods of workingtree start
 
1129
            # with the current in -memory inventory rather than triggering 
 
1130
            # a read, it is more complex - we need to teach read_inventory
 
1131
            # to know when to read, and when to not read first... and possibly
 
1132
            # to save first when the in memory one may be corrupted.
 
1133
            # so for now, we just only write it if it is indeed dirty.
 
1134
            # - RBC 20060907
 
1135
            self._write_inventory(self._inventory)
 
1136
    
1051
1137
    @deprecated_method(zero_eight)
1052
1138
    def iter_conflicts(self):
1053
1139
        """List all files in the tree that have text or content conflicts.
1206
1292
        """Yield list of PATH, IGNORE_PATTERN"""
1207
1293
        for subp in self.extras():
1208
1294
            pat = self.is_ignored(subp)
1209
 
            if pat != None:
 
1295
            if pat is not None:
1210
1296
                yield subp, pat
1211
1297
 
1212
1298
    def get_ignore_list(self):
1278
1364
    def kind(self, file_id):
1279
1365
        return file_kind(self.id2abspath(file_id))
1280
1366
 
1281
 
    @needs_read_lock
1282
1367
    def last_revision(self):
1283
1368
        """Return the last revision id of this working tree.
1284
1369
 
1285
 
        In early branch formats this was == the branch last_revision,
 
1370
        In early branch formats this was the same as the branch last_revision,
1286
1371
        but that cannot be relied upon - for working tree operations,
1287
 
        always use tree.last_revision().
 
1372
        always use tree.last_revision(). This returns the left most parent id,
 
1373
        or None if there are no parents.
 
1374
 
 
1375
        This was deprecated as of 0.11. Please use get_parent_ids instead.
1288
1376
        """
 
1377
        return self._last_revision()
 
1378
 
 
1379
    @needs_read_lock
 
1380
    def _last_revision(self):
 
1381
        """helper for get_parent_ids."""
1289
1382
        return self.branch.last_revision()
1290
1383
 
1291
1384
    def is_locked(self):
1525
1618
        # local work is unreferenced and will appear to have been lost.
1526
1619
        # 
1527
1620
        result = 0
1528
 
        if self.last_revision() != self.branch.last_revision():
 
1621
        try:
 
1622
            last_rev = self.get_parent_ids()[0]
 
1623
        except IndexError:
 
1624
            last_rev = None
 
1625
        if last_rev != self.branch.last_revision():
1529
1626
            # merge tree state up to new branch tip.
1530
1627
            basis = self.basis_tree()
1531
1628
            to_tree = self.branch.basis_tree()
1551
1648
                parent_trees.append(
1552
1649
                    (old_tip, self.branch.repository.revision_tree(old_tip)))
1553
1650
            self.set_parent_trees(parent_trees)
 
1651
            last_rev = parent_trees[0][0]
1554
1652
        else:
1555
1653
            # the working tree had the same last-revision as the master
1556
1654
            # branch did. We may still have pivot local work from the local
1557
1655
            # branch into old_tip:
1558
1656
            if old_tip is not None:
1559
1657
                self.add_parent_tree_id(old_tip)
1560
 
        if old_tip and old_tip != self.last_revision():
 
1658
        if old_tip and old_tip != last_rev:
1561
1659
            # our last revision was not the prior branch last revision
1562
1660
            # and we have converted that last revision to a pending merge.
1563
1661
            # base is somewhere between the branch tip now
1649
1747
    """
1650
1748
 
1651
1749
    @needs_read_lock
1652
 
    def last_revision(self):
1653
 
        """See WorkingTree.last_revision."""
 
1750
    def _last_revision(self):
 
1751
        """See WorkingTree._last_revision."""
1654
1752
        try:
1655
1753
            return self._control_files.get_utf8('last-revision').read()
1656
1754
        except NoSuchFile: