annotate 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
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
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
20
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
21 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
22 import java.util.Collection;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.Collections;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.HashSet;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
25 import java.util.Iterator;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
26 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
27 import java.util.Set;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 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
30 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
31 import org.tmatesoft.hg.repo.HgParentChildMap;
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
32 import org.tmatesoft.hg.repo.HgRepository;
648
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 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * 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
36 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author Artem Tikhomirov
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author TMate Software Ltd.
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 */
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
40 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
41
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 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
43
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 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
45 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
46 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 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
49 if (revisions.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 elements = Collections.<Nodeid>emptySet();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 elements = revisions;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
56 /**
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
57 * 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
58 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
59 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
60 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
61 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
62 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
63 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
64 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
65 copy.remove(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
66 continue;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
67 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
68 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
69 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
70 copy.remove(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
71 continue;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
72 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
73 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
74 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
75 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
77 /**
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
78 * Same as {@link #roots(HgParentChildMap)}, but doesn't require a parent-child map
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
79 */
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
80 public RevisionSet roots(HgRepository repo) {
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
81 // TODO introduce parent access interface, use it here, provide implementations
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
82 // that delegate to HgParentChildMap or HgRepository
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
83 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
84 final HgChangelog clog = repo.getChangelog();
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
85 byte[] parent1 = new byte[Nodeid.SIZE], parent2 = new byte[Nodeid.SIZE];
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
86 int[] parentRevs = new int[2];
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
87 for (Nodeid n : elements) {
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
88 assert clog.isKnown(n);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
89 clog.parents(clog.getRevisionIndex(n), parentRevs, parent1, parent2);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
90 if (parentRevs[0] != NO_REVISION && elements.contains(new Nodeid(parent1, false))) {
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
91 copy.remove(n);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
92 continue;
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
93 }
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
94 if (parentRevs[1] != NO_REVISION && elements.contains(new Nodeid(parent2, false))) {
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
95 copy.remove(n);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
96 continue;
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
97 }
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
98 }
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
99 return copy.size() == elements.size() ? this : new RevisionSet(copy);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
100 }
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
101
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
102 /**
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
103 * 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
104 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
105 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
106 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
107 // 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
108 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
109 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
110 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
111 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
112 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
113 copy.remove(p1);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
114 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
115 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
116 copy.remove(p2);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
117 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
118 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
119 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
120 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
121
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
122 /**
651
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
123 * Any ancestor of an element from the supplied child set found in this one.
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
124 * Elements of the supplied child set are not part of return value.
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
125 */
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
126 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
127 if (isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
128 return this;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
129 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
130 if (children.isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
131 return children;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
132 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 }
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
144 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
145 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
146 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
147 }
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
148 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
149 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
150 }
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
151 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
152 }
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
153
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
154 /**
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
155 * 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
156 * 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
157 */
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
158 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
159 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
160 return this;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
161 }
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
162 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
163 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
164 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 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
167 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 return this;
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 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 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
174 copy.retainAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 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
176 }
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 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
179 if (isEmpty() || other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 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
183 copy.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 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
185 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 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
188 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 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
195 copy.addAll(other.elements);
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 651
diff changeset
196 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
197 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 * 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
201 * 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
202 */
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 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
204 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 return other;
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 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
211 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
212 copyA.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 copyB.removeAll(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 copyA.addAll(copyB);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 return new RevisionSet(copyA);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 public boolean isEmpty() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 return elements.isEmpty();
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
651
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
222 public int size() {
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
223 return elements.size();
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
224 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
225
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
226 public List<Nodeid> asList() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
227 return new ArrayList<Nodeid>(elements);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
228 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
229
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
230 public Iterator<Nodeid> iterator() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
231 return elements.iterator();
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
232 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
233
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
235 public String toString() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
236 StringBuilder sb = new StringBuilder();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 sb.append('<');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 if (!isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 sb.append(elements.size());
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 sb.append(':');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 for (Nodeid n : elements) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 sb.append(n.shortNotation());
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 sb.append(',');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 if (sb.length() > 1) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 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
248 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 sb.append('>');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251 return sb.toString();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 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
256 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
257 return false;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
258 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 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
260 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
261
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 public int hashCode() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 return elements.hashCode();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
265 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
266 }