1395
class TestIterChildEntries(TestCaseWithDirState):
1397
def create_dirstate_with_two_trees(self):
1398
"""This dirstate contains multiple files and directories.
1408
b/h\xc3\xa5 h-\xc3\xa5-file #This is u'\xe5' encoded into utf-8
1410
Notice that a/e is an empty directory.
1412
There is one parent tree, which has the same shape with the following variations:
1413
b/g in the parent is gone.
1414
b/h in the parent has a different id
1415
b/i is new in the parent
1416
c is renamed to b/j in the parent
1418
:return: The dirstate, still write-locked.
1420
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
1421
null_sha = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
1422
NULL_PARENT_DETAILS = dirstate.DirState.NULL_PARENT_DETAILS
1423
root_entry = ('', '', 'a-root-value'), [
1424
('d', '', 0, False, packed_stat),
1425
('d', '', 0, False, 'parent-revid'),
1427
a_entry = ('', 'a', 'a-dir'), [
1428
('d', '', 0, False, packed_stat),
1429
('d', '', 0, False, 'parent-revid'),
1431
b_entry = ('', 'b', 'b-dir'), [
1432
('d', '', 0, False, packed_stat),
1433
('d', '', 0, False, 'parent-revid'),
1435
c_entry = ('', 'c', 'c-file'), [
1436
('f', null_sha, 10, False, packed_stat),
1437
('r', 'b/j', 0, False, ''),
1439
d_entry = ('', 'd', 'd-file'), [
1440
('f', null_sha, 20, False, packed_stat),
1441
('f', 'd', 20, False, 'parent-revid'),
1443
e_entry = ('a', 'e', 'e-dir'), [
1444
('d', '', 0, False, packed_stat),
1445
('d', '', 0, False, 'parent-revid'),
1447
f_entry = ('a', 'f', 'f-file'), [
1448
('f', null_sha, 30, False, packed_stat),
1449
('f', 'f', 20, False, 'parent-revid'),
1451
g_entry = ('b', 'g', 'g-file'), [
1452
('f', null_sha, 30, False, packed_stat),
1453
NULL_PARENT_DETAILS,
1455
h_entry1 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file1'), [
1456
('f', null_sha, 40, False, packed_stat),
1457
NULL_PARENT_DETAILS,
1459
h_entry2 = ('b', 'h\xc3\xa5', 'h-\xc3\xa5-file2'), [
1460
NULL_PARENT_DETAILS,
1461
('f', 'h', 20, False, 'parent-revid'),
1463
i_entry = ('b', 'i', 'i-file'), [
1464
NULL_PARENT_DETAILS,
1465
('f', 'h', 20, False, 'parent-revid'),
1467
j_entry = ('b', 'j', 'c-file'), [
1468
('r', 'c', 0, False, ''),
1469
('f', 'j', 20, False, 'parent-revid'),
1472
dirblocks.append(('', [root_entry]))
1473
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry]))
1474
dirblocks.append(('a', [e_entry, f_entry]))
1475
dirblocks.append(('b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
1476
state = dirstate.DirState.initialize('dirstate')
1479
state._set_data(['parent'], dirblocks)
1483
return state, dirblocks
1485
def test_iter_children_b(self):
1486
state, dirblocks = self.create_dirstate_with_two_trees()
1487
self.addCleanup(state.unlock)
1488
expected_result = []
1489
expected_result.append(dirblocks[3][1][2]) # h2
1490
expected_result.append(dirblocks[3][1][3]) # i
1491
expected_result.append(dirblocks[3][1][4]) # j
1492
self.assertEqual(expected_result,
1493
list(state._iter_child_entries(1, 'b')))
1495
def test_iter_child_root(self):
1496
state, dirblocks = self.create_dirstate_with_two_trees()
1497
self.addCleanup(state.unlock)
1498
expected_result = []
1499
expected_result.append(dirblocks[1][1][0]) # a
1500
expected_result.append(dirblocks[1][1][1]) # b
1501
expected_result.append(dirblocks[1][1][3]) # d
1502
expected_result.append(dirblocks[2][1][0]) # e
1503
expected_result.append(dirblocks[2][1][1]) # f
1504
expected_result.append(dirblocks[3][1][2]) # h2
1505
expected_result.append(dirblocks[3][1][3]) # i
1506
expected_result.append(dirblocks[3][1][4]) # j
1507
self.assertEqual(expected_result,
1508
list(state._iter_child_entries(1, '')))
1397
1511
class TestDirstateSortOrder(TestCaseWithTransport):
1398
1512
"""Test that DirState adds entries in the right order."""