~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Get back to the broken-pending-revision-tree-from-dirstate state of development, changing dirstate from_tree to use _set_data rather than generating lines itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2070
2070
            hc.write()
2071
2071
 
2072
2072
        if _inventory is None:
2073
 
            self._set_inventory(self.read_working_inventory())
 
2073
            self._inventory_is_modified = False
 
2074
            self.read_working_inventory()
2074
2075
        else:
2075
 
            self._set_inventory(_inventory)
 
2076
            # the caller of __init__ has provided an inventory,
 
2077
            # we assume they know what they are doing - as its only
 
2078
            # the Format factory and creation methods that are
 
2079
            # permitted to do this.
 
2080
            self._set_inventory(_inventory, dirty=False)
2076
2081
        self._dirty = None
2077
2082
        self._parent_revisions = None
 
2083
        self._dirstate = None
 
2084
 
 
2085
    def current_dirstate(self):
 
2086
        """Return the current dirstate object. 
 
2087
 
 
2088
        This is not part of the tree interface and only exposed for ease of
 
2089
        testing.
 
2090
 
 
2091
        :raises errors.NotWriteLocked: when not in a lock. 
 
2092
            XXX: This should probably be errors.NotLocked.
 
2093
        """
 
2094
        if not self._control_files._lock_count:
 
2095
            raise errors.NotWriteLocked(self)
 
2096
        if self._dirstate is not None:
 
2097
            return self._dirstate
 
2098
        local_path = self.bzrdir.get_workingtree_transport(None
 
2099
            ).local_abspath('dirstate')
 
2100
        self._dirstate = dirstate.DirState.on_file(local_path)
 
2101
        return self._dirstate
2078
2102
 
2079
2103
    def _new_tree(self):
2080
2104
        """Initialize the state in this tree to be a new tree."""
2088
2112
 
2089
2113
        WorkingTree4 supplies revision_trees for any basis tree.
2090
2114
        """
2091
 
        local_path = self.bzrdir.get_workingtree_transport(None).local_abspath('dirstate')
2092
 
        self._dirstate = dirstate.DirState.on_file(local_path)
2093
 
        parent_ids = self._dirstate.get_parent_ids()
 
2115
        dirstate = self.current_dirstate()
 
2116
        parent_ids = dirstate.get_parent_ids()
2094
2117
        if revision_id not in parent_ids:
2095
2118
            raise errors.NoSuchRevisionInTree(self, revision_id)
 
2119
        raise NotImplementedError(self.revision_tree)
2096
2120
 
2097
2121
    @needs_write_lock
2098
2122
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
2125
2149
            If tree is None, then that element is treated as an unreachable
2126
2150
            parent tree - i.e. a ghost.
2127
2151
        """
 
2152
        dirstate = self.current_dirstate()
2128
2153
        if len(parents_list) > 0:
2129
2154
            if not allow_leftmost_as_ghost and parents_list[0][1] is None:
2130
2155
                raise errors.GhostRevisionUnusableHere(leftmost_id)
2131
 
            leftmost_id = parents_list[0][0]
2132
 
            #self.set_last_revision(leftmost_id)
2133
 
        else:
2134
 
            self.set_last_revision(None)
2135
 
        merges = [revid for revid, tree in parents_list[1:]]
2136
 
        self._control_files.put_utf8('pending-merges', '\n'.join(merges))
 
2156
        real_trees = []
 
2157
        ghosts = []
 
2158
        # convert absent trees to the null tree, which we convert back to 
 
2159
        # missing on access.
 
2160
        for rev_id, tree in parents_list:
 
2161
            if tree is not None:
 
2162
                real_trees.append((rev_id, tree))
 
2163
            else:
 
2164
                real_trees.append((rev_id,
 
2165
                    self.branch.repository.revision_tree(None)))
 
2166
                ghosts.append(rev_id)
 
2167
        dirstate.set_parent_trees(real_trees, ghosts=ghosts)
 
2168
        self._dirty = True
2137
2169
 
2138
2170
    def unlock(self):
2139
2171
        """Unlock in format 4 trees needs to write the entire dirstate."""
2144
2176
            # dirstate updates.
2145
2177
            if self._control_files._lock_mode == 'w':
2146
2178
                if self._dirty:
2147
 
                    self._write_dirstate()
 
2179
                    self.flush()
 
2180
            self._dirstate = None
2148
2181
        # reverse order of locking.
2149
2182
        try:
2150
2183
            return self._control_files.unlock()
2151
2184
        finally:
2152
2185
            self.branch.unlock()
2153
2186
 
2154
 
    def _write_dirstate(self):
 
2187
    def flush(self):
2155
2188
        """Write the full dirstate to disk."""
2156
 
        # in progress - not ready yet.
2157
 
        return
2158
 
        state_header = 'Bzr dirstate format 1'
2159
 
        checksum_line = ''
2160
 
        lines = [state_header, checksum_line]
2161
 
        lines.append("%s" % " ".join(self._parent_revisions))
2162
 
        kind_map = {
2163
 
            'root_directory':'r',
2164
 
            'file':'f',
2165
 
            'directory':'d',
2166
 
            'link':'l',
2167
 
            }
2168
 
        # root is not yielded by iter_entries_by_dir
2169
 
        entry = self._inventory.root
2170
 
        lines.append(kind_map[entry.kind])
2171
 
        lines.append('') # dir stats dont matter.
2172
 
        lines.append('') # and they have no sha1/link target
2173
 
        lines.append(entry.file_id)
2174
 
        lines.append('/')
2175
 
        lines.append('null:')
2176
 
        lines.append('')
2177
 
        lines.append('')
2178
 
        lines.append('')
2179
 
        lines.append('')
2180
 
        lines.append('')
2181
 
        lines.append('')
2182
 
        for path, entry in self._inventory.iter_entries_by_dir():
2183
 
            lines.append(kind_map[entry.kind])
2184
 
            lines.append(path)
2185
 
            # lines.append(entry.stat_blob)
2186
 
            # lines.append(entry.dirstate_value)
2187
 
 
2188
 
        self._control_files.put_utf8('dirstate', '\n'.join(lines))
 
2189
        self.current_dirstate().save()
2189
2190
        
2190
2191
 
2191
2192
def get_conflicted_stem(path):
2511
2512
            wt._write_inventory(inv)
2512
2513
            wt.set_root_id(inv.root.file_id)
2513
2514
            wt.set_last_revision(revision_id)
2514
 
            wt.set_pending_merges([])
2515
2515
            build_tree(wt.basis_tree(), wt)
2516
2516
        finally:
2517
2517
            control_files.unlock()