33
39
from bzrlib.transport.local import LocalTransport
34
40
from bzrlib.workingtree import (
35
41
InventoryWorkingTree,
42
WorkingTreeFormatMetaDir,
39
class WorkingTree3(InventoryWorkingTree):
46
class PreDirStateWorkingTree(InventoryWorkingTree):
48
def __init__(self, basedir='.', *args, **kwargs):
49
super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
50
# update the whole cache up front and write to disk if anything changed;
51
# in the future we might want to do this more selectively
52
# two possible ways offer themselves : in self._unlock, write the cache
53
# if needed, or, when the cache sees a change, append it to the hash
54
# cache file, and have the parser take the most recent entry for a
56
wt_trans = self.bzrdir.get_workingtree_transport(None)
57
cache_filename = wt_trans.local_abspath('stat-cache')
58
self._hashcache = hashcache.HashCache(basedir, cache_filename,
59
self.bzrdir._get_file_mode(),
60
self._content_filter_stack_provider())
63
# is this scan needed ? it makes things kinda slow.
67
trace.mutter("write hc")
70
def _write_hashcache_if_dirty(self):
71
"""Write out the hashcache if it is dirty."""
72
if self._hashcache.needs_write:
74
self._hashcache.write()
76
if e.errno not in (errno.EPERM, errno.EACCES):
78
# TODO: jam 20061219 Should this be a warning? A single line
79
# warning might be sufficient to let the user know what
81
trace.mutter('Could not write hashcache for %s\nError: %s',
82
self._hashcache.cache_file_name(), e)
85
def get_file_sha1(self, file_id, path=None, stat_value=None):
87
path = self._inventory.id2path(file_id)
88
return self._hashcache.get_sha1(path, stat_value)
91
class WorkingTree3(PreDirStateWorkingTree):
40
92
"""This is the Format 3 working tree.
42
94
This differs from the base WorkingTree by:
86
138
self.branch.unlock()
89
class WorkingTreeFormat3(WorkingTreeFormat):
141
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
90
142
"""The second working tree format updated to record a format marker.
93
145
- exists within a metadir controlling .bzr
94
146
- includes an explicit version marker for the workingtree control
95
files, separate from the BzrDir format
147
files, separate from the ControlDir format
96
148
- modifies the hash cache format
97
149
- is new in bzr 0.8
98
150
- uses a LockDir to guard access for writes.
142
195
control_files = self._open_control_files(a_bzrdir)
143
196
control_files.create_lock()
144
197
control_files.lock_write()
145
transport.put_bytes('format', self.get_format_string(),
198
transport.put_bytes('format', self.as_string(),
146
199
mode=a_bzrdir._get_file_mode())
147
200
if from_branch is not None:
148
201
branch = from_branch