Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgStatusCollector.java @ 403:2747b0723867
FIXMEs: work on exceptions and javadoc
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 05 Mar 2012 14:50:51 +0100 |
parents | 0ae53c32ecef |
children | 866fc3b597a0 |
comparison
equal
deleted
inserted
replaced
402:1fcc7f7b6d65 | 403:2747b0723867 |
---|---|
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.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import static org.tmatesoft.hg.repo.HgRepository.*; |
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; | |
21 | 20 |
22 import java.util.Collection; | 21 import java.util.Collection; |
23 import java.util.Collections; | 22 import java.util.Collections; |
24 import java.util.LinkedHashMap; | 23 import java.util.LinkedHashMap; |
25 import java.util.LinkedList; | 24 import java.util.LinkedList; |
28 import java.util.TreeSet; | 27 import java.util.TreeSet; |
29 | 28 |
30 import org.tmatesoft.hg.core.HgBadStateException; | 29 import org.tmatesoft.hg.core.HgBadStateException; |
31 import org.tmatesoft.hg.core.HgException; | 30 import org.tmatesoft.hg.core.HgException; |
32 import org.tmatesoft.hg.core.HgInvalidControlFileException; | 31 import org.tmatesoft.hg.core.HgInvalidControlFileException; |
32 import org.tmatesoft.hg.core.HgInvalidRevisionException; | |
33 import org.tmatesoft.hg.core.Nodeid; | 33 import org.tmatesoft.hg.core.Nodeid; |
34 import org.tmatesoft.hg.internal.IntMap; | 34 import org.tmatesoft.hg.internal.IntMap; |
35 import org.tmatesoft.hg.internal.ManifestRevision; | 35 import org.tmatesoft.hg.internal.ManifestRevision; |
36 import org.tmatesoft.hg.internal.Pool; | 36 import org.tmatesoft.hg.internal.Pool; |
37 import org.tmatesoft.hg.util.Path; | 37 import org.tmatesoft.hg.util.Path; |
182 public void setScope(Path.Matcher scopeMatcher) { | 182 public void setScope(Path.Matcher scopeMatcher) { |
183 // do not assign null, ever | 183 // do not assign null, ever |
184 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; | 184 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; |
185 } | 185 } |
186 | 186 |
187 // hg status --change <rev> | 187 /** |
188 public void change(int rev, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { | 188 * 'hg status --change REV' command counterpart. |
189 * | |
190 * @throws HgInvalidRevisionException if argument specifies non-existent revision index | |
191 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
192 */ | |
193 public void change(int revisionIndex, HgStatusInspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { | |
189 int[] parents = new int[2]; | 194 int[] parents = new int[2]; |
190 repo.getChangelog().parents(rev, parents, null, null); | 195 repo.getChangelog().parents(revisionIndex, parents, null, null); |
191 walk(parents[0], rev, inspector); | 196 walk(parents[0], revisionIndex, inspector); |
192 } | 197 } |
193 | 198 |
194 // rev1 and rev2 are changelog revision numbers, argument order matters. | 199 /** |
195 // Either rev1 or rev2 may be -1 to indicate comparison to empty repository (XXX this is due to use of | 200 * Parameters <b>rev1</b> and <b>rev2</b> are changelog revision indexes, shall not be the same. Argument order matters. |
196 // parents in #change(), I believe. Perhaps, need a constant for this? Otherwise this hidden knowledge gets | 201 * FIXME Either rev1 or rev2 may be -1 to indicate comparison to empty repository (this is due to use of |
197 // exposed to e.g. Record | 202 * parents in #change(), I believe. Perhaps, need a constant for this? Otherwise this hidden knowledge gets |
198 public void walk(int rev1, int rev2, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { | 203 * exposed to e.g. Record |
204 * XXX cancellation? | |
205 * | |
206 * @param rev1 <em>from</em> changeset index, non-negative or {@link HgRepository#TIP} | |
207 * @param rev2 <em>to</em> changeset index, non-negative or {@link HgRepository#TIP} | |
208 * @param inspector callback for status information | |
209 * @throws HgInvalidRevisionException if any argument specifies non-existent revision index | |
210 * @throws IllegalArgumentException inspector other incorrect argument values | |
211 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
212 */ | |
213 public void walk(int rev1, int rev2, HgStatusInspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { | |
199 if (rev1 == rev2) { | 214 if (rev1 == rev2) { |
200 throw new IllegalArgumentException(); | 215 throw new IllegalArgumentException(); |
201 } | 216 } |
202 if (inspector == null) { | 217 if (inspector == null) { |
203 throw new IllegalArgumentException(); | 218 throw new IllegalArgumentException(); |
204 } | 219 } |
205 final int lastManifestRevision = repo.getChangelog().getLastRevision(); | 220 final int lastChangelogRevision = repo.getChangelog().getLastRevision(); |
206 if (rev1 == TIP) { | 221 if (rev1 == TIP) { |
207 rev1 = lastManifestRevision; | 222 rev1 = lastChangelogRevision; |
208 } | 223 } |
209 if (rev2 == TIP) { | 224 if (rev2 == TIP) { |
210 rev2 = lastManifestRevision; | 225 rev2 = lastChangelogRevision; |
226 } | |
227 if (rev1 != -1 && (HgInternals.wrongRevisionIndex(rev1) || rev1 == WORKING_COPY || rev1 == BAD_REVISION || rev1 > lastChangelogRevision)) { | |
228 throw new HgInvalidRevisionException(rev1); | |
229 } | |
230 if (rev2 != -1 && (HgInternals.wrongRevisionIndex(rev2) || rev2 == WORKING_COPY || rev2 == BAD_REVISION || rev2 > lastChangelogRevision)) { | |
231 throw new HgInvalidRevisionException(rev2); | |
211 } | 232 } |
212 if (inspector instanceof Record) { | 233 if (inspector instanceof Record) { |
213 ((Record) inspector).init(rev1, rev2, this); | 234 ((Record) inspector).init(rev1, rev2, this); |
214 } | 235 } |
215 // in fact, rev1 and rev2 are often next (or close) to each other, | 236 // in fact, rev1 and rev2 are often next (or close) to each other, |
231 // read with neighbors to save potential subsequent calls for neighboring elements | 252 // read with neighbors to save potential subsequent calls for neighboring elements |
232 // XXX perhaps, if revlog.baseRevision is cheap, shall expand minRev up to baseRevision | 253 // XXX perhaps, if revlog.baseRevision is cheap, shall expand minRev up to baseRevision |
233 // which going to be read anyway | 254 // which going to be read anyway |
234 if (need1) { | 255 if (need1) { |
235 minRev = rev1; | 256 minRev = rev1; |
236 maxRev = rev1 < lastManifestRevision-5 ? rev1+5 : lastManifestRevision; | 257 maxRev = rev1 < lastChangelogRevision-5 ? rev1+5 : lastChangelogRevision; |
237 initCacheRange(minRev, maxRev); | 258 initCacheRange(minRev, maxRev); |
238 } | 259 } |
239 if (need2) { | 260 if (need2) { |
240 minRev = rev2; | 261 minRev = rev2; |
241 maxRev = rev2 < lastManifestRevision-5 ? rev2+5 : lastManifestRevision; | 262 maxRev = rev2 < lastChangelogRevision-5 ? rev2+5 : lastChangelogRevision; |
242 initCacheRange(minRev, maxRev); | 263 initCacheRange(minRev, maxRev); |
243 } | 264 } |
244 } | 265 } |
245 r1 = get(rev1); | 266 r1 = get(rev1); |
246 r2 = get(rev2); | 267 r2 = get(rev2); |
281 inspector.removed(r1fname); | 302 inspector.removed(r1fname); |
282 } | 303 } |
283 } | 304 } |
284 } | 305 } |
285 | 306 |
286 public Record status(int rev1, int rev2) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { | 307 /** |
308 * Collects status between two revisions, changes from <b>rev1</b> up to <b>rev2</b>. | |
309 * | |
310 * @param rev1 <em>from</em> changeset index | |
311 * @param rev2 <em>to</em> changeset index | |
312 * @return information object that describes change between the revisions | |
313 * @throws HgInvalidRevisionException if any argument specifies non-existent revision index | |
314 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | |
315 */ | |
316 public Record status(int rev1, int rev2) throws HgInvalidRevisionException, HgInvalidControlFileException { | |
287 Record rv = new Record(); | 317 Record rv = new Record(); |
288 walk(rev1, rev2, rv); | 318 walk(rev1, rev2, rv); |
289 return rv; | 319 return rv; |
290 } | 320 } |
291 | 321 |