/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

Update with new parent-ids patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
322
322
        self.branch.break_lock()
323
323
 
324
324
    def _set_inventory(self, inv):
 
325
        assert inv.root is not None
325
326
        self._inventory = inv
326
327
        self.path2id = self._inventory.path2id
327
328
 
399
400
            try:
400
401
                xml = self.read_basis_inventory()
401
402
                inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
 
403
                inv.root.revision = revision_id
402
404
            except NoSuchFile:
403
405
                inv = None
404
406
            if inv is not None and inv.revision_id == revision_id:
405
407
                return bzrlib.tree.RevisionTree(self.branch.repository, inv,
406
408
                                                revision_id)
407
409
        # FIXME? RBC 20060403 should we cache the inventory here ?
408
 
        return self.branch.repository.revision_tree(revision_id)
 
410
        try:
 
411
            return self.branch.repository.revision_tree(revision_id)
 
412
        except errors.RevisionNotPresent:
 
413
            # the basis tree *may* be a ghost or a low level error may have
 
414
            # occured. If the revision is present, its a problem, if its not
 
415
            # its a ghost.
 
416
            if self.branch.repository.has_revision(revision_id):
 
417
                raise
 
418
            # the basis tree is a ghost
 
419
            return self.branch.repository.revision_tree(None)
409
420
 
410
421
    @staticmethod
411
422
    @deprecated_method(zero_eight)
643
654
        self._write_inventory(inv)
644
655
 
645
656
    @needs_write_lock
646
 
    def add_parent_tree_id(self, revision_id):
 
657
    def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
647
658
        """Add revision_id as a parent.
648
659
 
649
660
        This is equivalent to retrieving the current list of parent ids
652
663
        :param revision_id: The revision id to add to the parent list. It may
653
664
        be a ghost revision.
654
665
        """
655
 
        self.set_parent_ids(self.get_parent_ids() + [revision_id])
 
666
        self.set_parent_ids(self.get_parent_ids() + [revision_id],
 
667
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
656
668
 
657
669
    @needs_write_lock
658
 
    def add_parent_tree(self, parent_tuple):
 
670
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
659
671
        """Add revision_id, tree tuple as a parent.
660
672
 
661
673
        This is equivalent to retrieving the current list of parent trees
666
678
 
667
679
        :param parent_tuple: The (revision id, tree) to add to the parent list.             If the revision_id is a ghost, pass None for the tree.
668
680
        """
669
 
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]])
 
681
        self.set_parent_ids(self.get_parent_ids() + [parent_tuple[0]],
 
682
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
670
683
 
671
684
    @needs_write_lock
672
685
    def add_pending_merge(self, *revision_ids):
673
686
        # TODO: Perhaps should check at this point that the
674
687
        # history of the revision is actually present?
675
688
        p = self.pending_merges()
 
689
        existing_parents = self.get_parent_ids()
676
690
        updated = False
677
691
        for rev_id in revision_ids:
678
692
            if rev_id in p:
679
693
                continue
 
694
            if rev_id in existing_parents:
 
695
                continue
680
696
            p.append(rev_id)
681
697
            updated = True
682
698
        if updated:
699
715
        return p
700
716
 
701
717
    @needs_write_lock
702
 
    def set_parent_ids(self, revision_ids):
 
718
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
703
719
        """Set the parent ids to revision_ids.
704
720
        
705
721
        See also set_parent_trees. This api will try to retrieve the tree data
719
735
            except errors.RevisionNotPresent:
720
736
                trees.append((rev_id, None))
721
737
                pass
722
 
        self.set_parent_trees(trees)
 
738
        self.set_parent_trees(trees,
 
739
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
723
740
 
724
741
    @needs_write_lock
725
 
    def set_parent_trees(self, parents_list):
 
742
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
726
743
        """Set the parents of the working tree.
727
744
 
728
745
        :param parents_list: A list of (revision_id, tree) tuples. 
731
748
        """
732
749
        parent = parents_list[:1]
733
750
        if len(parent):
 
751
            if (not allow_leftmost_as_ghost and not
 
752
                self.branch.repository.has_revision(parent[0][0])):
 
753
                raise errors.GhostRevision(parent[0][0])
734
754
            self.set_last_revision(parent[0][0])
735
755
        else:
736
756
            self.set_last_revision(None)
739
759
 
740
760
    @needs_write_lock
741
761
    def set_pending_merges(self, rev_list):
 
762
        if self.last_revision() is None:
 
763
            new_last_list = rev_list[:1]
 
764
            rev_list = rev_list[1:]
 
765
            if new_last_list:
 
766
                self.set_last_revision(new_last_list[0])
742
767
        self._control_files.put_utf8('pending-merges', '\n'.join(rev_list))
743
768
 
744
769
    @needs_write_lock
923
948
        if to_dir_id == None and to_name != '':
924
949
            raise BzrError("destination %r is not a versioned directory" % to_name)
925
950
        to_dir_ie = inv[to_dir_id]
926
 
        if to_dir_ie.kind not in ('directory', 'root_directory'):
 
951
        if to_dir_ie.kind != 'directory':
927
952
            raise BzrError("destination %r is not a directory" % to_abs)
928
953
 
929
954
        to_idpath = inv.get_idpath(to_dir_id)
1239
1264
        for regex, mapping in rules:
1240
1265
            match = regex.match(filename)
1241
1266
            if match is not None:
1242
 
                # one or more of the groups in mapping will have a non-None group 
1243
 
                # match.
 
1267
                # one or more of the groups in mapping will have a non-None
 
1268
                # group match.
1244
1269
                groups = match.groups()
1245
1270
                rules = [mapping[group] for group in 
1246
1271
                    mapping if groups[group] is not None]
1479
1504
        Do a 'normal' merge of the old branch basis if it is relevant.
1480
1505
        """
1481
1506
        old_tip = self.branch.update()
1482
 
        if old_tip is not None:
1483
 
            self.add_pending_merge(old_tip)
1484
 
        self.branch.lock_read()
1485
1507
        try:
1486
1508
            result = 0
1487
1509
            if self.last_revision() != self.branch.last_revision():
1524
1546
                                      this_tree=self)
1525
1547
            return result
1526
1548
        finally:
1527
 
            self.branch.unlock()
 
1549
            if old_tip is not None:
 
1550
                self.add_pending_merge(old_tip)
1528
1551
 
1529
1552
    @needs_write_lock
1530
1553
    def _write_inventory(self, inv):