72
78
fs.st_ctime, fs.st_ino, fs.st_dev)
75
def _write_cache(branch, entry_iter):
81
def _write_cache(branch, entry_iter, dangerfiles):
76
82
from atomicfile import AtomicFile
78
84
outf = AtomicFile(branch.controlfilename('stat-cache'), 'wb', 'utf-8')
80
86
for entry in entry_iter:
87
if entry[0] in dangerfiles:
81
89
outf.write(entry[0] + ' ' + entry[1] + ' ')
82
90
outf.write(b2a_qp(entry[2], True))
83
91
outf.write(' %d %d %d %d %d\n' % entry[3:])
114
122
yield ie.file_id, path
117
def build_cache(branch):
118
inv = branch.read_working_inventory()
121
_update_cache_from_list(branch, cache, _files_from_inventory(inv))
126
def update_cache(branch, flush=False):
127
"""Update and return the cache for the branch.
129
The returned cache may contain entries that have not been written
130
to disk for files recently touched.
132
flush -- discard any previous cache and recalculate from scratch.
125
def update_cache(branch, inv):
126
136
# TODO: It's supposed to be faster to stat the files in order by inum.
127
137
# We don't directly know the inum of the files of course but we do
128
138
# know where they were last sighted, so we can sort by that.
130
cache = load_cache(branch)
143
cache = load_cache(branch)
144
inv = branch.read_working_inventory()
131
145
return _update_cache_from_list(branch, cache, _files_from_inventory(inv))
135
149
def _update_cache_from_list(branch, cache, to_update):
136
"""Update the cache to have info on the named files.
138
to_update is a sequence of (file_id, path) pairs.
150
"""Update and return the cache for given files.
152
cache -- Previously cached values to be validated.
154
to_update -- Sequence of (file_id, path) pairs to check.
140
159
hardcheck = dirty = 0
161
# files that have been recently touched and can't be
162
# committed to a persistent cache yet.
165
now = int(time.time())
141
167
for file_id, path in to_update:
142
168
fap = branch.abspath(path)
143
169
fp = fingerprint(fap, path)
163
192
cache[file_id] = cacheentry
166
mutter('statcache: read %d files, %d changed, %d in cache'
167
% (hardcheck, dirty, len(cache)))
195
mutter('statcache: read %d files, %d changed, %d dangerous, '
197
% (hardcheck, dirty, len(dangerfiles), len(cache)))
170
_write_cache(branch, cache.itervalues())
200
mutter('updating on-disk statcache')
201
_write_cache(branch, cache.itervalues(), dangerfiles)