194
195
tree = self.make_branch_and_tree('tree')
195
paths = ['a', 'b/', 'b/c', 'b/d/', 'b/d/e', 'f']
196
file_ids = ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'f-id']
196
paths = ['a', 'b/', 'b/c', 'b/d/', 'b/d/e', 'b-c', 'f']
197
file_ids = ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'b-c-id', 'f-id']
197
198
self.build_tree(['tree/' + p for p in paths])
198
199
tree.set_root_id('TREE_ROOT')
199
200
tree.add([p.rstrip('/') for p in paths], file_ids)
214
215
e_text = t.get_bytes('b/d/e')
215
216
e_sha = osutils.sha_string(e_text)
216
217
e_len = len(e_text)
218
b_c_text = t.get_bytes('b-c')
219
b_c_sha = osutils.sha_string(b_c_text)
220
b_c_len = len(b_c_text)
217
221
# f_packed_stat = dirstate.pack_stat(os.stat('tree/f'))
218
222
f_text = t.get_bytes('f')
219
223
f_sha = osutils.sha_string(f_text)
244
248
('f', '', 0, False, null_stat),
245
249
('f', e_sha, e_len, False, revision_id),
251
'b-c':(('', 'b-c', 'b-c-id'), [
252
('f', '', 0, False, null_stat),
253
('f', b_c_sha, b_c_len, False, revision_id),
247
255
'f':(('', 'f', 'f-id'), [
248
256
('f', '', 0, False, null_stat),
249
257
('f', f_sha, f_len, False, revision_id),
276
284
tree, state, expected = self.create_basic_dirstate()
277
285
# Now we will just remove and add every file so we get an extra entry
278
286
# per entry. Unversion in reverse order so we handle subdirs
279
tree.unversion(['f-id', 'e-id', 'd-id', 'c-id', 'b-id', 'a-id'])
280
tree.add(['a', 'b', 'b/c', 'b/d', 'b/d/e', 'f'],
281
['a-id2', 'b-id2', 'c-id2', 'd-id2', 'e-id2', 'f-id2'])
287
tree.unversion(['f-id', 'b-c-id', 'e-id', 'd-id', 'c-id', 'b-id', 'a-id'])
288
tree.add(['a', 'b', 'b/c', 'b/d', 'b/d/e', 'b-c', 'f'],
289
['a-id2', 'b-id2', 'c-id2', 'd-id2', 'e-id2', 'b-c-id2', 'f-id2'])
283
291
# Update the expected dictionary.
284
for path in ['a', 'b', 'b/c', 'b/d', 'b/d/e', 'f']:
292
for path in ['a', 'b', 'b/c', 'b/d', 'b/d/e', 'b-c', 'f']:
285
293
orig = expected[path]
286
294
path2 = path + '2'
287
295
# This record was deleted in the current tree
1750
1759
(dir, name) tuples, and sorted according to how _bisect
1753
dir_names = sorted(osutils.split(p) for p in paths)
1754
result = state._bisect(dir_names)
1762
result = state._bisect(paths)
1755
1763
# For now, results are just returned in whatever order we read them.
1756
1764
# We could sort by (dir, name, file_id) or something like that, but in
1757
1765
# the end it would still be fairly arbitrary, and we don't want the
1758
1766
# extra overhead if we can avoid it. So sort everything to make sure
1759
1767
# equality is true
1760
assert len(map_keys) == len(dir_names)
1768
assert len(map_keys) == len(paths)
1762
for dir_name, keys in zip(dir_names, map_keys):
1770
for path, keys in zip(paths, map_keys):
1763
1771
if keys is None:
1764
1772
# This should not be present in the output
1766
expected[dir_name] = sorted(expected_map[k] for k in keys)
1774
expected[path] = sorted(expected_map[k] for k in keys)
1768
for dir_name in result:
1769
result[dir_name].sort()
1776
# The returned values are just arranged randomly based on when they
1777
# were read, for testing, make sure it is properly sorted.
1771
1781
self.assertEqual(expected, result)
1809
1819
dir_name_id, trees_info = entry
1810
1820
expected[dir_name_id] = trees_info
1812
dir_names = sorted(osutils.split(p) for p in paths)
1813
result = state._bisect_recursive(dir_names)
1822
result = state._bisect_recursive(paths)
1815
1824
self.assertEqual(expected, result)
1825
1834
self.assertBisect(expected, [['b/c']], state, ['b/c'])
1826
1835
self.assertBisect(expected, [['b/d']], state, ['b/d'])
1827
1836
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e'])
1837
self.assertBisect(expected, [['b-c']], state, ['b-c'])
1828
1838
self.assertBisect(expected, [['f']], state, ['f'])
1830
1840
def test_bisect_multi(self):
1836
1846
# ('', 'f') sorts before the others
1837
1847
self.assertBisect(expected, [['f'], ['b/d'], ['b/d/e']],
1838
1848
state, ['b/d', 'b/d/e', 'f'])
1849
self.assertBisect(expected, [['b'], ['b/c'], ['b-c']],
1850
state, ['b', 'b/c', 'b-c'])
1840
1852
def test_bisect_one_page(self):
1841
1853
"""Test bisect when there is only 1 page to read"""
1847
1859
self.assertBisect(expected,[['b/c']], state, ['b/c'])
1848
1860
self.assertBisect(expected,[['b/d']], state, ['b/d'])
1849
1861
self.assertBisect(expected,[['b/d/e']], state, ['b/d/e'])
1862
self.assertBisect(expected,[['b-c']], state, ['b-c'])
1850
1863
self.assertBisect(expected,[['f']], state, ['f'])
1851
1864
self.assertBisect(expected,[['a'], ['b'], ['f']],
1852
1865
state, ['a', 'b', 'f'])
1853
1866
# ('', 'f') sorts before the others
1854
1867
self.assertBisect(expected, [['f'], ['b/d'], ['b/d/e']],
1855
1868
state, ['b/d', 'b/d/e', 'f'])
1869
self.assertBisect(expected, [['b'], ['b/c'], ['b-c']],
1870
state, ['b', 'b/c', 'b-c'])
1857
1872
def test_bisect_duplicate_paths(self):
1858
1873
"""When bisecting for a path, handle multiple entries."""
1866
1881
self.assertBisect(expected, [['b/d', 'b/d2']], state, ['b/d'])
1867
1882
self.assertBisect(expected, [['b/d/e', 'b/d/e2']],
1868
1883
state, ['b/d/e'])
1884
self.assertBisect(expected, [['b-c', 'b-c2']], state, ['b-c'])
1869
1885
self.assertBisect(expected, [['f', 'f2']], state, ['f'])
1871
1887
def test_bisect_page_size_too_small(self):
1878
1894
self.assertBisect(expected, [['b/c']], state, ['b/c'])
1879
1895
self.assertBisect(expected, [['b/d']], state, ['b/d'])
1880
1896
self.assertBisect(expected, [['b/d/e']], state, ['b/d/e'])
1897
self.assertBisect(expected, [['b-c']], state, ['b-c'])
1881
1898
self.assertBisect(expected, [['f']], state, ['f'])
1883
1900
def test_bisect_missing(self):
1886
1903
self.assertBisect(expected, [None], state, ['foo'])
1887
1904
self.assertBisect(expected, [None], state, ['b/foo'])
1888
1905
self.assertBisect(expected, [None], state, ['bar/foo'])
1906
self.assertBisect(expected, [None], state, ['b-c/foo'])
1890
1908
self.assertBisect(expected, [['a'], None, ['b/d']],
1891
1909
state, ['a', 'foo', 'b/d'])
1907
1925
def test_bisect_dirblocks(self):
1908
1926
tree, state, expected = self.create_duplicated_dirstate()
1909
1927
self.assertBisectDirBlocks(expected,
1910
[['', 'a', 'a2', 'b', 'b2', 'f', 'f2']], state, [''])
1928
[['', 'a', 'a2', 'b', 'b2', 'b-c', 'b-c2', 'f', 'f2']],
1911
1930
self.assertBisectDirBlocks(expected,
1912
1931
[['b/c', 'b/c2', 'b/d', 'b/d2']], state, ['b'])
1913
1932
self.assertBisectDirBlocks(expected,
1914
1933
[['b/d/e', 'b/d/e2']], state, ['b/d'])
1915
1934
self.assertBisectDirBlocks(expected,
1916
[['', 'a', 'a2', 'b', 'b2', 'f', 'f2'],
1935
[['', 'a', 'a2', 'b', 'b2', 'b-c', 'b-c2', 'f', 'f2'],
1917
1936
['b/c', 'b/c2', 'b/d', 'b/d2'],
1918
1937
['b/d/e', 'b/d/e2'],
1919
1938
], state, ['', 'b', 'b/d'])
1934
1953
self.assertBisectRecursive(expected, ['a'], state, ['a'])
1935
1954
self.assertBisectRecursive(expected, ['b/c'], state, ['b/c'])
1936
1955
self.assertBisectRecursive(expected, ['b/d/e'], state, ['b/d/e'])
1956
self.assertBisectRecursive(expected, ['b-c'], state, ['b-c'])
1937
1957
self.assertBisectRecursive(expected, ['b/d', 'b/d/e'],
1938
1958
state, ['b/d'])
1939
1959
self.assertBisectRecursive(expected, ['b', 'b/c', 'b/d', 'b/d/e'],