Mercurial > jhg
diff src/org/tmatesoft/hg/internal/RevisionSet.java @ 650:3b275cc2d2aa
Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 28 Jun 2013 19:27:26 +0200 |
parents | e79cf9a8130b |
children | 6e98d34eaca8 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevisionSet.java Wed Jun 26 20:52:38 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/RevisionSet.java Fri Jun 28 19:27:26 2013 +0200 @@ -92,9 +92,9 @@ } /** - * Immediate parents of the supplied children set found in this one. + * Any ancestor of an element from the supplied children set found in this one. */ - public RevisionSet parentsOf(RevisionSet children, HgParentChildMap<HgChangelog> parentHelper) { + public RevisionSet ancestors(RevisionSet children, HgParentChildMap<HgChangelog> parentHelper) { if (isEmpty()) { return this; } @@ -102,18 +102,36 @@ return children; } RevisionSet chRoots = children.roots(parentHelper); - HashSet<Nodeid> parents = new HashSet<Nodeid>(); - for (Nodeid n : chRoots.elements) { - Nodeid p1 = parentHelper.firstParent(n); - Nodeid p2 = parentHelper.secondParent(n); - if (p1 != null && elements.contains(p1)) { - parents.add(p1); + HashSet<Nodeid> ancestors = new HashSet<Nodeid>(); + Set<Nodeid> childrenToCheck = chRoots.elements; + while (!childrenToCheck.isEmpty()) { + HashSet<Nodeid> nextRound = new HashSet<Nodeid>(); + for (Nodeid n : childrenToCheck) { + Nodeid p1 = parentHelper.firstParent(n); + Nodeid p2 = parentHelper.secondParent(n); + if (p1 != null && elements.contains(p1)) { + nextRound.add(p1); + } + if (p2 != null && elements.contains(p2)) { + nextRound.add(p2); + } } - if (p2 != null && elements.contains(p2)) { - parents.add(p2); - } + ancestors.addAll(nextRound); + childrenToCheck = nextRound; + } + return new RevisionSet(ancestors); + } + + /** + * Revisions that are both direct and indirect children of elements of this revision set + * as known in supplied parent-child map + */ + public RevisionSet children(HgParentChildMap<HgChangelog> parentHelper) { + if (isEmpty()) { + return this; } - return new RevisionSet(parents); + List<Nodeid> children = parentHelper.childrenOf(elements); + return new RevisionSet(new HashSet<Nodeid>(children)); } public RevisionSet intersect(RevisionSet other) {