Mercurial > hg
changeset 18984:efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
This foreground logic will be reused by update logic.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Tue, 16 Apr 2013 15:16:33 +0200 |
parents | 31bcc5112191 |
children | a59e575c6ff8 |
files | mercurial/bookmarks.py mercurial/obsolete.py |
diffstat | 2 files changed, 29 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/bookmarks.py Mon Apr 15 17:10:58 2013 +0200 +++ b/mercurial/bookmarks.py Tue Apr 16 15:16:33 2013 +0200 @@ -292,19 +292,7 @@ # (new != nullrev has been excluded by the previous check) return True elif repo.obsstore: - # We only need this complicated logic if there is obsolescence - # XXX will probably deserve an optimised revset. - nm = repo.changelog.nodemap - validdests = set([old]) - plen = -1 - # compute the whole set of successors or descendants - while len(validdests) != plen: - plen = len(validdests) - succs = set(c.node() for c in validdests) - mutable = [c.node() for c in validdests if c.mutable()] - succs.update(obsolete.allsuccessors(repo.obsstore, mutable)) - known = (n for n in succs if n in nm) - validdests = set(repo.set('%ln::', known)) - return new in validdests + return new.node() in obsolete.foreground(repo, [old.node()]) else: + # still an independant clause as it is lazyer (and therefore faster) return old.descendant(new)
--- a/mercurial/obsolete.py Mon Apr 15 17:10:58 2013 +0200 +++ b/mercurial/obsolete.py Tue Apr 16 15:16:33 2013 +0200 @@ -405,6 +405,33 @@ seen.add(suc) remaining.add(suc) +def foreground(repo, nodes): + """return all nodes in the "foreground" of other node + + The foreground of a revision is anything reachable using parent -> children + or precursor -> sucessor relation. It is very similars to "descendant" but + augmented with obsolescence information. + + Beware that possible obsolescence cycle may result if complexe situation. + """ + repo = repo.unfiltered() + foreground = set(repo.set('%ln::', nodes)) + if repo.obsstore: + # We only need this complicated logic if there is obsolescence + # XXX will probably deserve an optimised revset. + nm = repo.changelog.nodemap + plen = -1 + # compute the whole set of successors or descendants + while len(foreground) != plen: + plen = len(foreground) + succs = set(c.node() for c in foreground) + mutable = [c.node() for c in foreground if c.mutable()] + succs.update(allsuccessors(repo.obsstore, mutable)) + known = (n for n in succs if n in nm) + foreground = set(repo.set('%ln::', known)) + return set(c.node() for c in foreground) + + def successorssets(repo, initialnode, cache=None): """Return all set of successors of initial nodes