~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-19 10:42:59 UTC
  • mto: This revision was merged to the branch mainline in revision 5806.
  • Revision ID: jelmer@samba.org-20110419104259-g9exlcp1f5jdu3ci
Move Inventory._get_mutable_inventory -> mutable_inventory_from_tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
            branch.tags.set_tag('v1.0', 'rev-3')
118
118
        return wt
119
119
 
 
120
 
120
121
class LogCatcher(log.LogFormatter):
121
122
    """Pull log messages into a list rather than displaying them.
122
123
 
371
372
            wt.branch, log.ShortLogFormatter,
372
373
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
373
374
 
 
375
    def test_show_ids(self):
 
376
        wt = self.make_branch_and_tree('parent')
 
377
        self.build_tree(['parent/f1', 'parent/f2'])
 
378
        wt.add(['f1','f2'])
 
379
        self.wt_commit(wt, 'first post', rev_id='a')
 
380
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
381
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
 
382
        wt.merge_from_branch(child_wt.branch)
 
383
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
 
384
        self.assertFormatterResult("""\
 
385
    2 Joe Foo\t2005-11-22 [merge]
 
386
      revision-id:c
 
387
      merge branch 1
 
388
 
 
389
          1.1.1 Joe Foo\t2005-11-22
 
390
                revision-id:b
 
391
                branch 1 changes
 
392
 
 
393
    1 Joe Foo\t2005-11-22
 
394
      revision-id:a
 
395
      first post
 
396
 
 
397
""",
 
398
            wt.branch, log.ShortLogFormatter,
 
399
            formatter_kwargs=dict(levels=0,show_ids=True))
 
400
 
374
401
 
375
402
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
376
403
 
659
686
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
660
687
                             sio.getvalue())
661
688
 
 
689
    def test_show_ids(self):
 
690
        wt = self.make_branch_and_tree('parent')
 
691
        self.build_tree(['parent/f1', 'parent/f2'])
 
692
        wt.add(['f1','f2'])
 
693
        self.wt_commit(wt, 'first post', rev_id='a')
 
694
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
 
695
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
 
696
        wt.merge_from_branch(child_wt.branch)
 
697
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
 
698
        self.assertFormatterResult("""\
 
699
------------------------------------------------------------
 
700
revno: 2 [merge]
 
701
revision-id: c
 
702
parent: a
 
703
parent: b
 
704
committer: Joe Foo <joe@foo.com>
 
705
branch nick: parent
 
706
timestamp: Tue 2005-11-22 00:00:02 +0000
 
707
message:
 
708
  merge branch 1
 
709
    ------------------------------------------------------------
 
710
    revno: 1.1.1
 
711
    revision-id: b
 
712
    parent: a
 
713
    committer: Joe Foo <joe@foo.com>
 
714
    branch nick: child
 
715
    timestamp: Tue 2005-11-22 00:00:01 +0000
 
716
    message:
 
717
      branch 1 changes
 
718
------------------------------------------------------------
 
719
revno: 1
 
720
revision-id: a
 
721
committer: Joe Foo <joe@foo.com>
 
722
branch nick: parent
 
723
timestamp: Tue 2005-11-22 00:00:00 +0000
 
724
message:
 
725
  first post
 
726
""",
 
727
            wt.branch, log.LongLogFormatter,
 
728
            formatter_kwargs=dict(levels=0,show_ids=True))
 
729
 
662
730
 
663
731
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
664
732
 
1463
1531
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1464
1532
 
1465
1533
 
 
1534
class TestRevisionNotInBranch(TestCaseForLogFormatter):
 
1535
 
 
1536
    def setup_a_tree(self):
 
1537
        tree = self.make_branch_and_tree('tree')
 
1538
        tree.lock_write()
 
1539
        self.addCleanup(tree.unlock)
 
1540
        kwargs = {
 
1541
            'committer': 'Joe Foo <joe@foo.com>',
 
1542
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
 
1543
            'timezone': 0, # UTC
 
1544
        }
 
1545
        tree.commit('commit 1a', rev_id='1a', **kwargs)
 
1546
        tree.commit('commit 2a', rev_id='2a', **kwargs)
 
1547
        tree.commit('commit 3a', rev_id='3a', **kwargs)
 
1548
        return tree
 
1549
 
 
1550
    def setup_ab_tree(self):
 
1551
        tree = self.setup_a_tree()
 
1552
        tree.set_last_revision('1a')
 
1553
        tree.branch.set_last_revision_info(1, '1a')
 
1554
        kwargs = {
 
1555
            'committer': 'Joe Foo <joe@foo.com>',
 
1556
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
 
1557
            'timezone': 0, # UTC
 
1558
        }
 
1559
        tree.commit('commit 2b', rev_id='2b', **kwargs)
 
1560
        tree.commit('commit 3b', rev_id='3b', **kwargs)
 
1561
        return tree
 
1562
 
 
1563
    def test_one_revision(self):
 
1564
        tree = self.setup_ab_tree()
 
1565
        lf = LogCatcher()
 
1566
        rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1567
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
 
1568
                     end_revision=rev)
 
1569
        self.assertEqual(1, len(lf.revisions))
 
1570
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
 
1571
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
 
1572
 
 
1573
    def test_many_revisions(self):
 
1574
        tree = self.setup_ab_tree()
 
1575
        lf = LogCatcher()
 
1576
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1577
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1578
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
 
1579
                     end_revision=end_rev)
 
1580
        self.assertEqual(3, len(lf.revisions))
 
1581
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
 
1582
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
 
1583
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
 
1584
        self.assertEqual('2a', lf.revisions[1].rev.revision_id)
 
1585
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
 
1586
 
 
1587
    def test_long_format(self):
 
1588
        tree = self.setup_ab_tree()
 
1589
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1590
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1591
        self.assertFormatterResult("""\
 
