~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-04 20:03:08 UTC
  • mfrom: (5824 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5828.
  • Revision ID: jelmer@samba.org-20110504200308-7dzetv0igs4gh5p2
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
    xml5,
69
69
    xml7,
70
70
    )
71
 
from bzrlib.workingtree_4 import (
72
 
    WorkingTreeFormat4,
73
 
    WorkingTreeFormat5,
74
 
    WorkingTreeFormat6,
75
 
    )
76
71
""")
77
72
 
78
73
from bzrlib import symbol_versioning
758
753
        self._set_merges_from_parent_ids(revision_ids)
759
754
 
760
755
    @needs_tree_write_lock
761
 
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
762
 
        """See MutableTree.set_parent_trees."""
763
 
        parent_ids = [rev for (rev, tree) in parents_list]
764
 
        for revision_id in parent_ids:
765
 
            _mod_revision.check_not_reserved_id(revision_id)
766
 
 
767
 
        self._check_parents_for_ghosts(parent_ids,
768
 
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
769
 
 
770
 
        parent_ids = self._filter_parent_ids_by_ancestry(parent_ids)
771
 
 
772
 
        if len(parent_ids) == 0:
773
 
            leftmost_parent_id = _mod_revision.NULL_REVISION
774
 
            leftmost_parent_tree = None
775
 
        else:
776
 
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
777
 
 
778
 
        if self._change_last_revision(leftmost_parent_id):
779
 
            if leftmost_parent_tree is None:
780
 
                # If we don't have a tree, fall back to reading the
781
 
                # parent tree from the repository.
782
 
                self._cache_basis_inventory(leftmost_parent_id)
783
 
            else:
784
 
                inv = leftmost_parent_tree.inventory
785
 
                xml = self._create_basis_xml_from_inventory(
786
 
                                        leftmost_parent_id, inv)
787
 
                self._write_basis_inventory(xml)
788
 
        self._set_merges_from_parent_ids(parent_ids)
789
 
 
790
 
    @needs_tree_write_lock
791
756
    def set_pending_merges(self, rev_list):
792
757
        parents = self.get_parent_ids()
793
758
        leftmost = parents[:1]
1985
1950
        """See Tree.iter_all_file_ids"""
1986
1951
        return set(self.inventory)
1987
1952
 
 
1953
    @needs_tree_write_lock
 
1954
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
 
1955
        """See MutableTree.set_parent_trees."""
 
1956
        parent_ids = [rev for (rev, tree) in parents_list]
 
1957
        for revision_id in parent_ids:
 
1958
            _mod_revision.check_not_reserved_id(revision_id)
 
1959
 
 
1960
        self._check_parents_for_ghosts(parent_ids,
 
1961
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
1962
 
 
1963
        parent_ids = self._filter_parent_ids_by_ancestry(parent_ids)
 
1964
 
 
1965
        if len(parent_ids) == 0:
 
1966
            leftmost_parent_id = _mod_revision.NULL_REVISION
 
1967
            leftmost_parent_tree = None
 
1968
        else:
 
1969
            leftmost_parent_id, leftmost_parent_tree = parents_list[0]
 
1970
 
 
1971
        if self._change_last_revision(leftmost_parent_id):
 
1972
            if leftmost_parent_tree is None:
 
1973
                # If we don't have a tree, fall back to reading the
 
1974
                # parent tree from the repository.
 
1975
                self._cache_basis_inventory(leftmost_parent_id)
 
1976
            else:
 
1977
                inv = leftmost_parent_tree.inventory
 
1978
                xml = self._create_basis_xml_from_inventory(
 
1979
                                        leftmost_parent_id, inv)
 
1980
                self._write_basis_inventory(xml)
 
1981
        self._set_merges_from_parent_ids(parent_ids)
 
1982
 
1988
1983
    def _cache_basis_inventory(self, new_revision):
1989
1984
        """Cache new_revision as the basis inventory."""
1990
1985
        # TODO: this should allow the ready-to-use inventory to be passed in,
2973
2968
    def __init__(self, other_registry=None):
2974
2969
        super(WorkingTreeFormatRegistry, self).__init__(other_registry)
2975
2970
        self._default_format = None
 
2971
        self._default_format_key = None
2976
2972
 
2977
2973
    def get_default(self):
2978
2974
        """Return the current default format."""
 
2975
        if (self._default_format_key is not None and
 
2976
            self._default_format is None):
 
2977
            self._default_format = self.get(self._default_format_key)
2979
2978
        return self._default_format
2980
2979
 
2981
2980
    def set_default(self, format):
 
2981
        """Set the default format."""
2982
2982
        self._default_format = format
 
2983
        self._default_format_key = None
 
2984
 
 
2985
    def set_default_key(self, format_string):
 
2986
        """Set the default format by its format string."""
 
2987
        self._default_format_key = format_string
 
2988
        self._default_format = None
2983
2989
 
2984
2990
 
2985
2991
format_registry = WorkingTreeFormatRegistry()
3015
3021
    """If this format supports missing parent conflicts."""
3016
3022
 
3017
3023
    @classmethod
 
3024
    def find_format_string(klass, a_bzrdir):
 
3025
        """Return format name for the working tree object in a_bzrdir."""
 
3026
        try:
 
3027
            transport = a_bzrdir.get_workingtree_transport(None)
 
3028
            return transport.get_bytes("format")
 
3029
        except errors.NoSuchFile:
 
3030
            raise errors.NoWorkingTree(base=transport.base)
 
3031
 
 
3032
    @classmethod
3018
3033
    def find_format(klass, a_bzrdir):
3019
3034
        """Return the format for the working tree object in a_bzrdir."""
3020
3035
        try:
3021
 
            transport = a_bzrdir.get_workingtree_transport(None)
3022
 
            format_string = transport.get_bytes("format")
 
3036
            format_string = klass.find_format_string(a_bzrdir)
3023
3037
            return format_registry.get(format_string)
3024
 
        except errors.NoSuchFile:
3025
 
            raise errors.NoWorkingTree(base=transport.base)
3026
3038
        except KeyError:
3027
3039
            raise errors.UnknownFormatError(format=format_string,
3028
3040
                                            kind="working tree")
3252
3264
        return self.get_format_string()
3253
3265
 
3254
3266
 
3255
 
__default_format = WorkingTreeFormat6()
3256
3267
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3257
3268
    "bzrlib.workingtree_4", "WorkingTreeFormat4")
3258
3269
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
3260
3271
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
3261
3272
    "bzrlib.workingtree_4", "WorkingTreeFormat6")
3262
3273
format_registry.register(WorkingTreeFormat3())
3263
 
format_registry.set_default(__default_format)
 
3274
format_registry.set_default_key("Bazaar Working Tree Format 6 (bzr 1.14)\n")