Mercurial > jhg
diff src/org/tmatesoft/hg/internal/RevisionSet.java @ 652:cd77bf51b562
Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 02 Jul 2013 23:21:16 +0200 |
parents | 6e98d34eaca8 |
children | 629a7370554c |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevisionSet.java Mon Jul 01 21:19:53 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/RevisionSet.java Tue Jul 02 23:21:16 2013 +0200 @@ -16,6 +16,8 @@ */ package org.tmatesoft.hg.internal; +import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,6 +29,7 @@ import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgChangelog; import org.tmatesoft.hg.repo.HgParentChildMap; +import org.tmatesoft.hg.repo.HgRepository; /** * Unmodifiable collection of revisions with handy set operations @@ -72,6 +75,31 @@ } /** + * Same as {@link #roots(HgParentChildMap)}, but doesn't require a parent-child map + */ + public RevisionSet roots(HgRepository repo) { + // TODO introduce parent access interface, use it here, provide implementations + // that delegate to HgParentChildMap or HgRepository + HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); + final HgChangelog clog = repo.getChangelog(); + byte[] parent1 = new byte[Nodeid.SIZE], parent2 = new byte[Nodeid.SIZE]; + int[] parentRevs = new int[2]; + for (Nodeid n : elements) { + assert clog.isKnown(n); + clog.parents(clog.getRevisionIndex(n), parentRevs, parent1, parent2); + if (parentRevs[0] != NO_REVISION && elements.contains(new Nodeid(parent1, false))) { + copy.remove(n); + continue; + } + if (parentRevs[1] != NO_REVISION && elements.contains(new Nodeid(parent2, false))) { + copy.remove(n); + continue; + } + } + return copy.size() == elements.size() ? this : new RevisionSet(copy); + } + + /** * elements of the set that has no children in this set */ public RevisionSet heads(HgParentChildMap<HgChangelog> ph) { @@ -165,7 +193,7 @@ } HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); copy.addAll(other.elements); - return new RevisionSet(copy); + return copy.size() == elements.size() ? this : new RevisionSet(copy); } /**