1592
------------------------------------------------------------
 
1593
revision-id: 3a
 
1594
committer: Joe Foo <joe@foo.com>
 
1595
branch nick: tree
 
1596
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1597
message:
 
1598
  commit 3a
 
1599
------------------------------------------------------------
 
1600
revision-id: 2a
 
1601
committer: Joe Foo <joe@foo.com>
 
1602
branch nick: tree
 
1603
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1604
message:
 
1605
  commit 2a
 
1606
------------------------------------------------------------
 
1607
revno: 1
 
1608
committer: Joe Foo <joe@foo.com>
 
1609
branch nick: tree
 
1610
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1611
message:
 
1612
  commit 1a
 
1613
""",
 
1614
            tree.branch, log.LongLogFormatter, show_log_kwargs={
 
1615
                'start_revision': start_rev, 'end_revision': end_rev
 
1616
            })
 
1617
 
 
1618
    def test_short_format(self):
 
1619
        tree = self.setup_ab_tree()
 
1620
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1621
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1622
        self.assertFormatterResult("""\
 
1623
      Joe Foo\t2005-11-22
 
1624
      revision-id:3a
 
1625
      commit 3a
 
1626
 
 
1627
      Joe Foo\t2005-11-22
 
1628
      revision-id:2a
 
1629
      commit 2a
 
1630
 
 
1631
    1 Joe Foo\t2005-11-22
 
1632
      commit 1a
 
1633
 
 
1634
""",
 
1635
            tree.branch, log.ShortLogFormatter, show_log_kwargs={
 
1636
                'start_revision': start_rev, 'end_revision': end_rev
 
1637
            })
 
1638
 
 
1639
    def test_line_format(self):
 
1640
        tree = self.setup_ab_tree()
 
1641
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1642
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1643
        self.assertFormatterResult("""\
 
1644
Joe Foo 2005-11-22 commit 3a
 
1645
Joe Foo 2005-11-22 commit 2a
 
1646
1: Joe Foo 2005-11-22 commit 1a
 
1647
""",
 
1648
            tree.branch, log.LineLogFormatter, show_log_kwargs={
 
1649
                'start_revision': start_rev, 'end_revision': end_rev
 
1650
            })
 
1651
 
1466
1652
 
1467
1653
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1468
1654
 
1543
1729
    def test_bugs_handler_present(self):
1544
1730
        self.properties_handler_registry.get('bugs_properties_handler')
1545
1731
 
 
1732
 
 
1733
class TestLogForAuthors(TestCaseForLogFormatter):
 
1734
 
 
1735
    def setUp(self):
 
1736
        TestCaseForLogFormatter.setUp(self)
 
1737
        self.wt = self.make_standard_commit('nicky',
 
1738
            authors=['John Doe <jdoe@example.com>',
 
1739
                     'Jane Rey <jrey@example.com>'])
 
1740
 
 
1741
    def assertFormatterResult(self, formatter, who, result):
 
1742
        formatter_kwargs = dict()
 
1743
        if who is not None:
 
1744
            author_list_handler = log.author_list_registry.get(who)
 
1745
            formatter_kwargs['author_list_handler'] = author_list_handler
 
1746
        TestCaseForLogFormatter.assertFormatterResult(self, result,
 
1747
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
 
1748
 
 
1749
    def test_line_default(self):
 
1750
        self.assertFormatterResult(log.LineLogFormatter, None, """\
 
1751
1: John Doe 2005-11-22 add a
 
1752
""")
 
1753
 
 
1754
    def test_line_committer(self):
 
1755
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
 
1756
1: Lorem Ipsum 2005-11-22 add a
 
1757
""")
 
1758
 
 
1759
    def test_line_first(self):
 
1760
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
 
1761
1: John Doe 2005-11-22 add a
 
1762
""")
 
1763
 
 
1764
    def test_line_all(self):
 
1765
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
 
1766
1: John Doe, Jane Rey 2005-11-22 add a
 
1767
""")
 
1768
 
 
1769
 
 
1770
    def test_short_default(self):
 
1771
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
 
1772
    1 John Doe\t2005-11-22
 
