~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

(broken) Add Tree.get_root_id() & test

Add unique root on WorkingTree4 at construction time and test this: currently
fails trying to set_path_id when the tree has parents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
import bzrlib.mutabletree
73
73
from bzrlib.mutabletree import needs_tree_write_lock
74
74
from bzrlib.osutils import (
75
 
    compact_date,
76
 
    file_kind,
77
75
    isdir,
78
76
    normpath,
79
77
    pathjoin,
81
79
    realpath,
82
80
    safe_unicode,
83
81
    splitpath,
84
 
    supports_executable,
85
82
    )
86
83
from bzrlib.trace import mutter, note
87
84
from bzrlib.transport.local import LocalTransport
93
90
        deprecated_method,
94
91
        deprecated_function,
95
92
        DEPRECATED_PARAMETER,
96
 
        zero_eight,
97
 
        zero_eleven,
98
 
        zero_thirteen,
99
93
        )
100
94
from bzrlib.tree import Tree
101
95
from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
1094
1088
    def initialize(self, a_bzrdir, revision_id=None):
1095
1089
        """See WorkingTreeFormat.initialize().
1096
1090
 
1097
 
        revision_id allows creating a working tree at a different
 
1091
        :param revision_id: allows creating a working tree at a different
1098
1092
        revision than the branch is at.
 
1093
 
 
1094
        These trees get an initial random root id.
1099
1095
        """
1100
1096
        revision_id = osutils.safe_revision_id(revision_id)
1101
1097
        if not isinstance(a_bzrdir.transport, LocalTransport):
1109
1105
        if revision_id is None:
1110
1106
            revision_id = branch.last_revision()
1111
1107
        local_path = transport.local_abspath('dirstate')
 
1108
        # write out new dirstate (must exist when we create the tree)
1112
1109
        state = dirstate.DirState.initialize(local_path)
1113
1110
        state.unlock()
1114
1111
        wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1119
1116
        wt._new_tree()
1120
1117
        wt.lock_tree_write()
1121
1118
        try:
1122
 
            #wt.current_dirstate().set_path_id('', NEWROOT)
1123
1119
            wt.set_last_revision(revision_id)
1124
1120
            wt.flush()
1125
1121
            basis = wt.basis_tree()
1126
1122
            basis.lock_read()
 
1123
            state = wt.current_dirstate()
 
1124
            # if the basis has a root id we have to use that; otherwise we use
 
1125
            # a new random one
 
1126
            basis_root_id = basis.get_root_id()
 
1127
            if basis_root_id is not None:
 
1128
                wt._set_root_id(basis_root_id)
 
1129
                wt.flush()
 
1130
            elif revision_id in (None, NULL_REVISION):
 
1131
                wt._set_root_id(generate_ids.gen_root_id())
 
1132
                wt.flush()
1127
1133
            transform.build_tree(basis, wt)
1128
1134
            basis.unlock()
1129
1135
        finally:
1186
1192
        pred = self.has_filename
1187
1193
        return set((p for p in paths if not pred(p)))
1188
1194
 
 
1195
    def get_root_id(self):
 
1196
        return self.path2id('')
 
1197
 
1189
1198
    def _get_parent_index(self):
1190
1199
        """Return the index in the dirstate referenced by this tree."""
1191
1200
        return self._dirstate.get_parent_ids().index(self._revision_id) + 1