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
162
172
transform.finalize()
164
174
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)
175
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
170
176
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)
177
trans.create_file(contents, trans_id, sha1=sha1)
174
178
st_val = osutils.lstat(trans._limbo_name(trans_id))
175
179
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
176
180
self.assertEqual(o_sha1, sha1)
177
181
self.assertEqualStat(o_st_val, st_val)
179
183
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)
184
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
185
185
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)
186
trans.create_file(contents, trans_id, sha1=sha1)
189
187
st_val = osutils.lstat(trans._limbo_name(trans_id))
190
188
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
191
189
self.assertEqual(o_sha1, sha1)
192
190
self.assertEqualStat(o_st_val, st_val)
193
creation_mtime += 10.0
191
creation_mtime = trans._creation_mtime + 10.0
194
192
# We fake a time difference from when the file was created until now it
195
193
# is being renamed by using os.utime. Note that the change we actually
196
194
# want to see is the real ctime change from 'os.rename()', but as long
204
202
self.assertNotEqual(st_val.st_mtime, new_st_val.st_mtime)
206
204
def test_new_file_caches_sha1(self):
207
trans, root = self.get_transform()
208
self.wt.lock_tree_write()
209
self.addCleanup(self.wt.unlock)
210
content = ['just some content\n']
211
sha1 = osutils.sha_strings(content)
212
# Roll back the clock
213
transform._creation_mtime = creation_mtime = time.time() - 20.0
214
trans_id = trans.new_file('file1', root, content, file_id='file1-id',
205
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
206
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
216
208
st_val = osutils.lstat(trans._limbo_name(trans_id))
217
209
o_sha1, o_st_val = trans._observed_sha1s[trans_id]
218
210
self.assertEqual(o_sha1, sha1)
219
211
self.assertEqualStat(o_st_val, st_val)
213
def test_cancel_creation_removes_observed_sha1(self):
214
trans, root, contents, sha1 = self.get_transform_for_sha1_test()
215
trans_id = trans.new_file('file1', root, contents, file_id='file1-id',
217
self.assertTrue(trans_id in trans._observed_sha1s)
218
trans.cancel_creation(trans_id)
219
self.assertFalse(trans_id in trans._observed_sha1s)
221
221
def test_create_files_same_timestamp(self):
222
222
transform, root = self.get_transform()
223
223
self.wt.lock_tree_write()