1173
1174
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1177
def _prepare_tree(self):
1179
text = 'Hello World\n'
1180
tree = self.make_branch_and_tree('tree')
1181
self.build_tree_contents([('tree/a file', text)])
1182
tree.add('a file', 'a-file-id')
1183
# Note: dirstate does not sha prior to the first commit
1184
# so commit now in order for the test to work
1185
tree.commit('first')
1188
def test_sha1provider_sha1_used(self):
1189
tree, text = self._prepare_tree()
1190
state = dirstate.DirState.from_tree(tree, 'dirstate',
1191
UppercaseSHA1Provider())
1192
self.addCleanup(state.unlock)
1193
expected_sha = osutils.sha_string(text.upper() + "foo")
1194
entry = state._get_entry(0, path_utf8='a file')
1195
state._sha_cutoff_time()
1196
state._cutoff_time += 10
1197
sha1 = dirstate.update_entry(state, entry, 'tree/a file',
1198
os.lstat('tree/a file'))
1199
self.assertEqual(expected_sha, sha1)
1201
def test_sha1provider_stat_and_sha1_used(self):
1202
tree, text = self._prepare_tree()
1204
self.addCleanup(tree.unlock)
1205
state = tree._current_dirstate()
1206
state._sha1_provider = UppercaseSHA1Provider()
1207
# If we used the standard provider, it would look like nothing has
1209
file_ids_changed = [change[0] for change
1210
in tree.iter_changes(tree.basis_tree())]
1211
self.assertEqual(['a-file-id'], file_ids_changed)
1214
class UppercaseSHA1Provider():
1215
"""A custom SHA1Provider."""
1217
def sha1(self, abspath):
1218
return self.stat_and_sha1(abspath)[1]
1220
def stat_and_sha1(self, abspath):
1221
file_obj = file(abspath, 'rb')
1223
statvalue = os.fstat(file_obj.fileno())
1224
text = ''.join(file_obj.readlines())
1225
sha1 = osutils.sha_string(text.upper() + "foo")
1228
return statvalue, sha1
1177
1231
class TestCompiledUpdateEntry(TestUpdateEntry):
1178
1232
"""Test the pyrex implementation of _read_dirblocks"""
1182
1236
def set_update_entry(self):
1183
1237
from bzrlib._dirstate_helpers_c import update_entry
1184
1238
self.update_entry = update_entry
1241
class TestProcessEntryPython(test_dirstate.TestCaseWithDirState):
1244
super(TestProcessEntryPython, self).setUp()
1245
self.setup_process_entry()
1247
def setup_process_entry(self):
1248
from bzrlib import dirstate
1249
orig = dirstate._process_entry
1251
dirstate._process_entry = orig
1252
self.addCleanup(cleanup)
1253
dirstate._process_entry = dirstate.ProcessEntryPython
1255
def assertChangedFileIds(self, expected, tree):
1258
file_ids = [info[0] for info
1259
in tree.iter_changes(tree.basis_tree())]
1262
self.assertEqual(sorted(expected), sorted(file_ids))
1264
def test_simple_changes(self):
1265
tree = self.make_branch_and_tree('tree')
1266
self.build_tree(['tree/file'])
1267
tree.add(['file'], ['file-id'])
1268
self.assertChangedFileIds([tree.get_root_id(), 'file-id'], tree)
1270
self.assertChangedFileIds([], tree)
1272
def test_sha1provider_stat_and_sha1_used(self):
1273
tree = self.make_branch_and_tree('tree')
1274
self.build_tree(['tree/file'])
1275
tree.add(['file'], ['file-id'])
1278
self.addCleanup(tree.unlock)
1279
state = tree._current_dirstate()
1280
state._sha1_provider = UppercaseSHA1Provider()
1281
self.assertChangedFileIds(['file-id'], tree)
1284
class TestProcessEntryC(TestProcessEntryPython):
1285
_test_needs_features = [CompiledDirstateHelpersFeature]
1287
def setup_process_entry(self):
1288
from bzrlib import _dirstate_helpers_c
1289
orig = dirstate._process_entry
1291
dirstate._process_entry = orig
1292
self.addCleanup(cleanup)
1293
dirstate._process_entry = _dirstate_helpers_c.ProcessEntryC