/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Andrew Bennetts
  • Date: 2011-04-08 03:31:54 UTC
  • mfrom: (5766 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5767.
  • Revision ID: andrew.bennetts@canonical.com-20110408033154-la08nghd4391sw5m
Merge latest lp:bzr, move our new release notes entries to the current release.

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
        }
 
1544
        tree.commit('commit 1a', rev_id='1a', **kwargs)
 
1545
        tree.commit('commit 2a', rev_id='2a', **kwargs)
 
1546
        tree.commit('commit 3a', rev_id='3a', **kwargs)
 
1547
        return tree
 
1548
 
 
1549
    def setup_ab_tree(self):
 
1550
        tree = self.setup_a_tree()
 
1551
        tree.set_last_revision('1a')
 
1552
        tree.branch.set_last_revision_info(1, '1a')
 
1553
        kwargs = {
 
1554
            'committer': 'Joe Foo <joe@foo.com>',
 
1555
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
 
1556
        }
 
1557
        tree.commit('commit 2b', rev_id='2b', **kwargs)
 
1558
        tree.commit('commit 3b', rev_id='3b', **kwargs)
 
1559
        return tree
 
1560
 
 
1561
    def test_one_revision(self):
 
1562
        tree = self.setup_ab_tree()
 
1563
        lf = LogCatcher()
 
1564
        rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1565
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
 
1566
                     end_revision=rev)
 
1567
        self.assertEqual(1, len(lf.revisions))
 
1568
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
 
1569
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
 
1570
 
 
1571
    def test_many_revisions(self):
 
1572
        tree = self.setup_ab_tree()
 
1573
        lf = LogCatcher()
 
1574
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1575
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1576
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
 
1577
                     end_revision=end_rev)
 
1578
        self.assertEqual(3, len(lf.revisions))
 
1579
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
 
1580
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
 
1581
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
 
1582
        self.assertEqual('2a', lf.revisions[1].rev.revision_id)
 
1583
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
 
1584
 
 
1585
    def test_long_format(self):
 
1586
        tree = self.setup_ab_tree()
 
1587
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1588
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1589
        self.assertFormatterResult("""\
 
1590
------------------------------------------------------------
 
1591
revision-id: 3a
 
1592
committer: Joe Foo <joe@foo.com>
 
1593
branch nick: tree
 
1594
timestamp: Tue 2005-11-22 11:00:00 +1100
 
1595
message:
 
1596
  commit 3a
 
1597
------------------------------------------------------------
 
1598
revision-id: 2a
 
1599
committer: Joe Foo <joe@foo.com>
 
1600
branch nick: tree
 
1601
timestamp: Tue 2005-11-22 11:00:00 +1100
 
1602
message:
 
1603
  commit 2a
 
1604
------------------------------------------------------------
 
1605
revno: 1
 
1606
committer: Joe Foo <joe@foo.com>
 
1607
branch nick: tree
 
1608
timestamp: Tue 2005-11-22 11:00:00 +1100
 
1609
message:
 
1610
  commit 1a
 
1611
""",
 
1612
            tree.branch, log.LongLogFormatter, show_log_kwargs={
 
1613
                'start_revision': start_rev, 'end_revision': end_rev
 
1614
            })
 
1615
 
 
1616
    def test_short_format(self):
 
1617
        tree = self.setup_ab_tree()
 
1618
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1619
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1620
        self.assertFormatterResult("""\
 
1621
      Joe Foo\t2005-11-22
 
1622
      revision-id:3a
 
1623
      commit 3a
 
1624
 
 
1625
      Joe Foo\t2005-11-22
 
1626
      revision-id:2a
 
1627
      commit 2a
 
1628
 
 
1629
    1 Joe Foo\t2005-11-22
 
1630
      commit 1a
 
1631
 
 
1632
""",
 
1633
            tree.branch, log.ShortLogFormatter, show_log_kwargs={
 
1634
                'start_revision': start_rev, 'end_revision': end_rev
 
1635
            })
 
1636
 
 
1637
    def test_line_format(self):
 
1638
        tree = self.setup_ab_tree()
 
1639
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
 
1640
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
 
1641
        self.assertFormatterResult("""\
 
1642
Joe Foo 2005-11-22 commit 3a
 
1643
Joe Foo 2005-11-22 commit 2a
 
1644
1: Joe Foo 2005-11-22 commit 1a
 
1645
""",
 
1646
            tree.branch, log.LineLogFormatter, show_log_kwargs={
 
1647
                'start_revision': start_rev, 'end_revision': end_rev
 
1648
            })
 
1649
 
1466
1650
 
1467
1651
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1468
1652
 
1543
1727
    def test_bugs_handler_present(self):
1544
1728
        self.properties_handler_registry.get('bugs_properties_handler')
1545
1729
 
 
1730
 
 
1731
class TestLogForAuthors(TestCaseForLogFormatter):
 
1732
 
 
1733
    def setUp(self):
 
1734
        TestCaseForLogFormatter.setUp(self)
 
1735
        self.wt = self.make_standard_commit('nicky',
 
1736
            authors=['John Doe <jdoe@example.com>',
 
1737
                     'Jane Rey <jrey@example.com>'])
 
1738
 
 
1739
    def assertFormatterResult(self, formatter, who, result):
 
1740
        formatter_kwargs = dict()
 
1741
        if who is not None:
 
1742
            author_list_handler = log.author_list_registry.get(who)
 
1743
            formatter_kwargs['author_list_handler'] = author_list_handler
 
