~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-15 14:47:59 UTC
  • mfrom: (2984.1.1 update_basis_161131)
  • Revision ID: pqm@pqm.ubuntu.com-20071115144759-zx0nd44rgp38riwr
(John Arbash Meinel) Fix bug #161131: when exactly 2 items were
        deleted, it would remove all items in a directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)