37
31
from bzrlib.lockable_files import LockableFiles
38
32
from bzrlib.lockdir import LockDir
39
from bzrlib.mutabletree import MutableTree
40
33
from bzrlib.transport.local import LocalTransport
41
34
from bzrlib.workingtree import (
42
35
InventoryWorkingTree,
43
WorkingTreeFormatMetaDir,
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):
39
class WorkingTree3(InventoryWorkingTree):
93
40
"""This is the Format 3 working tree.
95
42
This differs from the base WorkingTree by:
139
86
self.branch.unlock()
142
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
89
class WorkingTreeFormat3(WorkingTreeFormat):
143
90
"""The second working tree format updated to record a format marker.
146
93
- exists within a metadir controlling .bzr
147
94
- includes an explicit version marker for the workingtree control
148
files, separate from the ControlDir format
95
files, separate from the BzrDir format
149
96
- modifies the hash cache format
150
97
- is new in bzr 0.8
151
98
- uses a LockDir to guard access for writes.
196
142
control_files = self._open_control_files(a_bzrdir)
197
143
control_files.create_lock()
198
144
control_files.lock_write()
199
transport.put_bytes('format', self.as_string(),
145
transport.put_bytes('format', self.get_format_string(),
200
146
mode=a_bzrdir._get_file_mode())
201
147
if from_branch is not None:
202
148
branch = from_branch
222
168
basis_tree = branch.repository.revision_tree(revision_id)
223
169
# only set an explicit root id if there is one to set.
224
if basis_tree.get_root_id() is not None:
170
if basis_tree.inventory.root is not None:
225
171
wt.set_root_id(basis_tree.get_root_id())
226
172
if revision_id == _mod_revision.NULL_REVISION:
227
173
wt.set_parent_trees([])
229
175
wt.set_parent_trees([(revision_id, basis_tree)])
230
176
transform.build_tree(basis_tree, wt)
231
for hook in MutableTree.hooks['post_build_tree']:
234
178
# Unlock in this order so that the unlock-triggers-flush in
235
179
# WorkingTree is given a chance to fire.