31
37
from bzrlib.lockable_files import LockableFiles
32
38
from bzrlib.lockdir import LockDir
39
from bzrlib.mutabletree import MutableTree
33
40
from bzrlib.transport.local import LocalTransport
34
41
from bzrlib.workingtree import (
35
42
InventoryWorkingTree,
43
WorkingTreeFormatMetaDir,
39
class WorkingTree3(InventoryWorkingTree):
47
class PreDirStateWorkingTree(InventoryWorkingTree):
49
def __init__(self, basedir='.', *args, **kwargs):
50
super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
51
# update the whole cache up front and write to disk if anything changed;
52
# in the future we might want to do this more selectively
53
# two possible ways offer themselves : in self._unlock, write the cache
54
# if needed, or, when the cache sees a change, append it to the hash
55
# cache file, and have the parser take the most recent entry for a
57
wt_trans = self.bzrdir.get_workingtree_transport(None)
58
cache_filename = wt_trans.local_abspath('stat-cache')
59
self._hashcache = hashcache.HashCache(basedir, cache_filename,
60
self.bzrdir._get_file_mode(),
61
self._content_filter_stack_provider())
64
# is this scan needed ? it makes things kinda slow.
68
trace.mutter("write hc")
71
def _write_hashcache_if_dirty(self):
72
"""Write out the hashcache if it is dirty."""
73
if self._hashcache.needs_write:
75
self._hashcache.write()
77
if e.errno not in (errno.EPERM, errno.EACCES):
79
# TODO: jam 20061219 Should this be a warning? A single line
80
# warning might be sufficient to let the user know what
82
trace.mutter('Could not write hashcache for %s\nError: %s',
83
self._hashcache.cache_file_name(), e)
86
def get_file_sha1(self, file_id, path=None, stat_value=None):
88
path = self._inventory.id2path(file_id)
89
return self._hashcache.get_sha1(path, stat_value)
92
class WorkingTree3(PreDirStateWorkingTree):
40
93
"""This is the Format 3 working tree.
42
95
This differs from the base WorkingTree by:
86
139
self.branch.unlock()
89
class WorkingTreeFormat3(WorkingTreeFormat):
142
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
90
143
"""The second working tree format updated to record a format marker.
93
146
- exists within a metadir controlling .bzr
94
147
- includes an explicit version marker for the workingtree control
95
files, separate from the BzrDir format
148
files, separate from the ControlDir format
96
149
- modifies the hash cache format
97
150
- is new in bzr 0.8
98
151
- uses a LockDir to guard access for writes.
142
196
control_files = self._open_control_files(a_bzrdir)
143
197
control_files.create_lock()
144
198
control_files.lock_write()
145
transport.put_bytes('format', self.get_format_string(),
199
transport.put_bytes('format', self.as_string(),
146
200
mode=a_bzrdir._get_file_mode())
147
201
if from_branch is not None:
148
202
branch = from_branch
168
222
basis_tree = branch.repository.revision_tree(revision_id)
169
223
# only set an explicit root id if there is one to set.
170
if basis_tree.inventory.root is not None:
224
if basis_tree.get_root_id() is not None:
171
225
wt.set_root_id(basis_tree.get_root_id())
172
226
if revision_id == _mod_revision.NULL_REVISION:
173
227
wt.set_parent_trees([])
175
229
wt.set_parent_trees([(revision_id, basis_tree)])
176
230
transform.build_tree(basis_tree, wt)
231
for hook in MutableTree.hooks['post_build_tree']:
178
234
# Unlock in this order so that the unlock-triggers-flush in
179
235
# WorkingTree is given a chance to fire.