/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 bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
675
675
        """
676
676
        return self.get_parent_ids()[1:]
677
677
 
 
678
    def _check_parents_for_ghosts(self, revision_ids, allow_leftmost_as_ghost):
 
679
        """Common ghost checking functionality from set_parent_*.
 
680
 
 
681
        This checks that the left hand-parent exists if there are any
 
682
        revisions present.
 
683
        """
 
684
        if len(revision_ids) > 0:
 
685
            leftmost_id = revision_ids[0]
 
686
            if (not allow_leftmost_as_ghost and not
 
687
                self.branch.repository.has_revision(leftmost_id)):
 
688
                raise errors.GhostRevisionUnusableHere(leftmost_id)
 
689
 
 
690
    def _set_merges_from_parent_ids(self, parent_ids):
 
691
        merges = parent_ids[1:]
 
692
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
 
693
 
678
694
    @needs_tree_write_lock
679
695
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
680
696
        """Set the parent ids to revision_ids.
688
704
        :param revision_ids: The revision_ids to set as the parent ids of this
689
705
            working tree. Any of these may be ghosts.
690
706
        """
 
707
        self._check_parents_for_ghosts(revision_ids,
 
708
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
709
 
691
710
        if len(revision_ids) > 0:
692
 
            leftmost_id = revision_ids[0]
693
 
            if (not allow_leftmost_as_ghost and not
694
 
                self.branch.repository.has_revision(leftmost_id)):
695
 
                raise errors.GhostRevisionUnusableHere(leftmost_id)
696
 
            self.set_last_revision(leftmost_id)
 
711
            self.set_last_revision(revision_ids[0])
697
712
        else:
698
713
            self.set_last_revision(None)
699
 
        merges = revision_ids[1:]
700
 
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
 
714
 
 
715
        self._set_merges_from_parent_ids(revision_ids)
701
716
 
702
717
    @needs_tree_write_lock
703
718
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
704
719
        """See MutableTree.set_parent_trees."""
705
 
        # parent trees are not used in current format trees, delegate to
706
 
        # set_parent_ids
707
 
        self.set_parent_ids([rev for (rev, tree) in parents_list],
 
720
        parent_ids = [rev for (rev, tree) in parents_list]
 
721
 
 
722
        self._check_parents_for_ghosts(parent_ids,
708
723
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
709
724
 
 
725
        if len(parent_ids) == 0:
 
726
            leftmost_parent_id = None
 
727
            leftmost_parent_tree = None
 
728
        else:
 
729
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
 
730
 
 
731
        if self._change_last_revision(leftmost_parent_id):
 
732
            if leftmost_parent_tree is None:
 
733
                # If we don't have a tree, fall back to reading the
 
734
                # parent tree from the repository.
 
735
                self._cache_basis_inventory(leftmost_parent_id)
 
736
            else:
 
737
                inv = leftmost_parent_tree.inventory
 
738
                xml = self._create_basis_xml_from_inventory(
 
739
                                        leftmost_parent_id, inv)
 
740
                self._write_basis_inventory(xml)
 
741
        self._set_merges_from_parent_ids(parent_ids)
 
742
 
710
743
    @needs_tree_write_lock
711
744
    def set_pending_merges(self, rev_list):
712
745
        parents = self.get_parent_ids()
810
843
        else:
811
844
            return '?'
812
845
 
813
 
    def list_files(self):
 
846
    def list_files(self, include_root=False):
814
847
        """Recursively list all files as (path, class, kind, id, entry).
815
848
 
816
849
        Lists, but does not descend into unversioned directories.
821
854
        Skips the control directory.
822
855
        """
823
856
        inv = self._inventory
 
857
        if include_root is True:
 
858
            yield ('', 'V', 'directory', inv.root.file_id, inv.root)
824
859
        # Convert these into local objects to save lookup times
825
860
        pathjoin = osutils.pathjoin
826
861
        file_kind = osutils.file_kind
1383
1418
            self.branch.set_revision_history([new_revision])
1384
1419
        return True
1385
1420
 
 
1421
    def _write_basis_inventory(self, xml):
 
1422
        """Write the basis inventory XML to the basis-inventory file"""
 
1423
        assert isinstance(xml, str), 'serialised xml must be bytestring.'
 
1424
        path = self._basis_inventory_name()
 
1425
        sio = StringIO(xml)
 
1426
        self._control_files.put(path, sio)
 
1427
 
 
1428
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
 
1429
        """Create the text that will be saved in basis-inventory"""
 
1430
        inventory.revision_id = revision_id
 
1431
        return bzrlib.xml6.serializer_v6.write_inventory_to_string(inventory)
 
1432
 
1386
1433
    def _cache_basis_inventory(self, new_revision):
1387
1434
        """Cache new_revision as the basis inventory."""
1388
1435
        # TODO: this should allow the ready-to-use inventory to be passed in,
1405
1452
                'format="6"' not in firstline):
1406
1453
                inv = self.branch.repository.deserialise_inventory(
1407
1454
                    new_revision, xml)
1408
 
                inv.revision_id = new_revision
1409
 
                xml = bzrlib.xml6.serializer_v6.write_inventory_to_string(inv)
1410
 
            assert isinstance(xml, str), 'serialised xml must be bytestring.'
1411
 
            path = self._basis_inventory_name()
1412
 
            sio = StringIO(xml)
1413
 
            self._control_files.put(path, sio)
 
1455
                xml = self._create_basis_xml_from_inventory(new_revision, inv)
 
1456
            self._write_basis_inventory(xml)
1414
1457
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
1415
1458
            pass
1416
1459