[PATCH 6 of 9] add a function to calculate the branch heads that will be closed
Alexis S. L. Carvalho
alexis at cecm.usp.br
Sun Mar 2 19:01:28 UTC 2008
# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1204481759 10800
# Node ID 09195d7818674502a33a74060ac41e58092c6a50
# Parent cd038204b2f47831131a5b28cee6c5864605aa30
add a function to calculate the branch heads that will be closed
diff -r cd038204b2f4 -r 09195d781867 mercurial/localrepo.py
--- a/mercurial/localrepo.py Sun Mar 02 15:15:59 2008 -0300
+++ b/mercurial/localrepo.py Sun Mar 02 15:15:59 2008 -0300
@@ -721,6 +721,46 @@ class localrepository(repo.repository):
self.origroot)
self._wlockref = weakref.ref(l)
return l
+
+ def closebranchnodes(self, name, parents):
+ """
+ returns the heads of branch name that are ancestors of one of the
+ parents
+ """
+ branches = self.branchtags()
+ if name not in branches:
+ raise repo.RepoError(_("there's no branch named %s") % name)
+ heads = branches[name]
+ parents = [p for p in parents if p != nullid]
+
+ # The easy common case: see if the heads we want to close
+ # are in parents
+ close = [p for p in parents if p in heads]
+ if len(close) == len(heads) or len(close) == len(parents):
+ # either all the heads of the branch were in parents,
+ # or all parents were heads of the branch
+ return close
+
+ # Handle the more general case: see if one or more of the remaining
+ # heads are ancestors of one of the remaining parents
+ cl = self.changelog
+ parents = [cl.rev(p) for p in parents if p not in close]
+ heads = dict.fromkeys([cl.rev(n) for n in branches[name]
+ if n not in close])
+ ancestors = dict.fromkeys(parents)
+ for r in xrange(max(parents), min(heads) - 1, -1):
+ if r in ancestors:
+ if r in heads:
+ close.append(cl.node(r))
+ # no need to put parentrevs(r) in ancestor
+ # since the other heads are not ancestors of r
+ else:
+ for p in cl.parentrevs(r):
+ if p != nullrev:
+ ancestors[p] = 1
+ del ancestors[r]
+
+ return close
def filecommit(self, fn, manifest1, manifest2, linkrev, tr, changelist):
"""
More information about the Mercurial-devel
mailing list