1032
1032
This takes the basic dirstate, and moves the paths around.
1034
1034
tree, state, expected = self.create_basic_dirstate()
1035
1036
tree.rename_one('a', 'b/g')
1038
tree.rename_one('b/d', 'h')
1037
1040
old_a = expected['a']
1038
1041
expected['a'] = (old_a[0], [('r', 'b/g', 0, False, ''), old_a[1][1]])
1039
1042
expected['b/g'] = (('b', 'g', 'a-id'), [old_a[1][0],
1040
1043
('r', 'a', 0, False, '')])
1044
old_d = expected['b/d']
1045
expected['b/d'] = (old_d[0], [('r', 'h', 0, False, ''), old_d[1][1]])
1046
expected['h'] = (('', 'h', 'd-id'), [old_d[1][0],
1047
('r', 'b/d', 0, False, '')])
1049
old_e = expected['b/d/e']
1050
expected['b/d/e'] = (old_e[0], [('r', 'h/e', 0, False, ''),
1052
expected['h/e'] = (('h', 'e', 'e-id'), [old_e[1][0],
1053
('r', 'b/d/e', 0, False, '')])
1043
1057
new_state = dirstate.DirState.from_tree(tree, 'dirstate')
1082
1096
def assertBisectDirBlocks(self, expected_map, map_keys, state, paths):
1083
1097
"""Assert that bisecting for dirbblocks returns the right result.
1085
:param expected: A map from path => expected values
1099
:param expected_map: A map from key => expected values
1086
1100
:param map_keys: A nested list of paths we expect to be returned.
1087
1101
Something like [['a', 'b', 'f'], ['b/c', 'b/d']]
1088
1102
:param state: The DirState object.
1103
1117
self.assertEqual(expected, result)
1119
def assertBisectRecursive(self, expected_map, map_keys, state, paths):
1120
"""Assert the return value of a recursive bisection.
1122
:param expected_map: A map from key => entry value
1123
:param map_keys: A list of paths we expect to be returned.
1124
Something like ['a', 'b', 'f', 'b/d', 'b/d2']
1125
:param state: The DirState object.
1126
:param paths: A list of files and directories. It will be broken up
1127
into (dir, name) pairs and sorted before calling _bisect_recursive.
1130
for key in map_keys:
1131
entry = expected_map[key]
1132
dir_name_id, trees_info = entry
1133
expected[dir_name_id] = trees_info
1135
dir_names = sorted(osutils.split(p) for p in paths)
1136
result = state._bisect_recursive(dir_names)
1138
self.assertEqual(expected, result)
1105
1140
def test_bisect_each(self):
1106
1141
"""Find a single record using bisect."""
1107
1142
tree, state, expected = self.create_basic_dirstate()
1185
1220
# Search for the pre and post renamed entries
1186
1221
self.assertBisect(expected, [['a']], state, ['a'])
1187
1222
self.assertBisect(expected, [['b/g']], state, ['b/g'])
1223
self.assertBisect(expected, [['b/d']], state, ['b/d'])
1224
self.assertBisect(expected, [['h']], state, ['h'])
1226
# What about b/d/e? shouldn't that also get 2 directory entries?
1227
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e'])
1228
self.assertBisect(expected, [['h/e']], state, ['h/e'])
1189
1230
def test_bisect_dirblocks(self):
1190
1231
tree, state, expected = self.create_duplicated_dirstate()
1210
1251
self.assertBisectDirBlocks(expected, [None], state, ['c'])
1211
1252
self.assertBisectDirBlocks(expected, [None], state, ['b/d/e'])
1212
1253
self.assertBisectDirBlocks(expected, [None], state, ['f'])
1255
def test_bisect_recursive_each(self):
1256
tree, state, expected = self.create_basic_dirstate()
1257
self.assertBisectRecursive(expected, ['a'], state, ['a'])
1258
self.assertBisectRecursive(expected, ['b/c'], state, ['b/c'])
1259
self.assertBisectRecursive(expected, ['b/d/e'], state, ['b/d/e'])
1260
self.assertBisectRecursive(expected, ['b/d', 'b/d/e'],
1262
self.assertBisectRecursive(expected, ['b', 'b/c', 'b/d', 'b/d/e'],
1264
self.assertBisectRecursive(expected, ['', 'a', 'b', 'f', 'b/c',
1268
def test_bisect_recursive_multiple(self):
1269
tree, state, expected = self.create_basic_dirstate()
1270
self.assertBisectRecursive(expected, ['a', 'b/c'], state, ['a', 'b/c'])
1271
self.assertBisectRecursive(expected, ['b/d', 'b/d/e'],
1272
state, ['b/d', 'b/d/e'])
1274
def test_bisect_recursive_missing(self):
1275
tree, state, expected = self.create_basic_dirstate()
1276
self.assertBisectRecursive(expected, [], state, ['d'])
1277
self.assertBisectRecursive(expected, [], state, ['b/e'])
1278
self.assertBisectRecursive(expected, [], state, ['g'])
1279
self.assertBisectRecursive(expected, ['a'], state, ['a', 'g'])
1281
def test_bisect_recursive_renamed(self):
1282
tree, state, expected = self.create_renamed_dirstate()
1284
# Looking for either renamed item should find the other
1285
self.assertBisectRecursive(expected, ['a', 'b/g'], state, ['a'])
1286
self.assertBisectRecursive(expected, ['a', 'b/g'], state, ['b/g'])
1287
# Looking in the containing directory should find the rename target,
1288
# and anything in a subdir of the renamed target.
1289
self.assertBisectRecursive(expected, ['a', 'b', 'b/c', 'b/d',
1290
'b/d/e', 'b/g', 'h', 'h/e'],