52
52
At the moment this is stored in a simple textfile; it might be nice
53
53
to use a tdb instead.
55
The cache is represented as a map from file_id to a tuple of (file_id,
56
sha1, path, size, mtime, ctime, ino, dev).
71
58
def fingerprint(path, abspath):
82
69
fs.st_ctime, fs.st_ino, fs.st_dev)
85
def _write_cache(branch, entry_iter, dangerfiles):
72
def write_cache(branch, entry_iter):
86
73
from atomicfile import AtomicFile
88
outf = AtomicFile(branch.controlfilename('stat-cache'), 'wb', 'utf-8')
75
outf = AtomicFile(branch.controlfilename('work-cache.tmp'), 'wb')
90
77
for entry in entry_iter:
91
if entry[0] in dangerfiles:
93
78
outf.write(entry[0] + ' ' + entry[1] + ' ')
94
79
outf.write(b2a_qp(entry[2], True))
95
80
outf.write(' %d %d %d %d %d\n' % entry[3:])
126
111
yield ie.file_id, path
130
def update_cache(branch, inv=None, flush=False):
131
"""Update and return the cache for the branch.
133
The returned cache may contain entries that have not been written
134
to disk for files recently touched.
136
flush -- discard any previous cache and recalculate from scratch.
114
def build_cache(branch):
115
inv = branch.read_working_inventory()
118
_update_cache_from_list(branch, cache, _files_from_inventory(inv))
122
def update_cache(branch, inv):
140
123
# TODO: It's supposed to be faster to stat the files in order by inum.
141
124
# We don't directly know the inum of the files of course but we do
142
125
# know where they were last sighted, so we can sort by that.
144
assert isinstance(flush, bool)
148
cache = load_cache(branch)
150
inv = branch.read_working_inventory()
127
cache = load_cache(branch)
151
128
return _update_cache_from_list(branch, cache, _files_from_inventory(inv))
155
132
def _update_cache_from_list(branch, cache, to_update):
156
"""Update and return the cache for given files.
158
cache -- Previously cached values to be validated.
160
to_update -- Sequence of (file_id, path) pairs to check.
133
"""Update the cache to have info on the named files.
135
to_update is a sequence of (file_id, path) pairs.
165
137
hardcheck = dirty = 0
167
# files that have been recently touched and can't be
168
# committed to a persistent cache yet.
171
now = int(time.time())
173
138
for file_id, path in to_update:
174
139
fap = branch.abspath(path)
175
140
fp = fingerprint(fap, path)
198
160
cache[file_id] = cacheentry
201
mutter('statcache: read %d files, %d changed, %d dangerous, '
203
% (hardcheck, dirty, len(dangerfiles), len(cache)))
163
mutter('work cache: read %d files, %d changed' % (hardcheck, dirty))
206
mutter('updating on-disk statcache')
207
_write_cache(branch, cache.itervalues(), dangerfiles)
166
write_cache(branch, cache.itervalues())