~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Jelmer Vernooij
  • Date: 2010-04-30 11:03:59 UTC
  • mto: This revision was merged to the branch mainline in revision 5197.
  • Revision ID: jelmer@samba.org-20100430110359-ow3e3grh7sxy93pa
Remove more unused imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    errors,
23
22
    log,
24
23
    registry,
117
116
            branch.tags.set_tag('v1.0', 'rev-3')
118
117
        return wt
119
118
 
120
 
 
121
119
class LogCatcher(log.LogFormatter):
122
120
    """Pull log messages into a list rather than displaying them.
123
121
 
372
370
            wt.branch, log.ShortLogFormatter,
373
371
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
374
372
 
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
 
 
401
373
 
402
374
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
403
375
 
686
658
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
687
659
                             sio.getvalue())
688
660
 
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
 
 
730
661
 
731
662
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
732
663
 
946
877
            formatter_kwargs=dict(levels=0))
947
878
 
948
879
 
949
 
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
950
 
 
951
 
    def test_gnu_changelog(self):
952
 
        wt = self.make_standard_commit('nicky', authors=[])
953
 
        self.assertFormatterResult('''\
954
 
2005-11-22  Lorem Ipsum  <test@example.com>
955
 
 
956
 
\tadd a
957
 
 
958
 
''',
959
 
            wt.branch, log.GnuChangelogLogFormatter)
960
 
 
961
 
    def test_with_authors(self):
962
 
        wt = self.make_standard_commit('nicky',
963
 
            authors=['Fooa Fooz <foo@example.com>',
964
 
                     'Bari Baro <bar@example.com>'])
965
 
        self.assertFormatterResult('''\
966
 
2005-11-22  Fooa Fooz  <foo@example.com>
967
 
 
968
 
\tadd a
969
 
 
970
 
''',
971
 
            wt.branch, log.GnuChangelogLogFormatter)
972
 
 
973
 
    def test_verbose(self):
974
 
        wt = self.make_standard_commit('nicky')
975
 
        self.assertFormatterResult('''\
976
 
2005-11-22  John Doe  <jdoe@example.com>
977
 
 
978
 
\t* a:
979
 
 
980
 
\tadd a
981
 
 
982
 
''',
983
 
            wt.branch, log.GnuChangelogLogFormatter,
984
 
            show_log_kwargs=dict(verbose=True))
985
 
 
986
880
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
987
881
 
988
882
    def _get_view_revisions(self, *args, **kwargs):
1531
1425
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1532
1426
 
1533
1427
 
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
 
 
1652
1428
 
1653
1429
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1654
1430
 
1728
1504
 
1729
1505
    def test_bugs_handler_present(self):
1730
1506
        self.properties_handler_registry.get('bugs_properties_handler')
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
 
 
1878
 
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1879
 
 
1880
 
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1881
 
        # See test_merge_sorted_exclude_ancestry below for the difference with
1882
 
        # bt.per_branch.test_iter_merge_sorted_revision.
1883
 
        # TestIterMergeSortedRevisionsBushyGraph. 
1884
 
        # make_branch_with_alternate_ancestries
1885
 
        # and test_merge_sorted_exclude_ancestry
1886
 
        # See the FIXME in assertLogRevnos too.
1887
 
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1888
 
        # 1
1889
 
        # |\
1890
 
        # 2 \
1891
 
        # |  |
1892
 
        # |  1.1.1
1893
 
        # |  | \
1894
 
        # |  |  1.2.1
1895
 
        # |  | /
1896
 
        # |  1.1.2
1897
 
        # | /
1898
 
        # 3
1899
 
        builder.start_series()
1900
 
        builder.build_snapshot('1', None, [
1901
 
            ('add', ('', 'TREE_ROOT', 'directory', '')),])
1902
 
        builder.build_snapshot('1.1.1', ['1'], [])
1903
 
        builder.build_snapshot('2', ['1'], [])
1904
 
        builder.build_snapshot('1.2.1', ['1.1.1'], [])
1905
 
        builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
1906
 
        builder.build_snapshot('3', ['2', '1.1.2'], [])
1907
 
        builder.finish_series()
1908
 
        br = builder.get_branch()
1909
 
        br.lock_read()
1910
 
        self.addCleanup(br.unlock)
1911
 
        return br
1912
 
 
1913
 
    def assertLogRevnos(self, expected_revnos, b, start, end,
1914
 
                        exclude_common_ancestry, generate_merge_revisions=True):
1915
 
        # FIXME: the layering in log makes it hard to test intermediate levels,
1916
 
        # I wish adding filters with their parameters were easier...
1917
 
        # -- vila 20100413
1918
 
        iter_revs = log._calc_view_revisions(
1919
 
            b, start, end, direction='reverse',
1920
 
            generate_merge_revisions=generate_merge_revisions,
1921
 
            exclude_common_ancestry=exclude_common_ancestry)
1922
 
        self.assertEqual(expected_revnos,
1923
 
                         [revid for revid, revno, depth in iter_revs])
1924
 
 
1925
 
    def test_merge_sorted_exclude_ancestry(self):
1926
 
        b = self.make_branch_with_alternate_ancestries()
1927
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1928
 
                             b, '1', '3', exclude_common_ancestry=False)
1929
 
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1930
 
        # it should be mentioned even if merge_sort order will make it appear
1931
 
        # after 1.1.1
1932
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1933
 
                             b, '1.1.1', '3', exclude_common_ancestry=True)
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)
1943