comparison 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
comparison
equal deleted inserted replaced
651:6e98d34eaca8 652:cd77bf51b562
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.internal; 17 package org.tmatesoft.hg.internal;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
20
19 import java.util.ArrayList; 21 import java.util.ArrayList;
20 import java.util.Collection; 22 import java.util.Collection;
21 import java.util.Collections; 23 import java.util.Collections;
22 import java.util.HashSet; 24 import java.util.HashSet;
23 import java.util.Iterator; 25 import java.util.Iterator;
25 import java.util.Set; 27 import java.util.Set;
26 28
27 import org.tmatesoft.hg.core.Nodeid; 29 import org.tmatesoft.hg.core.Nodeid;
28 import org.tmatesoft.hg.repo.HgChangelog; 30 import org.tmatesoft.hg.repo.HgChangelog;
29 import org.tmatesoft.hg.repo.HgParentChildMap; 31 import org.tmatesoft.hg.repo.HgParentChildMap;
32 import org.tmatesoft.hg.repo.HgRepository;
30 33
31 /** 34 /**
32 * Unmodifiable collection of revisions with handy set operations 35 * Unmodifiable collection of revisions with handy set operations
33 * 36 *
34 * @author Artem Tikhomirov 37 * @author Artem Tikhomirov
62 copy.remove(n); 65 copy.remove(n);
63 continue; 66 continue;
64 } 67 }
65 Nodeid p2 = ph.secondParent(n); 68 Nodeid p2 = ph.secondParent(n);
66 if (p2 != null && elements.contains(p2)) { 69 if (p2 != null && elements.contains(p2)) {
70 copy.remove(n);
71 continue;
72 }
73 }
74 return copy.size() == elements.size() ? this : new RevisionSet(copy);
75 }
76
77 /**
78 * Same as {@link #roots(HgParentChildMap)}, but doesn't require a parent-child map
79 */
80 public RevisionSet roots(HgRepository repo) {
81 // TODO introduce parent access interface, use it here, provide implementations
82 // that delegate to HgParentChildMap or HgRepository
83 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
84 final HgChangelog clog = repo.getChangelog();
85 byte[] parent1 = new byte[Nodeid.SIZE], parent2 = new byte[Nodeid.SIZE];
86 int[] parentRevs = new int[2];
87 for (Nodeid n : elements) {
88 assert clog.isKnown(n);
89 clog.parents(clog.getRevisionIndex(n), parentRevs, parent1, parent2);
90 if (parentRevs[0] != NO_REVISION && elements.contains(new Nodeid(parent1, false))) {
91 copy.remove(n);
92 continue;
93 }
94 if (parentRevs[1] != NO_REVISION && elements.contains(new Nodeid(parent2, false))) {
67 copy.remove(n); 95 copy.remove(n);
68 continue; 96 continue;
69 } 97 }
70 } 98 }
71 return copy.size() == elements.size() ? this : new RevisionSet(copy); 99 return copy.size() == elements.size() ? this : new RevisionSet(copy);
163 if (other.isEmpty()) { 191 if (other.isEmpty()) {
164 return this; 192 return this;
165 } 193 }
166 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements); 194 HashSet<Nodeid> copy = new HashSet<Nodeid>(elements);
167 copy.addAll(other.elements); 195 copy.addAll(other.elements);
168 return new RevisionSet(copy); 196 return copy.size() == elements.size() ? this : new RevisionSet(copy);
169 } 197 }
170 198
171 /** 199 /**
172 * A ^ B := (A\B).union(B\A) 200 * A ^ B := (A\B).union(B\A)
173 * A ^ B := A.union(B) \ A.intersect(B) 201 * A ^ B := A.union(B) \ A.intersect(B)