author Dirkjan Ochtman <>
Fri, 06 Feb 2009 16:57:23 +0100
changeset 56 cd5ef08c3002c4f71f3ae6da79813fd80d2f4c7f
parent 2 da886424da04ed29ca4d86c960da1a28da462ea4
permissions -rw-r--r--
Refactor pushlogFeed() so that it's a normal webcommand. Makes compatibility easier and makes sure various values are available that are no longer available to protocol commands in newer hg.

from mercurial import hg, cmdutil, util
from mercurial.node import hex, bin, nullid

def newchanges(ui, repo, oldrev, newrev='tip'):
    def isancestor(node, child):
        """Is the given node an ancestor of the child? returns True or False"""
        return repo.changelog.ancestor(child, node) == node

    oldrev = repo.lookup(oldrev)
    newrev = repo.lookup(newrev)

    displayer = cmdutil.show_changeset(ui, repo, {})

    reachable = {}

    def between(top, bottom):
        """repo.between doesn't seem to actually return *all* the changesets,
        just some of them. This returns all of them, dammit, including the
        top, but not the bottom."""
        while top != bottom:
            yield top;

            (p1, p2) = repo.changelog.parents(top)
            if p2 != nullid:
                raise hg.RepoError("between called on merge revision %s. p2: %s" % (hex(top), hex(p2)))

            top = p1

    def processtip(tip):
        (base, p1, p2) = repo.branches([tip])[0][1:]

        ancestor = repo.changelog.ancestor(base, oldrev)

        # Now compute a map of nodes that are ancestors of the oldrev, stopping
        # when we get back to the branch base

        reachable[ancestor] = 1
        reachable.update(repo.changelog.reachable(oldrev, ancestor))

        bt = between(tip, base)
        for c in bt:
            if c in reachable:

  , c)

        if not isancestor(base, oldrev):
  , base)

        for c in (p1, p2):
            if not isancestor(c, oldrev):


cmdtable = {
    'newchanges': (newchanges, [], "hg newchanges oldrev [newrev]"),