annotate 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
rev   line source
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
19 import java.util.ArrayList;
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.util.Collection;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.Collections;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.HashSet;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
23 import java.util.Iterator;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
24 import java.util.List;
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.Set;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.core.Nodeid;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
28 import org.tmatesoft.hg.repo.HgChangelog;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
29 import org.tmatesoft.hg.repo.HgParentChildMap;
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * Unmodifiable collection of revisions with handy set operations
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * @author Artem Tikhomirov
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author TMate Software Ltd.
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 */
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
37 public final class RevisionSet implements Iterable<Nodeid> {
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 private final Set<Nodeid> elements;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public RevisionSet(Collection<Nodeid> revisions) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 this(revisions == null ? new HashSet<Nodeid>() : new HashSet<Nodeid>(revisions));
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 private RevisionSet(HashSet<Nodeid> revisions) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 if (revisions.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 elements = Collections.<Nodeid>emptySet();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 elements = revisions;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
53 /**
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
54 * elements of the set with no parents or parents not from the same set
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
55 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
56 public RevisionSet roots(HgParentChildMap<HgChangelog> ph) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
57 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
58 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
59 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
60 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
61 if (p1 != null && elements.contains(p1)) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
62 copy.remove(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
63 continue;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
64 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
65 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
66 if (p2 != null && elements.contains(p2)) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
67 copy.remove(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
68 continue;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
69 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
70 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
71 return copy.size() == elements.size() ? this : new RevisionSet(copy);
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
74 /**
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
75 * elements of the set that has no children in this set
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
76 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
77 public RevisionSet heads(HgParentChildMap<HgChangelog> ph) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
78 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
79 // can't do copy.removeAll(ph.childrenOf(asList())); as actual heads are indeed children of some other node
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
80 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
81 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
82 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
83 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
84 if (p1 != null && elements.contains(p1)) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
85 copy.remove(p1);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
86 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
87 if (p2 != null && elements.contains(p2)) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
88 copy.remove(p2);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
89 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
90 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
91 return copy.size() == elements.size() ? this : new RevisionSet(copy);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
92 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
93
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
94 /**
650
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
95 * Any ancestor of an element from the supplied children set found in this one.
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
96 */
650
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
97 public RevisionSet ancestors(RevisionSet children, HgParentChildMap<HgChangelog> parentHelper) {
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
98 if (isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
99 return this;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
100 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
101 if (children.isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
102 return children;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
103 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
104 RevisionSet chRoots = children.roots(parentHelper);
650
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
105 HashSet<Nodeid> ancestors = new HashSet<Nodeid>();
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
106 Set<Nodeid> childrenToCheck = chRoots.elements;
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
107 while (!childrenToCheck.isEmpty()) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
108 HashSet<Nodeid> nextRound = new HashSet<Nodeid>();
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
109 for (Nodeid n : childrenToCheck) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
110 Nodeid p1 = parentHelper.firstParent(n);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
111 Nodeid p2 = parentHelper.secondParent(n);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
112 if (p1 != null && elements.contains(p1)) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
113 nextRound.add(p1);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
114 }
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
115 if (p2 != null && elements.contains(p2)) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
116 nextRound.add(p2);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
117 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
118 }
650
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
119 ancestors.addAll(nextRound);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
120 childrenToCheck = nextRound;
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
121 }
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
122 return new RevisionSet(ancestors);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
123 }
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
124
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
125 /**
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
126 * Revisions that are both direct and indirect children of elements of this revision set
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
127 * as known in supplied parent-child map
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
128 */
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
129 public RevisionSet children(HgParentChildMap<HgChangelog> parentHelper) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
130 if (isEmpty()) {
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
131 return this;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
132 }
650
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
133 List<Nodeid> children = parentHelper.childrenOf(elements);
3b275cc2d2aa Push: phase4 - settle local and remote phases, push updated phases regardless of server publishing state, do not push secret changesets
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 649
diff changeset
134 return new RevisionSet(new HashSet<Nodeid>(children));
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 public RevisionSet intersect(RevisionSet other) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 copy.retainAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 return copy.size() == elements.size() ? this : new RevisionSet(copy);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 public RevisionSet subtract(RevisionSet other) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 if (isEmpty() || other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 copy.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 return copy.size() == elements.size() ? this : new RevisionSet(copy);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 public RevisionSet union(RevisionSet other) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 copy.addAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 return new RevisionSet(copy);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 * A ^ B := (A\B).union(B\A)
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 * A ^ B := A.union(B) \ A.intersect(B)
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 */
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 public RevisionSet symmetricDifference(RevisionSet other) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 HashSet<Nodeid> copyA = new HashSet<Nodeid>(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 HashSet<Nodeid> copyB = new HashSet<Nodeid>(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 copyA.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 copyB.removeAll(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 copyA.addAll(copyB);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 return new RevisionSet(copyA);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 public boolean isEmpty() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 return elements.isEmpty();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
193
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
194 public List<Nodeid> asList() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
195 return new ArrayList<Nodeid>(elements);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
196 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
197
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
198 public Iterator<Nodeid> iterator() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
199 return elements.iterator();
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
200 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
201
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 public String toString() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 StringBuilder sb = new StringBuilder();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 sb.append('<');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 if (!isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 sb.append(elements.size());
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 sb.append(':');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 for (Nodeid n : elements) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 sb.append(n.shortNotation());
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 sb.append(',');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 if (sb.length() > 1) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 sb.setCharAt(sb.length() - 1, '>');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 sb.append('>');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 return sb.toString();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 public boolean equals(Object obj) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 if (false == obj instanceof RevisionSet) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 return false;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 return elements.equals(((RevisionSet) obj).elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 public int hashCode() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 return elements.hashCode();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 }