~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-18 22:14:54 UTC
  • mto: This revision was merged to the branch mainline in revision 2456.
  • Revision ID: john@arbash-meinel.com-20070418221454-zkozu1yyny4zx3rv
Create a helper tree which has a semi-interesting history.
This allows us to test which files are actually modified.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
# vim: encoding=utf-8
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
400
398
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
401
399
            ('4b', '4', 0)],
402
400
            revisions)
 
401
 
 
402
 
 
403
class TestGetRevisionsTouchingFileID(TestCaseWithTransport):
 
404
 
 
405
    def create_tree_with_single_merge(self):
 
406
        """Create a branch with a moderate layout.
 
407
 
 
408
        The revision graph looks like:
 
409
 
 
410
           A
 
411
           |\
 
412
           B C
 
413
           |/
 
414
           D
 
415
 
 
416
        In this graph, A introduced files f1 and f2 and f3.
 
417
        B modifies f1 and f3, and C modifies f2 and f3.
 
418
        D merges the changes from B and C and resolves the conflict for f3.
 
419
        """
 
420
        # TODO: jam 20070218 This seems like it could really be done
 
421
        #       with make_branch_and_memory_tree() if we could just
 
422
        #       create the content of those files.
 
423
        # TODO: jam 20070218 Another alternative is that we would really
 
424
        #       like to only create this tree 1 time for all tests that
 
425
        #       use it. Since 'log' only uses the tree in a readonly
 
426
        #       fashion, it seems a shame to regenerate an identical
 
427
        #       tree for each test.
 
428
        tree = self.make_branch_and_tree('tree')
 
429
        tree.lock_write()
 
430
        self.addCleanup(tree.unlock)
 
431
 
 
432
        self.build_tree_contents([('tree/f1', 'A\n'),
 
433
                                  ('tree/f2', 'A\n'),
 
434
                                  ('tree/f3', 'A\n'),
 
435
                                 ])
 
436
        tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
 
437
        tree.commit('A', rev_id='A')
 
438
 
 
439
        self.build_tree_contents([('tree/f2', 'A\nC\n'),
 
440
                                  ('tree/f3', 'A\nC\n'),
 
441
                                 ])
 
442
        tree.commit('C', rev_id='C')
 
443
        # Revert back to A to build the other history.
 
444
        tree.set_last_revision('A')
 
445
        tree.branch.set_last_revision_info(1, 'A')
 
446
        self.build_tree_contents([('tree/f1', 'A\nB\n'),
 
447
                                  ('tree/f2', 'A\n'),
 
448
                                  ('tree/f3', 'A\nB\n'),
 
449
                                 ])
 
450
        tree.commit('B', rev_id='B')
 
451
        tree.set_parent_ids(['B', 'C'])
 
452
        self.build_tree_contents([('tree/f1', 'A\nB\n'),
 
453
                                  ('tree/f2', 'A\nC\n'),
 
454
                                  ('tree/f3', 'A\nB\nC\n'),
 
455
                                 ])
 
456
        tree.commit('D', rev_id='D')
 
457
 
 
458
        # Switch to a read lock for this tree.
 
459
        # We still have addCleanup(unlock)
 
460
        tree.unlock()
 
461
        tree.lock_read()
 
462
        return tree
 
463
 
 
464
    def test_tree_with_single_merge(self):
 
465
        """Make sure the tree layout is correct."""
 
466
        tree = self.create_tree_with_single_merge()
 
467
        rev_A_tree = tree.branch.repository.revision_tree('A')
 
468
        rev_B_tree = tree.branch.repository.revision_tree('B')
 
469
 
 
470
        f1_changed = (u'f1', 'f1-id', 'file', True, False)
 
471
        f2_changed = (u'f2', 'f2-id', 'file', True, False)
 
472
        f3_changed = (u'f3', 'f3-id', 'file', True, False)
 
473
 
 
474
        delta = rev_B_tree.changes_from(rev_A_tree)
 
475
        self.assertEqual([f1_changed, f3_changed], delta.modified)
 
476
        self.assertEqual([], delta.renamed)
 
477
        self.assertEqual([], delta.added)
 
478
        self.assertEqual([], delta.removed)
 
479
 
 
480
        rev_C_tree = tree.branch.repository.revision_tree('C')
 
481
        delta = rev_C_tree.changes_from(rev_A_tree)
 
482
        self.assertEqual([f2_changed, f3_changed], delta.modified)
 
483
        self.assertEqual([], delta.renamed)
 
484
        self.assertEqual([], delta.added)
 
485
        self.assertEqual([], delta.removed)
 
486
 
 
487
        rev_D_tree = tree.branch.repository.revision_tree('D')
 
488
        delta = rev_D_tree.changes_from(rev_B_tree)
 
489
        self.assertEqual([f2_changed, f3_changed], delta.modified)
 
490
        self.assertEqual([], delta.renamed)
 
491
        self.assertEqual([], delta.added)
 
492
        self.assertEqual([], delta.removed)
 
493
 
 
494
        delta = rev_D_tree.changes_from(rev_C_tree)
 
495
        self.assertEqual([f1_changed, f3_changed], delta.modified)
 
496
        self.assertEqual([], delta.renamed)
 
497
        self.assertEqual([], delta.added)
 
498
        self.assertEqual([], delta.removed)
 
499