[PATCH stable] revsets: add branchpoint() function

Patrick Mézard patrick at mezard.eu
Sun Aug 12 12:12:55 CDT 2012


Le 09/08/12 16:54, Ivan Andrus a écrit :
> # HG changeset patch
> # User Ivan Andrus <darthandrus at gmail.com>
> # Date 1344524011 -7200
> # Branch stable
> # Node ID c56d6699b2fead4fd9b294216baa89112ce65c91
> # Parent  96189d60d810317ef8f707ec3ab123a9beb288cd
> revsets: add branchpoint() function
> 
> The branchpoint() function returns changesets with more than one child.
> Eventually I would like to be able to see only branch points and merge
> points in a graphical log to see the topology of the repository.
> 
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -909,6 +909,15 @@
>      cl = repo.changelog
>      return [r for r in subset if cl.parentrevs(r)[1] != -1]
>  
> +def branchpoint(repo, subset, x):
> +    """``branchpoint()``
> +    Changesets with more than one child.
> +    """
> +    # i18n: "branchpoint" is a keyword
> +    getargs(x, 0, 0, _("branchpoint takes no arguments"))
> +    cl = repo.changelog
> +    return [r for r in subset if cl.children(repo[r].node())[1:]]

This is more or less in O((len(repo) - min(subset))^2)

  $ hg log -G -r 'branchpoint() or merge()' --hidden

runs in 2m46s here on mercurial repository. Please give a look at the implementation of revlog.children(). The following runs in 3s:


def branchpoint(repo, subset, x):
    """``branchpoint()``
    Changesets with more than one child.
    """
    # i18n: "branchpoint" is a keyword
    getargs(x, 0, 0, _("branchpoint takes no arguments"))
    cl = repo.changelog
    if not subset:
        return []
    baserev = min(subset)
    parentscount = [0]*(len(repo) - baserev)
    for r in xrange(baserev + 1, len(repo)):
        for p in cl.parentrevs(r):
            if p >= baserev:
                parentscount[p - baserev] += 1
    branchpoints = set((baserev + i) for i in xrange(len(parentscount))
                       if parentscount[i] > 1)
    return [r for r in subset if r in branchpoints]


I am +0 on the feature, running the previous command on mercurial repository does not seem very useful and I do not have a branchy repository where I would know the code base enough to make sense of this.

> +
>  def minrev(repo, subset, x):
>      """``min(set)``
>      Changeset with lowest revision number in set.



More information about the Mercurial-devel mailing list