105
105
self._new_parent = {}
106
106
# mapping of trans_id with new contents -> new file_kind
107
107
self._new_contents = {}
108
# mapping of trans_id => (sha1 of content, stat_value)
109
self._observed_sha1s = {}
108
110
# Set of trans_ids whose contents will be removed
109
111
self._removed_contents = set()
110
112
# Mapping of trans_id -> new execute-bit value
1272
1274
os.unlink(name)
1275
f.writelines(contents)
1276
if contents.__class__ is list:
1277
sha_digest = osutils.sha_strings(contents)
1278
f.writelines(contents)
1280
sha_value = osutils.sha()
1281
def observe_sha1(contents):
1282
sha_value_update = sha_value.update
1283
for content in contents:
1284
sha_value_update(content)
1286
f.writelines(observe_sha1(contents))
1287
sha_digest = sha_value.hexdigest()
1278
1290
self._set_mtime(name)
1279
1291
self._set_mode(trans_id, mode_id, S_ISREG)
1292
# It is unfortunate we have to use lstat instead of fstat, but we just
1293
# used utime and chmod on the file, so we need the accurate final
1295
self._observed_sha1s[trans_id] = (sha_digest, osutils.lstat(name))
1281
1297
def _read_file_chunks(self, trans_id):
1282
1298
cur_file = open(self._limbo_name(trans_id), 'rb')
1341
1357
def cancel_creation(self, trans_id):
1342
1358
"""Cancel the creation of new file contents."""
1343
1359
del self._new_contents[trans_id]
1360
if trans_id in self._observed_sha1s:
1361
del self._observed_sha1s[trans_id]
1344
1362
children = self._limbo_children.get(trans_id)
1345
1363
# if this is a limbo directory with children, move them before removing
1346
1364
# the directory
1829
1848
self.rename_count += 1
1849
# TODO: if trans_id in self._observed_sha1s, we should
1850
# re-stat the final target, since ctime will be
1851
# updated by the change.
1830
1852
if (trans_id in self._new_contents or
1831
1853
self.path_changed(trans_id)):
1832
1854
if trans_id in self._new_contents:
1838
1860
self._new_contents.clear()
1839
1861
return modified_paths
1863
def _apply_observed_sha1s(self):
1864
"""After we have finished renaming everything, update observed sha1s
1866
This has to be done after self._tree.apply_inventory_delta, otherwise
1867
it doesn't know anything about the files we are updating. Also, we want
1868
to do this as late as possible, so that most entries end up cached.
1870
# TODO: this doesn't update the stat information for directories. So
1871
# the first 'bzr status' will still need to rewrite
1872
# .bzr/checkout/dirstate. However, we at least don't need to
1873
# re-read all of the files.
1874
# TODO: If the operation took a while, we could do a time.sleep(3) here
1875
# to allow the clock to tick over and ensure we won't have any
1876
# problems. (we could observe start time, and finish time, and if
1877
# it is less than eg 10% overhead, add a sleep call.)
1878
paths = FinalPaths(self)
1879
for trans_id, observed in self._observed_sha1s.iteritems():
1880
path = paths.get_path(trans_id)
1881
# We could get the file_id, but dirstate prefers to use the path
1882
# anyway, and it is 'cheaper' to determine.
1883
# file_id = self._new_id[trans_id]
1884
self._tree._observed_sha1(None, path, observed)
1842
1887
class TransformPreview(DiskTreeTransform):
1843
1888
"""A TreeTransform for generating preview trees.