~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Alexander Belchenko
  • Date: 2007-11-19 22:54:30 UTC
  • mfrom: (3006 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3008.
  • Revision ID: bialix@ukr.net-20071119225430-x0ewosrsagis0yno
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
359
359
        # There are no files on disk and no parents
360
360
        tree = self.make_branch_and_tree('tree')
361
361
        expected_result = ([], [
362
 
            (('', '', tree.path2id('')), # common details
 
362
            (('', '', tree.get_root_id()), # common details
363
363
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
364
364
             ])])
365
365
        state = dirstate.DirState.from_tree(tree, 'dirstate')
372
372
        rev_id = tree.commit('first post').encode('utf8')
373
373
        root_stat_pack = dirstate.pack_stat(os.stat(tree.basedir))
374
374
        expected_result = ([rev_id], [
375
 
            (('', '', tree.path2id('')), # common details
 
375
            (('', '', tree.get_root_id()), # common details
376
376
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
377
377
              ('d', '', 0, False, rev_id), # first parent details
378
378
             ])])
392
392
        rev_id2 = tree2.commit('second post', allow_pointless=True)
393
393
        tree.merge_from_branch(tree2.branch)
394
394
        expected_result = ([rev_id, rev_id2], [
395
 
            (('', '', tree.path2id('')), # common details
 
395
            (('', '', tree.get_root_id()), # common details
396
396
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
397
397
              ('d', '', 0, False, rev_id), # first parent details
398
398
              ('d', '', 0, False, rev_id2), # second parent details
411
411
        tree = self.make_branch_and_tree('tree')
412
412
        self.build_tree(['tree/unknown'])
413
413
        expected_result = ([], [
414
 
            (('', '', tree.path2id('')), # common details
 
414
            (('', '', tree.get_root_id()), # common details
415
415
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
416
416
             ])])
417
417
        state = dirstate.DirState.from_tree(tree, 'dirstate')
428
428
        # There are files on disk and no parents
429
429
        tree = self.get_tree_with_a_file()
430
430
        expected_result = ([], [
431
 
            (('', '', tree.path2id('')), # common details
 
431
            (('', '', tree.get_root_id()), # common details
432
432
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
433
433
             ]),
434
434
            (('', 'a file', 'a file id'), # common
446
446
        # and length:
447
447
        self.build_tree_contents([('tree/a file', 'new content\n')])
448
448
        expected_result = ([rev_id], [
449
 
            (('', '', tree.path2id('')), # common details
 
449
            (('', '', tree.get_root_id()), # common details
450
450
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
451
451
              ('d', '', 0, False, rev_id), # first parent details
452
452
             ]),
473
473
        # and length again, giving us three distinct values:
474
474
        self.build_tree_contents([('tree/a file', 'new content\n')])
475
475
        expected_result = ([rev_id, rev_id2], [
476
 
            (('', '', tree.path2id('')), # common details
 
476
            (('', '', tree.get_root_id()), # common details
477
477
             [('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
478
478
              ('d', '', 0, False, rev_id), # first parent details
479
479
              ('d', '', 0, False, rev_id2), # second parent details
525
525
        # get a state object
526
526
        # no parents, default tree content
527
527
        expected_result = ([], [
528
 
            (('', '', tree.path2id('')), # common details
 
528
            (('', '', tree.get_root_id()), # common details
529
529
             # current tree details, but new from_tree skips statting, it
530
530
             # uses set_state_from_inventory, and thus depends on the
531
531
             # inventory state.
678
678
        try:
679
679
            tree1.add('')
680
680
            revid1 = tree1.commit('foo').encode('utf8')
681
 
            root_id = tree1.inventory.root.file_id
 
681
            root_id = tree1.get_root_id()
682
682
            inv = tree1.inventory
683
683
        finally:
684
684
            tree1.unlock()
892
892
        tree2.lock_write()
893
893
        try:
894
894
            revid2 = tree2.commit('foo')
895
 
            root_id = tree2.inventory.root.file_id
 
895
            root_id = tree2.get_root_id()
896
896
        finally:
897
897
            tree2.unlock()
898
898
        state = dirstate.DirState.initialize('dirstate')
962
962
        try:
963
963
            tree2.put_file_bytes_non_atomic('file-id', 'new file-content')
964
964
            revid2 = tree2.commit('foo')
965
 
            root_id = tree2.inventory.root.file_id
 
965
            root_id = tree2.get_root_id()
966
966
        finally:
967
967
            tree2.unlock()
968
968
        # check the layout in memory
2311
2311
            self.assertEqual(expected, state._find_block(key))
2312
2312
        finally:
2313
2313
            state.unlock()
 
2314
 
 
2315
 
 
2316
class TestDiscardMergeParents(TestCaseWithDirState):
 
2317
 
 
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()
 
2323
        state._validate()
 
2324
 
 
2325
    def test_discard_one_parent(self):
 
2326
        # No-op
 
2327
        packed_stat = 'AAAAREUHaIpFB2iKAAADAQAtkqUAAIGk'
 
2328
        root_entry_direntry = ('', '', 'a-root-value'), [
 
2329
            ('d', '', 0, False, packed_stat),
 
2330
            ('d', '', 0, False, packed_stat),
 
2331
            ]
 
2332
        dirblocks = []
 
2333
        dirblocks.append(('', [root_entry_direntry]))
 
2334
        dirblocks.append(('', []))
 
2335
 
 
2336
        state = self.create_empty_dirstate()
 
2337
        self.addCleanup(state.unlock)
 
2338
        state._set_data(['parent-id'], dirblocks[:])
 
2339
        state._validate()
 
2340
 
 
2341
        state._discard_merge_parents()
 
2342
        state._validate()
 
2343
        self.assertEqual(dirblocks, state._dirblocks)
 
2344
 
 
2345
    def test_discard_simple(self):
 
2346
        # No-op
 
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),
 
2352
            ]
 
2353
        expected_root_entry_direntry = ('', '', 'a-root-value'), [
 
2354
            ('d', '', 0, False, packed_stat),
 
2355
            ('d', '', 0, False, packed_stat),
 
2356
            ]
 
2357
        dirblocks = []
 
2358
        dirblocks.append(('', [root_entry_direntry]))
 
2359
        dirblocks.append(('', []))
 
2360
 
 
2361
        state = self.create_empty_dirstate()
 
2362
        self.addCleanup(state.unlock)
 
2363
        state._set_data(['parent-id', 'merged-id'], dirblocks[:])
 
2364
        state._validate()
 
2365
 
 
2366
        # This should strip of the extra column
 
2367
        state._discard_merge_parents()
 
2368
        state._validate()
 
2369
        expected_dirblocks = [('', [expected_root_entry_direntry]), ('', [])]
 
2370
        self.assertEqual(expected_dirblocks, state._dirblocks)
 
2371
 
 
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]),
 
2384
                           (file_in_root_key,
 
2385
                            [present_file, present_file, present_file]),
 
2386
                          ]),
 
2387
                    ]
 
2388
 
 
2389
        state = self.create_empty_dirstate()
 
2390
        self.addCleanup(state.unlock)
 
2391
        state._set_data(['parent-id', 'merged-id'], dirblocks[:])
 
2392
        state._validate()
 
2393
 
 
2394
        exp_dirblocks = [('', [(root_key, [present_dir, present_dir])]),
 
2395
                         ('', [(file_in_root_key,
 
2396
                                [present_file, present_file]),
 
2397
                              ]),
 
2398
                        ]
 
2399
        state._discard_merge_parents()
 
2400
        state._validate()
 
2401
        self.assertEqual(exp_dirblocks, state._dirblocks)
 
2402
 
 
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')
 
2416
 
 
2417
        dirblocks = [
 
2418
            ('', [(root_key, [present_dir, present_dir, present_dir])]),
 
2419
            ('', [(key_in_1,
 
2420
                   [absent, present_file, ('r', 'file-in-2', 'c-file-id')]),
 
2421
                  (key_in_2,
 
2422
                   [absent, ('r', 'file-in-1', 'c-file-id'), present_file]),
 
2423
                  (file_in_root_key,
 
2424
                   [present_file, present_file, present_file]),
 
2425
                  (file_rename_s_key,
 
2426
                   [('r', 'file-t', 'b-file-id'), absent, present_file]),
 
2427
                  (file_rename_t_key,
 
2428
                   [present_file, absent, ('r', 'file-s', 'b-file-id')]),
 
2429
                 ]),
 
2430
        ]
 
2431
        exp_dirblocks = [
 
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]),
 
2436
                 ]),
 
2437
        ]
 
2438
        state = self.create_empty_dirstate()
 
2439
        self.addCleanup(state.unlock)
 
2440
        state._set_data(['parent-id', 'merged-id'], dirblocks[:])
 
2441
        state._validate()
 
2442
 
 
2443
        state._discard_merge_parents()
 
2444
        state._validate()
 
2445
        self.assertEqual(exp_dirblocks, state._dirblocks)
 
2446
 
 
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')
 
2457
 
 
2458
        dirblocks = [
 
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]),
 
2464
                    ]),
 
2465
        ]
 
2466
        exp_dirblocks = [
 
2467
            ('', [(root_key, [present_dir, present_dir])]),
 
2468
            ('', [(subdir_key, [present_dir, present_dir])]),
 
2469
            ('sub', []),
 
2470
        ]
 
2471
        state = self.create_empty_dirstate()
 
2472
        self.addCleanup(state.unlock)
 
2473
        state._set_data(['parent-id', 'merged-id'], dirblocks[:])
 
2474
        state._validate()
 
2475
 
 
2476
        state._discard_merge_parents()
 
2477
        state._validate()
 
2478
        self.assertEqual(exp_dirblocks, state._dirblocks)