tests/test-annotate.py
author Boris Feld <boris.feld@octobus.net>
Thu, 05 Oct 2017 15:25:18 +0200
changeset 34852 d45236f3d38e
parent 34433 2f5a135b2b04
child 35946 cf887d601014
permissions -rw-r--r--
log: add obsfate by default in changeset printer Having an obsfate by default in log will be useful for users to understand why they have obsolete and unstable changesets. Obsfate will only be shown for obsolete changesets, which only happens if people opt-in to experimental feature. But when obsolete changeset are visible, it is very useful to understand where they are. Having it in log could be sufficient for most people, so they don't have to learn a new command (like obslog which is itself useful in case of divergences). For example, when pulling and working directory parent become obsolete: $ hg pull ... working directory parent is obsolete! (f936c1697205) This message comes from the Evolve extension. Obsfate would comes handy: $ hg log -G o changeset: 2:6f91013c5136 | tag: tip | parent: 0:4ef7b558f3ec | user: Boris Feld <boris.feld@octobus.net> | date: Mon Oct 09 16:00:27 2017 +0200 | summary: A | | @ changeset: 1:f936c1697205 |/ user: Boris Feld <boris.feld@octobus.net> | date: Mon Oct 09 16:00:27 2017 +0200 | obsfate: rewritten using amend as 2:6f91013c5136 | summary: -A | o changeset: 0:feb4dd822b8c user: Boris Feld <boris.feld@octobus.net> date: Tue Oct 09 16:00:00 2017 +0200 summary: ROOT And once we update, we don't have an obsolete changeset in the log anymore so we don't show obsfate anymore, most users won't see obsfate often if they don't have obsolete changeset often: @ changeset: 2:6f91013c5136 | tag: tip | parent: 0:4ef7b558f3ec | user: Boris Feld <boris.feld@octobus.net> | date: Mon Oct 09 16:00:27 2017 +0200 | summary: A | o changeset: 0:feb4dd822b8c user: Boris Feld <boris.feld@octobus.net> date: Tue Oct 09 16:00:00 2017 +0200 summary: ROOT

from __future__ import absolute_import
from __future__ import print_function

import unittest

from mercurial import (
    mdiff,
)
from mercurial.context import (
    annotateline,
    _annotatepair,
)

class AnnotateTests(unittest.TestCase):
    """Unit tests for annotate code."""

    def testannotatepair(self):
        self.maxDiff = None # camelcase-required

        oldfctx = b'old'
        p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
        olddata = b'a\nb\n'
        p1data = b'a\nb\nc\n'
        p2data = b'a\nc\nd\n'
        childdata = b'a\nb2\nc\nc2\nd\n'
        diffopts = mdiff.diffopts()

        def decorate(text, rev):
            return ([annotateline(fctx=rev, lineno=i)
                     for i in xrange(1, text.count(b'\n') + 1)],
                    text)

        # Basic usage

        oldann = decorate(olddata, oldfctx)
        p1ann = decorate(p1data, p1fctx)
        p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
        self.assertEqual(p1ann[0], [
            annotateline('old', 1),
            annotateline('old', 2),
            annotateline('p1', 3),
        ])

        p2ann = decorate(p2data, p2fctx)
        p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
        self.assertEqual(p2ann[0], [
            annotateline('old', 1),
            annotateline('p2', 2),
            annotateline('p2', 3),
        ])

        # Test with multiple parents (note the difference caused by ordering)

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p1ann, p2ann], childfctx, childann, False,
                                 diffopts)
        self.assertEqual(childann[0], [
            annotateline('old', 1),
            annotateline('c', 2),
            annotateline('p2', 2),
            annotateline('c', 4),
            annotateline('p2', 3),
        ])

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p2ann, p1ann], childfctx, childann, False,
                                 diffopts)
        self.assertEqual(childann[0], [
            annotateline('old', 1),
            annotateline('c', 2),
            annotateline('p1', 3),
            annotateline('c', 4),
            annotateline('p2', 3),
        ])

        # Test with skipchild (note the difference caused by ordering)

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p1ann, p2ann], childfctx, childann, True,
                                 diffopts)
        self.assertEqual(childann[0], [
            annotateline('old', 1),
            annotateline('old', 2, True),
            # note that this line was carried over from earlier so it is *not*
            # marked skipped
            annotateline('p2', 2),
            annotateline('p2', 2, True),
            annotateline('p2', 3),
        ])

        childann = decorate(childdata, childfctx)
        childann = _annotatepair([p2ann, p1ann], childfctx, childann, True,
                                 diffopts)
        self.assertEqual(childann[0], [
            annotateline('old', 1),
            annotateline('old', 2, True),
            annotateline('p1', 3),
            annotateline('p1', 3, True),
            annotateline('p2', 3),
        ])

if __name__ == '__main__':
    import silenttestrunner
    silenttestrunner.main(__name__)