annotate src/org/tmatesoft/hg/internal/RevisionSet.java @ 707:42b88709e41d

Merge: support 'unresolved' resolution with MergeStateBuilder
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Aug 2013 19:22:59 +0200
parents 629a7370554c
children
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;
653
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
22 import java.util.Arrays;
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.Collection;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.Collections;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.HashSet;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
26 import java.util.Iterator;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
27 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
28 import java.util.Set;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 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
31 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
32 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
33 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
34
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * 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
37 *
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author Artem Tikhomirov
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 * @author TMate Software Ltd.
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 */
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
41 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
42
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 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
44
653
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
45 public RevisionSet(Nodeid... revisions) {
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
46 this(revisions == null ? null : Arrays.asList(revisions));
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
47 }
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
48
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 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
50 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
51 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 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
54 if (revisions.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 elements = Collections.<Nodeid>emptySet();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 elements = revisions;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
61 /**
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
62 * 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
63 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
64 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
65 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
66 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
67 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
68 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
69 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
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 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
74 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
75 copy.remove(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
76 continue;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
77 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
78 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
79 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
80 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
82 /**
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
83 * 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
84 */
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 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
86 // 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
87 // 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
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 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
100 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
101 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
102 }
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
103 }
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
104 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
105 }
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
106
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
107 /**
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
108 * 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
109 */
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
110 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
111 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
112 // 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
113 for (Nodeid n : elements) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
114 assert ph.knownNode(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
115 Nodeid p1 = ph.firstParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
116 Nodeid p2 = ph.secondParent(n);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
117 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
118 copy.remove(p1);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
119 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
120 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
121 copy.remove(p2);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
122 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
123 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
124 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
125 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
126
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
127 /**
651
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
128 * 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
129 * 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
130 */
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
131 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
132 if (isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
133 return this;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
134 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
135 if (children.isEmpty()) {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
136 return children;
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
137 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 }
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 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
150 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
151 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
152 }
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
153 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
154 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
155 }
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 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
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
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 /**
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 * 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
161 * 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
162 */
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 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
164 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
165 return this;
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
166 }
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
167 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
168 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
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 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
172 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 return other;
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 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
179 copy.retainAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 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
181 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 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
184 if (isEmpty() || other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 return this;
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 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
188 copy.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 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
190 }
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 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
193 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 return this;
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 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
200 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
201 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
202 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 /**
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 * 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
206 * 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
207 */
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 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
209 if (isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
210 return this;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212 if (other.isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 return other;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 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
216 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
217 copyA.removeAll(other.elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 copyB.removeAll(elements);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 copyA.addAll(copyB);
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 return new RevisionSet(copyA);
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
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 public boolean isEmpty() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 return elements.isEmpty();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226
651
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
227 public int size() {
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
228 return elements.size();
6e98d34eaca8 Push: tests (push to empty, push changes, respect secret)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 650
diff changeset
229 }
649
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
230
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
231 public List<Nodeid> asList() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
232 return new ArrayList<Nodeid>(elements);
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
233 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
234
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
235 public Iterator<Nodeid> iterator() {
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
236 return elements.iterator();
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
237 }
e79cf9a8130b Push: phase4 - update local and remote phase information
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 648
diff changeset
238
648
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 public String toString() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 StringBuilder sb = new StringBuilder();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 sb.append('<');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 if (!isEmpty()) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 sb.append(elements.size());
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 sb.append(':');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 for (Nodeid n : elements) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248 sb.append(n.shortNotation());
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 if (sb.length() > 1) {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 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
253 } else {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 sb.append('>');
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 return sb.toString();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
257 }
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 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260 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
261 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
262 return false;
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 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
265 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
266
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 @Override
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
268 public int hashCode() {
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269 return elements.hashCode();
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 }
690e71d29bf6 Introduced RevisionSet to ease update of phase roots on push
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 }