93
93
self.addCleanup(transform.finalize)
94
94
return transform, transform.root
96
def get_transform_for_sha1_test(self):
97
trans, root = self.get_transform()
98
self.wt.lock_tree_write()
99
self.addCleanup(self.wt.unlock)
100
contents = ['just some content\n']
101
sha1 = osutils.sha_strings(contents)
102
# Roll back the clock
103
trans._creation_mtime = time.time() - 20.0
104
return trans, root, contents, sha1
96
106
def test_existing_limbo(self):
97
107
transform, root = self.get_transform()
98
108
limbo_name = transform._limbodir
161
171
transform.finalize()
162
172
transform.finalize()
174
def test_apply_informs_tree_of_observed_sha1(self):
175
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
176
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
179
orig = self.wt._observed_sha1
180
def _observed_sha1(*args):
183
self.wt._observed_sha1 = _observed_sha1
185
self.assertEqual([(None, 'file1', trans._observed_sha1s[trans_id])],
164
188
def test_create_file_caches_sha1(self):
165
trans, root = self.get_transform()
166
self.wt.lock_tree_write()
167
self.addCleanup(self.wt.unlock)
168
content = ['just some content\n']
169
sha1 = osutils.sha_strings(content)
189
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
170
190
trans_id = trans.create_path('file1', root)
171
# Roll back the clock
172
transform._creation_mtime = creation_mtime = time.time() - 20.0
173
trans.create_file(content, trans_id, sha1=sha1)
191
trans.create_file(contents, trans_id, sha1=sha1)
174
192
st_val = osutils.lstat(trans._limbo_name(trans_id))
175
193
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
176
194
self.assertEqual(o_sha1, sha1)
177
195
self.assertEqualStat(o_st_val, st_val)
179
197
def test__apply_insertions_updates_sha1(self):
180
trans, root = self.get_transform()
181
self.wt.lock_tree_write()
182
self.addCleanup(self.wt.unlock)
183
content = ['just some content\n']
184
sha1 = osutils.sha_strings(content)
198
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
185
199
trans_id = trans.create_path('file1', root)
186
# Roll back the clock
187
transform._creation_mtime = creation_mtime = time.time() - 20.0
188
trans.create_file(content, trans_id, sha1=sha1)
200
trans.create_file(contents, trans_id, sha1=sha1)
189
201
st_val = osutils.lstat(trans._limbo_name(trans_id))
190
202
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
191
203
self.assertEqual(o_sha1, sha1)
192
204
self.assertEqualStat(o_st_val, st_val)
193
creation_mtime += 10.0
205
creation_mtime = trans._creation_mtime + 10.0
194
206
# We fake a time difference from when the file was created until now it
195
207
# is being renamed by using os.utime. Note that the change we actually
196
208
# want to see is the real ctime change from 'os.rename()', but as long
203
215
self.assertEqualStat(o_st_val, new_st_val)
204
216
self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
218
def test_new_file_caches_sha1(self):
219
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
220
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
222
st_val = osutils.lstat(trans._limbo_name(trans_id))
223
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
224
self.assertEqual(o_sha1, sha1)
225
self.assertEqualStat(o_st_val, st_val)
227
def test_cancel_creation_removes_observed_sha1(self):
228
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
229
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
231
self.assertTrue(trans_id in trans._observed_sha1s)
232
trans.cancel_creation(trans_id)
233
self.assertFalse(trans_id in trans._observed_sha1s)
206
235
def test_create_files_same_timestamp(self):
207
236
transform, root = self.get_transform()
208
237
self.wt.lock_tree_write()