2311
2311
self.assertEqual(expected, state._find_block(key))
2316
class TestDiscardMergeParents(TestCaseWithDirState):
2318
def test_discard_no_parents(self):
2319
# This should be a no-op
2320
state = self.create_empty_dirstate()
2321
self.addCleanup(state.unlock)
2322
state._discard_merge_parents()
2325
def test_discard_one_parent(self):
2327
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
2328
root_entry_direntry = ('', '', 'a-root-value'), [
2329
('d', '', 0, False, packed_stat),
2330
('d', '', 0, False, packed_stat),
2333
dirblocks.append(('', [root_entry_direntry]))
2334
dirblocks.append(('', []))
2336
state = self.create_empty_dirstate()
2337
self.addCleanup(state.unlock)
2338
state._set_data(['parent-id'], dirblocks[:])
2341
state._discard_merge_parents()
2343
self.assertEqual(dirblocks, state._dirblocks)
2345
def test_discard_simple(self):
2347
packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
2348
root_entry_direntry = ('', '', 'a-root-value'), [
2349
('d', '', 0, False, packed_stat),
2350
('d', '', 0, False, packed_stat),
2351
('d', '', 0, False, packed_stat),
2353
expected_root_entry_direntry = ('', '', 'a-root-value'), [
2354
('d', '', 0, False, packed_stat),
2355
('d', '', 0, False, packed_stat),
2358
dirblocks.append(('', [root_entry_direntry]))
2359
dirblocks.append(('', []))
2361
state = self.create_empty_dirstate()
2362
self.addCleanup(state.unlock)
2363
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2366
# This should strip of the extra column
2367
state._discard_merge_parents()
2369
expected_dirblocks = [('', [expected_root_entry_direntry]), ('', [])]
2370
self.assertEqual(expected_dirblocks, state._dirblocks)
2372
def test_discard_absent(self):
2373
"""If entries are only in a merge, discard should remove the entries"""
2374
null_stat = dirstate.DirState.NULLSTAT
2375
present_dir = ('d', '', 0, False, null_stat)
2376
present_file = ('f', '', 0, False, null_stat)
2377
absent = dirstate.DirState.NULL_PARENT_DETAILS
2378
root_key = ('', '', 'a-root-value')
2379
file_in_root_key = ('', 'file-in-root', 'a-file-id')
2380
file_in_merged_key = ('', 'file-in-merged', 'b-file-id')
2381
dirblocks = [('', [(root_key, [present_dir, present_dir, present_dir])]),
2382
('', [(file_in_merged_key,
2383
[absent, absent, present_file]),
2385
[present_file, present_file, present_file]),
2389
state = self.create_empty_dirstate()
2390
self.addCleanup(state.unlock)
2391
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2394
exp_dirblocks = [('', [(root_key, [present_dir, present_dir])]),
2395
('', [(file_in_root_key,
2396
[present_file, present_file]),
2399
state._discard_merge_parents()
2401
self.assertEqual(exp_dirblocks, state._dirblocks)
2403
def test_discard_renamed(self):
2404
null_stat = dirstate.DirState.NULLSTAT
2405
present_dir = ('d', '', 0, False, null_stat)
2406
present_file = ('f', '', 0, False, null_stat)
2407
absent = dirstate.DirState.NULL_PARENT_DETAILS
2408
root_key = ('', '', 'a-root-value')
2409
file_in_root_key = ('', 'file-in-root', 'a-file-id')
2410
# Renamed relative to parent
2411
file_rename_s_key = ('', 'file-s', 'b-file-id')
2412
file_rename_t_key = ('', 'file-t', 'b-file-id')
2413
# And one that is renamed between the parents, but absent in this
2414
key_in_1 = ('', 'file-in-1', 'c-file-id')
2415
key_in_2 = ('', 'file-in-2', 'c-file-id')
2418
('', [(root_key, [present_dir, present_dir, present_dir])]),
2420
[absent, present_file, ('r', 'file-in-2', 'c-file-id')]),
2422
[absent, ('r', 'file-in-1', 'c-file-id'), present_file]),
2424
[present_file, present_file, present_file]),
2426
[('r', 'file-t', 'b-file-id'), absent, present_file]),
2428
[present_file, absent, ('r', 'file-s', 'b-file-id')]),
2432
('', [(root_key, [present_dir, present_dir])]),
2433
('', [(key_in_1, [absent, present_file]),
2434
(file_in_root_key, [present_file, present_file]),
2435
(file_rename_t_key, [present_file, absent]),
2438
state = self.create_empty_dirstate()
2439
self.addCleanup(state.unlock)
2440
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2443
state._discard_merge_parents()
2445
self.assertEqual(exp_dirblocks, state._dirblocks)
2447
def test_discard_all_subdir(self):
2448
null_stat = dirstate.DirState.NULLSTAT
2449
present_dir = ('d', '', 0, False, null_stat)
2450
present_file = ('f', '', 0, False, null_stat)
2451
absent = dirstate.DirState.NULL_PARENT_DETAILS
2452
root_key = ('', '', 'a-root-value')
2453
subdir_key = ('', 'sub', 'dir-id')
2454
child1_key = ('sub', 'child1', 'child1-id')
2455
child2_key = ('sub', 'child2', 'child2-id')
2456
child3_key = ('sub', 'child3', 'child3-id')
2459
('', [(root_key, [present_dir, present_dir, present_dir])]),
2460
('', [(subdir_key, [present_dir, present_dir, present_dir])]),
2461
('sub', [(child1_key, [absent, absent, present_file]),
2462
(child2_key, [absent, absent, present_file]),
2463
(child3_key, [absent, absent, present_file]),
2467
('', [(root_key, [present_dir, present_dir])]),
2468
('', [(subdir_key, [present_dir, present_dir])]),
2471
state = self.create_empty_dirstate()
2472
self.addCleanup(state.unlock)
2473
state._set_data(['parent-id', 'merged-id'], dirblocks[:])
2476
state._discard_merge_parents()
2478
self.assertEqual(exp_dirblocks, state._dirblocks)