Mercurial > public > mercurial-scm > hg-stable
diff mercurial/obsutil.py @ 32897:1858fc2327ef
template: add predecessors template
Add a 'predecessors' template that returns the list of all closest known
predecessors for a changectx. The elements of the list are row changectx node id
formatted by default as short nodes.
The "closest predecessors" are the first locally known revisions encountered
while, walking predecessors markers. For example:
1) If a (A, (B)) markers exists and both A and B are locally known A is a
closest predecessors of B.
2) If a (A, (B)) and (B, (C)) markers exists and only A and C are known
locally, A will be the closest precursors of C.
This logic respect repository filtering. So hidden revision will be skipped by
this logic unless --hidden is specified. Since we only display the visible
predecessors, this template will not display anything in most case. It makes a
good candidate for inclusion in the default log output.
I added a new test-file for testing the precursors in various scenarios. This
test file will also be used for the successors template.
A new "obsutil" module has been added to start gathering utility function
outside of the large obsolete.py module.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 15 Jun 2017 13:02:58 +0200 |
parents | |
children | 4f49810a1011 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/obsutil.py Thu Jun 15 13:02:58 2017 +0200 @@ -0,0 +1,36 @@ +# obsutil.py - utility functions for obsolescence +# +# Copyright 2017 Boris Feld <boris.feld@octobus.net> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +def closestpredecessors(repo, nodeid): + """yield the list of next predecessors pointing on visible changectx nodes + + This function respect the repoview filtering, filtered revision will be + considered missing. + """ + + precursors = repo.obsstore.precursors + stack = [nodeid] + seen = set(stack) + + while stack: + current = stack.pop() + currentpreccs = precursors.get(current, ()) + + for prec in currentpreccs: + precnodeid = prec[0] + + # Basic cycle protection + if precnodeid in seen: + continue + seen.add(precnodeid) + + if precnodeid in repo: + yield precnodeid + else: + stack.append(precnodeid)