1773
      add a
 
1774
 
 
1775
""")
 
1776
 
 
1777
    def test_short_committer(self):
 
1778
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
 
1779
    1 Lorem Ipsum\t2005-11-22
 
1780
      add a
 
1781
 
 
1782
""")
 
1783
 
 
1784
    def test_short_first(self):
 
1785
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
 
1786
    1 John Doe\t2005-11-22
 
1787
      add a
 
1788
 
 
1789
""")
 
1790
 
 
1791
    def test_short_all(self):
 
1792
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
 
1793
    1 John Doe, Jane Rey\t2005-11-22
 
1794
      add a
 
1795
 
 
1796
""")
 
1797
 
 
1798
    def test_long_default(self):
 
1799
        self.assertFormatterResult(log.LongLogFormatter, None, """\
 
1800
------------------------------------------------------------
 
1801
revno: 1
 
1802
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1803
committer: Lorem Ipsum <test@example.com>
 
1804
branch nick: nicky
 
1805
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1806
message:
 
1807
  add a
 
1808
""")
 
1809
 
 
1810
    def test_long_committer(self):
 
1811
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
 
1812
------------------------------------------------------------
 
1813
revno: 1
 
1814
committer: Lorem Ipsum <test@example.com>
 
1815
branch nick: nicky
 
1816
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1817
message:
 
1818
  add a
 
1819
""")
 
1820
 
 
1821
    def test_long_first(self):
 
1822
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
 
1823
------------------------------------------------------------
 
1824
revno: 1
 
1825
author: John Doe <jdoe@example.com>
 
1826
committer: Lorem Ipsum <test@example.com>
 
1827
branch nick: nicky
 
1828
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1829
message:
 
1830
  add a
 
1831
""")
 
1832
 
 
1833
    def test_long_all(self):
 
1834
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
 
1835
------------------------------------------------------------
 
1836
revno: 1
 
1837
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1838
committer: Lorem Ipsum <test@example.com>
 
1839
branch nick: nicky
 
1840
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1841
message:
 
1842
  add a
 
1843
""")
 
1844
 
 
1845
    def test_gnu_changelog_default(self):
 
1846
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
 
1847
2005-11-22  John Doe  <jdoe@example.com>
 
1848
 
 
1849
\tadd a
 
1850
 
 
1851
""")
 
1852
 
 
1853
    def test_gnu_changelog_committer(self):
 
1854
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
 
1855
2005-11-22  Lorem Ipsum  <test@example.com>
 
1856
 
 
1857
\tadd a
 
1858
 
 
1859
""")
 
1860
 
 
1861
    def test_gnu_changelog_first(self):
 
1862
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
 
1863
2005-11-22  John Doe  <jdoe@example.com>
 
1864
 
 
1865
\tadd a
 
1866
 
 
1867
""")
 
1868
 
 
1869
    def test_gnu_changelog_all(self):
 
1870
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
 
1871
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
 
1872
 
 
1873
\tadd a
 
1874
 
 
1875
""")
 
1876
 
 
1877
 
1546
1878
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1547
1879
 
1548
1880
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1579
1911
        return br
1580
1912
 
1581
1913
    def assertLogRevnos(self, expected_revnos, b, start, end,
1582
 
                        exclude_common_ancestry):
 
1914
                        exclude_common_ancestry, generate_merge_revisions=True):
1583
1915
        # FIXME: the layering in log makes it hard to test intermediate levels,
1584
1916
        # I wish adding filters with their parameters were easier...
1585
1917
        # -- vila 20100413
1586
1918
        iter_revs = log._calc_view_revisions(
1587
1919
            b, start, end, direction='reverse',
1588
 
            generate_merge_revisions=True,
 
1920
            generate_merge_revisions=generate_merge_revisions,
1589
1921
            exclude_common_ancestry=exclude_common_ancestry)
1590
1922
        self.assertEqual(expected_revnos,
1591
1923
                         [revid for revid, revno, depth in iter_revs])
1593
1925
    def test_merge_sorted_exclude_ancestry(self):
1594
1926
        b = self.make_branch_with_alternate_ancestries()
1595
1927
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1596
 
                             b, '1', '3', False)
 
1928
                             b, '1', '3', exclude_common_ancestry=False)
1597
1929
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1598
1930
        # it should be mentioned even if merge_sort order will make it appear
1599
1931
        # after 1.1.1
1600
1932
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1601
 
                             b, '1.1.1', '3', True)
 
1933
                             b, '1.1.1', '3', exclude_common_ancestry=True)
1602
1934
 
 
1935
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
 
1936
        b = self.make_branch_with_alternate_ancestries()
 
1937
        self.assertLogRevnos(['3', '2'],
 
1938
                             b, '1', '3', exclude_common_ancestry=True,
 
1939
                             generate_merge_revisions=False)
 
1940
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
 
1941
                             b, '1', '3', exclude_common_ancestry=True,
 
1942
                             generate_merge_revisions=True)
1603
1943