1744
        TestCaseForLogFormatter.assertFormatterResult(self, result,
 
1745
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
 
1746
 
 
1747
    def test_line_default(self):
 
1748
        self.assertFormatterResult(log.LineLogFormatter, None, """\
 
1749
1: John Doe 2005-11-22 add a
 
1750
""")
 
1751
 
 
1752
    def test_line_committer(self):
 
1753
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
 
1754
1: Lorem Ipsum 2005-11-22 add a
 
1755
""")
 
1756
 
 
1757
    def test_line_first(self):
 
1758
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
 
1759
1: John Doe 2005-11-22 add a
 
1760
""")
 
1761
 
 
1762
    def test_line_all(self):
 
1763
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
 
1764
1: John Doe, Jane Rey 2005-11-22 add a
 
1765
""")
 
1766
 
 
1767
 
 
1768
    def test_short_default(self):
 
1769
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
 
1770
    1 John Doe\t2005-11-22
 
1771
      add a
 
1772
 
 
1773
""")
 
1774
 
 
1775
    def test_short_committer(self):
 
1776
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
 
1777
    1 Lorem Ipsum\t2005-11-22
 
1778
      add a
 
1779
 
 
1780
""")
 
1781
 
 
1782
    def test_short_first(self):
 
1783
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
 
1784
    1 John Doe\t2005-11-22
 
1785
      add a
 
1786
 
 
1787
""")
 
1788
 
 
1789
    def test_short_all(self):
 
1790
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
 
1791
    1 John Doe, Jane Rey\t2005-11-22
 
1792
      add a
 
1793
 
 
1794
""")
 
1795
 
 
1796
    def test_long_default(self):
 
1797
        self.assertFormatterResult(log.LongLogFormatter, None, """\
 
1798
------------------------------------------------------------
 
1799
revno: 1
 
1800
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1801
committer: Lorem Ipsum <test@example.com>
 
1802
branch nick: nicky
 
1803
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1804
message:
 
1805
  add a
 
1806
""")
 
1807
 
 
1808
    def test_long_committer(self):
 
1809
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
 
1810
------------------------------------------------------------
 
1811
revno: 1
 
1812
committer: Lorem Ipsum <test@example.com>
 
1813
branch nick: nicky
 
1814
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1815
message:
 
1816
  add a
 
1817
""")
 
1818
 
 
1819
    def test_long_first(self):
 
1820
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
 
1821
------------------------------------------------------------
 
1822
revno: 1
 
1823
author: John Doe <jdoe@example.com>
 
1824
committer: Lorem Ipsum <test@example.com>
 
1825
branch nick: nicky
 
1826
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1827
message:
 
1828
  add a
 
1829
""")
 
1830
 
 
1831
    def test_long_all(self):
 
1832
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
 
1833
------------------------------------------------------------
 
1834
revno: 1
 
1835
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
 
1836
committer: Lorem Ipsum <test@example.com>
 
1837
branch nick: nicky
 
1838
timestamp: Tue 2005-11-22 00:00:00 +0000
 
1839
message:
 
1840
  add a
 
1841
""")
 
1842
 
 
1843
    def test_gnu_changelog_default(self):
 
1844
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
 
1845
2005-11-22  John Doe  <jdoe@example.com>
 
1846
 
 
1847
\tadd a
 
1848
 
 
1849
""")
 
1850
 
 
1851
    def test_gnu_changelog_committer(self):
 
1852
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
 
1853
2005-11-22  Lorem Ipsum  <test@example.com>
 
1854
 
 
1855
\tadd a
 
1856
 
 
1857
""")
 
1858
 
 
1859
    def test_gnu_changelog_first(self):
 
1860
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
 
1861
2005-11-22  John Doe  <jdoe@example.com>
 
1862
 
 
1863
\tadd a
 
1864
 
 
1865
""")
 
1866
 
 
1867
    def test_gnu_changelog_all(self):
 
1868
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
 
1869
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
 
1870
 
 
1871
\tadd a
 
1872
 
 
1873
""")
 
1874
 
 
1875
 
1546
1876
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1547
1877
 
1548
1878
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1579
1909
        return br
1580
1910
 
1581
1911
    def assertLogRevnos(self, expected_revnos, b, start, end,
1582
 
                        exclude_common_ancestry):
 
1912
                        exclude_common_ancestry, generate_merge_revisions=True):
1583
1913
        # FIXME: the layering in log makes it hard to test intermediate levels,
1584
1914
        # I wish adding filters with their parameters were easier...
1585
1915
        # -- vila 20100413
1586
1916
        iter_revs = log._calc_view_revisions(
1587
1917
            b, start, end, direction='reverse',
1588
 
            generate_merge_revisions=True,
 
1918
            generate_merge_revisions=generate_merge_revisions,
1589
1919
            exclude_common_ancestry=exclude_common_ancestry)
1590
1920
        self.assertEqual(expected_revnos,
1591
1921
                         [revid for revid, revno, depth in iter_revs])
1593
1923
    def test_merge_sorted_exclude_ancestry(self):
1594
1924
        b = self.make_branch_with_alternate_ancestries()
1595
1925
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1596
 
                             b, '1', '3', False)
 
1926
                             b, '1', '3', exclude_common_ancestry=False)
1597
1927
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1598
1928
        # it should be mentioned even if merge_sort order will make it appear
1599
1929
        # after 1.1.1
1600
1930
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1601
 
                             b, '1.1.1', '3', True)
 
1931
                             b, '1.1.1', '3', exclude_common_ancestry=True)
1602
1932
 
 
1933
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
 
1934
        b = self.make_branch_with_alternate_ancestries()
 
1935
        self.assertLogRevnos(['3', '2'],
 
1936
                             b, '1', '3', exclude_common_ancestry=True,
 
1937
                             generate_merge_revisions=False)
 
1938
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
 
1939
                             b, '1', '3', exclude_common_ancestry=True,
 
1940
                             generate_merge_revisions=True)
1603
1941