diff src/org/tmatesoft/hg/internal/PhasesHelper.java @ 648:690e71d29bf6

Introduced RevisionSet to ease update of phase roots on push
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 25 Jun 2013 20:48:37 +0200
parents c75297c17867
children e79cf9a8130b
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/PhasesHelper.java	Tue Jun 25 18:53:18 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/PhasesHelper.java	Tue Jun 25 20:48:37 2013 +0200
@@ -131,7 +131,39 @@
 			}
 		}
 		return HgPhase.Public;
+	}
 
+
+	/**
+	 * @return all revisions with secret phase
+	 */
+	public RevisionSet allSecret() {
+		return allOf(HgPhase.Secret);
+	}
+	
+	public RevisionSet allDraft() {
+		return allOf(HgPhase.Draft).subtract(allOf(HgPhase.Secret));
+	}
+
+	/**
+	 * For a given phase, collect all revisions with phase that is the same or more private (i.e. for Draft, returns Draft+Secret)
+	 * The reason is not a nice API intention (which is awful, indeed), but an ease of implementation 
+	 */
+	private RevisionSet allOf(HgPhase phase) {
+		assert phase != HgPhase.Public;
+		if (!isCapableOfPhases()) {
+			return new RevisionSet(Collections.<Nodeid>emptyList());
+		}
+		final List<Nodeid> roots = getPhaseRoots(phase);
+		if (parentHelper != null) {
+			return new RevisionSet(roots).union(new RevisionSet(parentHelper.childrenOf(roots)));
+		} else {
+			RevisionSet rv = new RevisionSet(Collections.<Nodeid>emptyList());
+			for (RevisionDescendants rd : getPhaseDescendants(phase)) {
+				rv = rv.union(rd.asRevisionSet());
+			}
+			return rv;
+		}
 	}
 
 	private Boolean readRoots() throws HgRuntimeException {