913
778
state._validate()
915
780
state.set_parent_trees([('parent-revid', rt)], ghosts=[])
916
root_entry = (('', '', 'TREE_ROOT'),
917
[('d', '', 0, False, 'x'*32),
918
('d', '', 0, False, 'parent-revid')])
919
self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
920
self.assertEqual(root_entry,
921
state._get_entry(0, fileid_utf8='TREE_ROOT'))
922
self.assertEqual((None, None),
923
state._get_entry(0, fileid_utf8='Asecond-root-id'))
924
state.set_path_id('', 'Asecond-root-id')
781
state.set_path_id('', 'foobarbaz')
925
782
state._validate()
926
783
# now see that it is what we expected
927
old_root_entry = (('', '', 'TREE_ROOT'),
928
[('a', '', 0, False, ''),
929
('d', '', 0, False, 'parent-revid')])
930
new_root_entry = (('', '', 'Asecond-root-id'),
931
[('d', '', 0, False, ''),
932
('a', '', 0, False, '')])
933
expected_rows = [new_root_entry, old_root_entry]
785
(('', '', 'TREE_ROOT'),
786
[('a', '', 0, False, ''),
787
('d', '', 0, False, 'parent-revid'),
789
(('', '', 'foobarbaz'),
790
[('d', '', 0, False, ''),
791
('a', '', 0, False, ''),
934
794
state._validate()
935
795
self.assertEqual(expected_rows, list(state._iter_entries()))
936
self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
937
self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=''))
938
self.assertEqual((None, None),
939
state._get_entry(0, fileid_utf8='TREE_ROOT'))
940
self.assertEqual(old_root_entry,
941
state._get_entry(1, fileid_utf8='TREE_ROOT'))
942
self.assertEqual(new_root_entry,
943
state._get_entry(0, fileid_utf8='Asecond-root-id'))
944
self.assertEqual((None, None),
945
state._get_entry(1, fileid_utf8='Asecond-root-id'))
946
796
# should work across save too
1512
class TestIterChildEntries(TestCaseWithDirState):
1514
def create_dirstate_with_two_trees(self):
1515
"""This dirstate contains multiple files and directories.
1525
b/h\xc3\xa5 h-\xc3\xa5-file #This is u'\xe5' encoded into utf-8
1527
Notice that a/e is an empty directory.
1529
There is one parent tree, which has the same shape with the following variations:
1530
b/g in the parent is gone.
1531
b/h in the parent has a different id
1532
b/i is new in the parent
1533
c is renamed to b/j in the parent
1535
:return: The dirstate, still write-locked.
1537
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
1538
null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
1539
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1540
root_entry = ('', '', 'a-root-value'), [
1541
('d', '', 0, False, packed_stat),
1542
('d', '', 0, False, 'parent-revid'),
1544
a_entry = ('', 'a', 'a-dir'), [
1545
('d', '', 0, False, packed_stat),
1546
('d', '', 0, False, 'parent-revid'),
1548
b_entry = ('', 'b', 'b-dir'), [
1549
('d', '', 0, False, packed_stat),
1550
('d', '', 0, False, 'parent-revid'),
1552
c_entry = ('', 'c', 'c-file'), [
1553
('f', null_sha, 10, False, packed_stat),
1554
('r', 'b/j', 0, False, ''),
1556
d_entry = ('', 'd', 'd-file'), [
1557
('f', null_sha, 20, False, packed_stat),
1558
('f', 'd', 20, False, 'parent-revid'),
1560
e_entry = ('a', 'e', 'e-dir'), [
1561
('d', '', 0, False, packed_stat),
1562
('d', '', 0, False, 'parent-revid'),
1564
f_entry = ('a', 'f', 'f-file'), [
1565
('f', null_sha, 30, False, packed_stat),
1566
('f', 'f', 20, False, 'parent-revid'),
1568
g_entry = ('b', 'g', 'g-file'), [
1569
('f', null_sha, 30, False, packed_stat),
1570
NULL_PARENT_DETAILS,
1572
h_entry1 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file1'), [
1573
('f', null_sha, 40, False, packed_stat),
1574
NULL_PARENT_DETAILS,
1576
h_entry2 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file2'), [
1577
NULL_PARENT_DETAILS,
1578
('f', 'h', 20, False, 'parent-revid'),
1580
i_entry = ('b', 'i', 'i-file'), [
1581
NULL_PARENT_DETAILS,
1582
('f', 'h', 20, False, 'parent-revid'),
1584
j_entry = ('b', 'j', 'c-file'), [
1585
('r', 'c', 0, False, ''),
1586
('f', 'j', 20, False, 'parent-revid'),
1589
dirblocks.append(('', [root_entry]))
1590
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry]))
1591
dirblocks.append(('a', [e_entry, f_entry]))
1592
dirblocks.append(('b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
1593
state = dirstate.DirState.initialize('dirstate')
1596
state._set_data(['parent'], dirblocks)
1600
return state, dirblocks
1602
def test_iter_children_b(self):
1603
state, dirblocks = self.create_dirstate_with_two_trees()
1604
self.addCleanup(state.unlock)
1605
expected_result = []
1606
expected_result.append(dirblocks[3][1][2]) # h2
1607
expected_result.append(dirblocks[3][1][3]) # i
1608
expected_result.append(dirblocks[3][1][4]) # j
1609
self.assertEqual(expected_result,
1610
list(state._iter_child_entries(1, 'b')))
1612
def test_iter_child_root(self):
1613
state, dirblocks = self.create_dirstate_with_two_trees()
1614
self.addCleanup(state.unlock)
1615
expected_result = []
1616
expected_result.append(dirblocks[1][1][0]) # a
1617
expected_result.append(dirblocks[1][1][1]) # b
1618
expected_result.append(dirblocks[1][1][3]) # d
1619
expected_result.append(dirblocks[2][1][0]) # e
1620
expected_result.append(dirblocks[2][1][1]) # f
1621
expected_result.append(dirblocks[3][1][2]) # h2
1622
expected_result.append(dirblocks[3][1][3]) # i
1623
expected_result.append(dirblocks[3][1][4]) # j
1624
self.assertEqual(expected_result,
1625
list(state._iter_child_entries(1, '')))
1628
class TestDirstateSortOrder(tests.TestCaseWithTransport):
1333
class TestDirstateSortOrder(TestCaseWithTransport):
1629
1334
"""Test that DirState adds entries in the right order."""
1631
1336
def test_add_sorting(self):
1741
1443
self.st_ino = ino
1742
1444
self.st_mode = mode
1746
return _FakeStat(st.st_size, st.st_mtime, st.st_ctime, st.st_dev,
1747
st.st_ino, st.st_mode)
1750
class TestPackStat(tests.TestCaseWithTransport):
1447
class TestUpdateEntry(TestCaseWithDirState):
1448
"""Test the DirState.update_entry functions"""
1450
def get_state_with_a(self):
1451
"""Create a DirState tracking a single object named 'a'"""
1452
state = InstrumentedDirState.initialize('dirstate')
1453
self.addCleanup(state.unlock)
1454
state.add('a', 'a-id', 'file', None, '')
1455
entry = state._get_entry(0, path_utf8='a')
1458
def test_update_entry(self):
1459
state, entry = self.get_state_with_a()
1460
self.build_tree(['a'])
1461
# Add one where we don't provide the stat or sha already
1462
self.assertEqual(('', 'a', 'a-id'), entry[0])
1463
self.assertEqual([('f', '', 0, False, dirstate.DirState.NULLSTAT)],
1465
# Flush the buffers to disk
1467
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1468
state._dirblock_state)
1470
stat_value = os.lstat('a')
1471
packed_stat = dirstate.pack_stat(stat_value)
1472
link_or_sha1 = state.update_entry(entry, abspath='a',
1473
stat_value=stat_value)
1474
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1477
# The dirblock entry should not cache the file's sha1
1478
self.assertEqual([('f', '', 14, False, dirstate.DirState.NULLSTAT)],
1480
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1481
state._dirblock_state)
1482
mode = stat_value.st_mode
1483
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False)], state._log)
1486
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1487
state._dirblock_state)
1489
# If we do it again right away, we don't know if the file has changed
1490
# so we will re-read the file. Roll the clock back so the file is
1491
# guaranteed to look too new.
1492
state.adjust_time(-10)
1494
link_or_sha1 = state.update_entry(entry, abspath='a',
1495
stat_value=stat_value)
1496
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1497
('sha1', 'a'), ('is_exec', mode, False),
1499
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1501
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1502
state._dirblock_state)
1503
self.assertEqual([('f', '', 14, False, dirstate.DirState.NULLSTAT)],
1507
# However, if we move the clock forward so the file is considered
1508
# "stable", it should just cache the value.
1509
state.adjust_time(+20)
1510
link_or_sha1 = state.update_entry(entry, abspath='a',
1511
stat_value=stat_value)
1512
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1514
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1515
('sha1', 'a'), ('is_exec', mode, False),
1516
('sha1', 'a'), ('is_exec', mode, False),
1518
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
1521
# Subsequent calls will just return the cached value
1522
link_or_sha1 = state.update_entry(entry, abspath='a',
1523
stat_value=stat_value)
1524
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1526
self.assertEqual([('sha1', 'a'), ('is_exec', mode, False),
1527
('sha1', 'a'), ('is_exec', mode, False),
1528
('sha1', 'a'), ('is_exec', mode, False),
1530
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
1533
def test_update_entry_symlink(self):
1534
"""Update entry should read symlinks."""
1535
if not osutils.has_symlinks():
1536
# PlatformDeficiency / TestSkipped
1537
raise TestSkipped("No symlink support")
1538
state, entry = self.get_state_with_a()
1540
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1541
state._dirblock_state)
1542
os.symlink('target', 'a')
1544
state.adjust_time(-10) # Make the symlink look new
1545
stat_value = os.lstat('a')
1546
packed_stat = dirstate.pack_stat(stat_value)
1547
link_or_sha1 = state.update_entry(entry, abspath='a',
1548
stat_value=stat_value)
1549
self.assertEqual('target', link_or_sha1)
1550
self.assertEqual([('read_link', 'a', '')], state._log)
1551
# Dirblock is not updated (the link is too new)
1552
self.assertEqual([('l', '', 6, False, dirstate.DirState.NULLSTAT)],
1554
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1555
state._dirblock_state)
1557
# Because the stat_value looks new, we should re-read the target
1558
link_or_sha1 = state.update_entry(entry, abspath='a',
1559
stat_value=stat_value)
1560
self.assertEqual('target', link_or_sha1)
1561
self.assertEqual([('read_link', 'a', ''),
1562
('read_link', 'a', ''),
1564
self.assertEqual([('l', '', 6, False, dirstate.DirState.NULLSTAT)],
1566
state.adjust_time(+20) # Skip into the future, all files look old
1567
link_or_sha1 = state.update_entry(entry, abspath='a',
1568
stat_value=stat_value)
1569
self.assertEqual('target', link_or_sha1)
1570
# We need to re-read the link because only now can we cache it
1571
self.assertEqual([('read_link', 'a', ''),
1572
('read_link', 'a', ''),
1573
('read_link', 'a', ''),
1575
self.assertEqual([('l', 'target', 6, False, packed_stat)],
1578
# Another call won't re-read the link
1579
self.assertEqual([('read_link', 'a', ''),
1580
('read_link', 'a', ''),
1581
('read_link', 'a', ''),
1583
link_or_sha1 = state.update_entry(entry, abspath='a',
1584
stat_value=stat_value)
1585
self.assertEqual('target', link_or_sha1)
1586
self.assertEqual([('l', 'target', 6, False, packed_stat)],
1589
def do_update_entry(self, state, entry, abspath):
1590
stat_value = os.lstat(abspath)
1591
return state.update_entry(entry, abspath, stat_value)
1593
def test_update_entry_dir(self):
1594
state, entry = self.get_state_with_a()
1595
self.build_tree(['a/'])
1596
self.assertIs(None, self.do_update_entry(state, entry, 'a'))
1598
def test_update_entry_dir_unchanged(self):
1599
state, entry = self.get_state_with_a()
1600
self.build_tree(['a/'])
1601
state.adjust_time(+20)
1602
self.assertIs(None, self.do_update_entry(state, entry, 'a'))
1603
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1604
state._dirblock_state)
1606
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1607
state._dirblock_state)
1608
self.assertIs(None, self.do_update_entry(state, entry, 'a'))
1609
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1610
state._dirblock_state)
1612
def test_update_entry_file_unchanged(self):
1613
state, entry = self.get_state_with_a()
1614
self.build_tree(['a'])
1615
sha1sum = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1616
state.adjust_time(+20)
1617
self.assertEqual(sha1sum, self.do_update_entry(state, entry, 'a'))
1618
self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
1619
state._dirblock_state)
1621
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1622
state._dirblock_state)
1623
self.assertEqual(sha1sum, self.do_update_entry(state, entry, 'a'))
1624
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1625
state._dirblock_state)
1627
def create_and_test_file(self, state, entry):
1628
"""Create a file at 'a' and verify the state finds it.
1630
The state should already be versioning *something* at 'a'. This makes
1631
sure that state.update_entry recognizes it as a file.
1633
self.build_tree(['a'])
1634
stat_value = os.lstat('a')
1635
packed_stat = dirstate.pack_stat(stat_value)
1637
link_or_sha1 = self.do_update_entry(state, entry, abspath='a')
1638
self.assertEqual('b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6',
1640
self.assertEqual([('f', link_or_sha1, 14, False, packed_stat)],
1644
def create_and_test_dir(self, state, entry):
1645
"""Create a directory at 'a' and verify the state finds it.
1647
The state should already be versioning *something* at 'a'. This makes
1648
sure that state.update_entry recognizes it as a directory.
1650
self.build_tree(['a/'])
1651
stat_value = os.lstat('a')
1652
packed_stat = dirstate.pack_stat(stat_value)
1654
link_or_sha1 = self.do_update_entry(state, entry, abspath='a')
1655
self.assertIs(None, link_or_sha1)
1656
self.assertEqual([('d', '', 0, False, packed_stat)], entry[1])
1660
def create_and_test_symlink(self, state, entry):
1661
"""Create a symlink at 'a' and verify the state finds it.
1663
The state should already be versioning *something* at 'a'. This makes
1664
sure that state.update_entry recognizes it as a symlink.
1666
This should not be called if this platform does not have symlink
1669
# caller should care about skipping test on platforms without symlinks
1670
os.symlink('path/to/foo', 'a')
1672
stat_value = os.lstat('a')
1673
packed_stat = dirstate.pack_stat(stat_value)
1675
link_or_sha1 = self.do_update_entry(state, entry, abspath='a')
1676
self.assertEqual('path/to/foo', link_or_sha1)
1677
self.assertEqual([('l', 'path/to/foo', 11, False, packed_stat)],
1681
def test_update_file_to_dir(self):
1682
"""If a file changes to a directory we return None for the sha.
1683
We also update the inventory record.
1685
state, entry = self.get_state_with_a()
1686
# The file sha1 won't be cached unless the file is old
1687
state.adjust_time(+10)
1688
self.create_and_test_file(state, entry)
1690
self.create_and_test_dir(state, entry)
1692
def test_update_file_to_symlink(self):
1693
"""File becomes a symlink"""
1694
if not osutils.has_symlinks():
1695
# PlatformDeficiency / TestSkipped
1696
raise TestSkipped("No symlink support")
1697
state, entry = self.get_state_with_a()
1698
# The file sha1 won't be cached unless the file is old
1699
state.adjust_time(+10)
1700
self.create_and_test_file(state, entry)
1702
self.create_and_test_symlink(state, entry)
1704
def test_update_dir_to_file(self):
1705
"""Directory becoming a file updates the entry."""
1706
state, entry = self.get_state_with_a()
1707
# The file sha1 won't be cached unless the file is old
1708
state.adjust_time(+10)
1709
self.create_and_test_dir(state, entry)
1711
self.create_and_test_file(state, entry)
1713
def test_update_dir_to_symlink(self):
1714
"""Directory becomes a symlink"""
1715
if not osutils.has_symlinks():
1716
# PlatformDeficiency / TestSkipped
1717
raise TestSkipped("No symlink support")
1718
state, entry = self.get_state_with_a()
1719
# The symlink target won't be cached if it isn't old
1720
state.adjust_time(+10)
1721
self.create_and_test_dir(state, entry)
1723
self.create_and_test_symlink(state, entry)
1725
def test_update_symlink_to_file(self):
1726
"""Symlink becomes a file"""
1727
if not has_symlinks():
1728
raise TestSkipped("No symlink support")
1729
state, entry = self.get_state_with_a()
1730
# The symlink and file info won't be cached unless old
1731
state.adjust_time(+10)
1732
self.create_and_test_symlink(state, entry)
1734
self.create_and_test_file(state, entry)
1736
def test_update_symlink_to_dir(self):
1737
"""Symlink becomes a directory"""
1738
if not has_symlinks():
1739
raise TestSkipped("No symlink support")
1740
state, entry = self.get_state_with_a()
1741
# The symlink target won't be cached if it isn't old
1742
state.adjust_time(+10)
1743
self.create_and_test_symlink(state, entry)
1745
self.create_and_test_dir(state, entry)
1747
def test__is_executable_win32(self):
1748
state, entry = self.get_state_with_a()
1749
self.build_tree(['a'])
1751
# Make sure we are using the win32 implementation of _is_executable
1752
state._is_executable = state._is_executable_win32
1754
# The file on disk is not executable, but we are marking it as though
1755
# it is. With _is_executable_win32 we ignore what is on disk.
1756
entry[1][0] = ('f', '', 0, True, dirstate.DirState.NULLSTAT)
1758
stat_value = os.lstat('a')
1759
packed_stat = dirstate.pack_stat(stat_value)
1761
state.adjust_time(-10) # Make sure everything is new
1762
state.update_entry(entry, abspath='a', stat_value=stat_value)
1764
# The row is updated, but the executable bit stays set.
1765
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1768
# Make the disk object look old enough to cache
1769
state.adjust_time(+20)
1770
digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1771
state.update_entry(entry, abspath='a', stat_value=stat_value)
1772
self.assertEqual([('f', digest, 14, True, packed_stat)], entry[1])
1775
class TestPackStat(TestCaseWithTransport):
1752
1777
def assertPackStat(self, expected, stat_value):
1753
1778
"""Check the packed and serialized form of a stat value."""
2094
2120
self.assertContainsRe(str(e),
2095
2121
'file a-id is absent in row')
2098
class TestDirstateTreeReference(TestCaseWithDirState):
2100
def test_reference_revision_is_none(self):
2101
tree = self.make_branch_and_tree('tree', format='dirstate-with-subtree')
2102
subtree = self.make_branch_and_tree('tree/subtree',
2103
format='dirstate-with-subtree')
2104
subtree.set_root_id('subtree')
2105
tree.add_reference(subtree)
2107
state = dirstate.DirState.from_tree(tree, 'dirstate')
2108
key = ('', 'subtree', 'subtree')
2109
expected = ('', [(key,
2110
[('t', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])])
2113
self.assertEqual(expected, state._find_block(key))
2118
class TestDiscardMergeParents(TestCaseWithDirState):
2120
def test_discard_no_parents(self):
2121
# This should be a no-op
2122
state = self.create_empty_dirstate()
2123
self.addCleanup(state.unlock)
2124
state._discard_merge_parents()
2127
def test_discard_one_parent(self):
2129
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
2130
root_entry_direntry = ('', '', 'a-root-value'), [
2131
('d', '', 0, False, packed_stat),
2132
('d', '', 0, False, packed_stat),
2135
dirblocks.append(('', [root_entry_direntry]))
2136
dirblocks.append(('', []))
2138
state = self.create_empty_dirstate()
2139
self.addCleanup(state.unlock)
2140
state._set_data(['parent-id'], dirblocks[:])
2143
state._discard_merge_parents()
2145
self.assertEqual(dirblocks, state._dirblocks)
2147
def test_discard_simple(self):
2149
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
2150
root_entry_direntry = ('', '', 'a-root-value'), [
2151
('d', '', 0, False, packed_stat),
2152
('d', '', 0, False, packed_stat),
2153
('d', '', 0, False, packed_stat),
2155
expected_root_entry_direntry = ('', '', 'a-root-value'), [
2156
('d', '', 0, False, packed_stat),
2157
('d', '', 0, False, packed_stat),
2160
dirblocks.append(('', [root_entry_direntry]))
2161
dirblocks.append(('', []))
2163
state = self.create_empty_dirstate()
2164
self.addCleanup(state.unlock)
2165
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2168
# This should strip of the extra column
2169
state._discard_merge_parents()
2171
expected_dirblocks = [('', [expected_root_entry_direntry]), ('', [])]
2172
self.assertEqual(expected_dirblocks, state._dirblocks)
2174
def test_discard_absent(self):
2175
"""If entries are only in a merge, discard should remove the entries"""
2176
null_stat = dirstate.DirState.NULLSTAT
2177
present_dir = ('d', '', 0, False, null_stat)
2178
present_file = ('f', '', 0, False, null_stat)
2179
absent = dirstate.DirState.NULL_PARENT_DETAILS
2180
root_key = ('', '', 'a-root-value')
2181
file_in_root_key = ('', 'file-in-root', 'a-file-id')
2182
file_in_merged_key = ('', 'file-in-merged', 'b-file-id')
2183
dirblocks = [('', [(root_key, [present_dir, present_dir, present_dir])]),
2184
('', [(file_in_merged_key,
2185
[absent, absent, present_file]),
2187
[present_file, present_file, present_file]),
2191
state = self.create_empty_dirstate()
2192
self.addCleanup(state.unlock)
2193
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2196
exp_dirblocks = [('', [(root_key, [present_dir, present_dir])]),
2197
('', [(file_in_root_key,
2198
[present_file, present_file]),
2201
state._discard_merge_parents()
2203
self.assertEqual(exp_dirblocks, state._dirblocks)
2205
def test_discard_renamed(self):
2206
null_stat = dirstate.DirState.NULLSTAT
2207
present_dir = ('d', '', 0, False, null_stat)
2208
present_file = ('f', '', 0, False, null_stat)
2209
absent = dirstate.DirState.NULL_PARENT_DETAILS
2210
root_key = ('', '', 'a-root-value')
2211
file_in_root_key = ('', 'file-in-root', 'a-file-id')
2212
# Renamed relative to parent
2213
file_rename_s_key = ('', 'file-s', 'b-file-id')
2214
file_rename_t_key = ('', 'file-t', 'b-file-id')
2215
# And one that is renamed between the parents, but absent in this
2216
key_in_1 = ('', 'file-in-1', 'c-file-id')
2217
key_in_2 = ('', 'file-in-2', 'c-file-id')
2220
('', [(root_key, [present_dir, present_dir, present_dir])]),
2222
[absent, present_file, ('r', 'file-in-2', 'c-file-id')]),
2224
[absent, ('r', 'file-in-1', 'c-file-id'), present_file]),
2226
[present_file, present_file, present_file]),
2228
[('r', 'file-t', 'b-file-id'), absent, present_file]),
2230
[present_file, absent, ('r', 'file-s', 'b-file-id')]),
2234
('', [(root_key, [present_dir, present_dir])]),
2235
('', [(key_in_1, [absent, present_file]),
2236
(file_in_root_key, [present_file, present_file]),
2237
(file_rename_t_key, [present_file, absent]),
2240
state = self.create_empty_dirstate()
2241
self.addCleanup(state.unlock)
2242
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2245
state._discard_merge_parents()
2247
self.assertEqual(exp_dirblocks, state._dirblocks)
2249
def test_discard_all_subdir(self):
2250
null_stat = dirstate.DirState.NULLSTAT
2251
present_dir = ('d', '', 0, False, null_stat)
2252
present_file = ('f', '', 0, False, null_stat)
2253
absent = dirstate.DirState.NULL_PARENT_DETAILS
2254
root_key = ('', '', 'a-root-value')
2255
subdir_key = ('', 'sub', 'dir-id')
2256
child1_key = ('sub', 'child1', 'child1-id')
2257
child2_key = ('sub', 'child2', 'child2-id')
2258
child3_key = ('sub', 'child3', 'child3-id')
2261
('', [(root_key, [present_dir, present_dir, present_dir])]),
2262
('', [(subdir_key, [present_dir, present_dir, present_dir])]),
2263
('sub', [(child1_key, [absent, absent, present_file]),
2264
(child2_key, [absent, absent, present_file]),
2265
(child3_key, [absent, absent, present_file]),
2269
('', [(root_key, [present_dir, present_dir])]),
2270
('', [(subdir_key, [present_dir, present_dir])]),
2273
state = self.create_empty_dirstate()
2274
self.addCleanup(state.unlock)
2275
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2278
state._discard_merge_parents()
2280
self.assertEqual(exp_dirblocks, state._dirblocks)
2283
class Test_InvEntryToDetails(tests.TestCase):
2285
def assertDetails(self, expected, inv_entry):
2286
details = dirstate.DirState._inv_entry_to_details(inv_entry)
2287
self.assertEqual(expected, details)
2288
# details should always allow join() and always be a plain str when
2290
(minikind, fingerprint, size, executable, tree_data) = details
2291
self.assertIsInstance(minikind, str)
2292
self.assertIsInstance(fingerprint, str)
2293
self.assertIsInstance(tree_data, str)
2295
def test_unicode_symlink(self):
2296
inv_entry = inventory.InventoryLink('link-file-id',
2297
u'nam\N{Euro Sign}e',
2299
inv_entry.revision = 'link-revision-id'
2300
target = u'link-targ\N{Euro Sign}t'
2301
inv_entry.symlink_target = target
2302
self.assertDetails(('l', target.encode('UTF-8'), 0, False,
2303
'link-revision-id'), inv_entry)
2306
class TestSHA1Provider(tests.TestCaseInTempDir):
2308
def test_sha1provider_is_an_interface(self):
2309
p = dirstate.SHA1Provider()
2310
self.assertRaises(NotImplementedError, p.sha1, "foo")
2311
self.assertRaises(NotImplementedError, p.stat_and_sha1, "foo")
2313
def test_defaultsha1provider_sha1(self):
2314
text = 'test\r\nwith\nall\rpossible line endings\r\n'
2315
self.build_tree_contents([('foo', text)])
2316
expected_sha = osutils.sha_string(text)
2317
p = dirstate.DefaultSHA1Provider()
2318
self.assertEqual(expected_sha, p.sha1('foo'))
2320
def test_defaultsha1provider_stat_and_sha1(self):
2321
text = 'test\r\nwith\nall\rpossible line endings\r\n'
2322
self.build_tree_contents([('foo', text)])
2323
expected_sha = osutils.sha_string(text)
2324
p = dirstate.DefaultSHA1Provider()
2325
statvalue, sha1 = p.stat_and_sha1('foo')
2326
self.assertTrue(len(statvalue) >= 10)
2327
self.assertEqual(len(text), statvalue.st_size)
2328
self.assertEqual(expected_sha, sha1)