comparison src/org/tmatesoft/hg/core/HgStatusCommand.java @ 367:2fadf8695f8a

Use 'revision index' instead of the vague 'local revision number' concept in the API
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Dec 2011 15:37:27 +0100
parents 150500515714
children 8107b95f4280
comparison
equal deleted inserted replaced
366:189dc6dc1c3e 367:2fadf8695f8a
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import static org.tmatesoft.hg.core.HgStatus.Kind.*; 19 import static org.tmatesoft.hg.core.HgStatus.Kind.*;
20 import static org.tmatesoft.hg.repo.HgInternals.wrongLocalRevision; 20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex;
21 import static org.tmatesoft.hg.repo.HgRepository.*; 21 import static org.tmatesoft.hg.repo.HgRepository.*;
22 22
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.util.ConcurrentModificationException; 24 import java.util.ConcurrentModificationException;
25 import java.util.concurrent.CancellationException; 25 import java.util.concurrent.CancellationException;
96 } 96 }
97 97
98 /** 98 /**
99 * If set, either base:revision or base:workingdir 99 * If set, either base:revision or base:workingdir
100 * to unset, pass {@link HgRepository#TIP} or {@link HgRepository#BAD_REVISION} 100 * to unset, pass {@link HgRepository#TIP} or {@link HgRepository#BAD_REVISION}
101 * @param revision - local revision number to base status from 101 * @param changesetRevisionIndex - local index of a changeset to base status from
102 * @return <code>this</code> for convenience 102 * @return <code>this</code> for convenience
103 * @throws IllegalArgumentException when revision is negative or {@link HgRepository#WORKING_COPY} 103 * @throws IllegalArgumentException when revision is negative or {@link HgRepository#WORKING_COPY}
104 */ 104 */
105 public HgStatusCommand base(int revision) { 105 public HgStatusCommand base(int changesetRevisionIndex) {
106 if (revision == WORKING_COPY || wrongLocalRevision(revision)) { 106 if (changesetRevisionIndex == WORKING_COPY || wrongRevisionIndex(changesetRevisionIndex)) {
107 throw new IllegalArgumentException(String.valueOf(revision)); 107 throw new IllegalArgumentException(String.valueOf(changesetRevisionIndex));
108 } 108 }
109 if (revision == BAD_REVISION) { 109 if (changesetRevisionIndex == BAD_REVISION) {
110 revision = TIP; 110 changesetRevisionIndex = TIP;
111 } 111 }
112 startRevision = revision; 112 startRevision = changesetRevisionIndex;
113 return this; 113 return this;
114 } 114 }
115 115
116 /** 116 /**
117 * Revision without base == --change 117 * Revision without base == --change
118 * Pass {@link HgRepository#WORKING_COPY} or {@link HgRepository#BAD_REVISION} to reset 118 * Pass {@link HgRepository#WORKING_COPY} or {@link HgRepository#BAD_REVISION} to reset
119 * @param revision - non-negative local revision number, or any of {@link HgRepository#BAD_REVISION}, {@link HgRepository#WORKING_COPY} or {@link HgRepository#TIP} 119 * @param changesetRevisionIndex - non-negative local revision number, or any of {@link HgRepository#BAD_REVISION}, {@link HgRepository#WORKING_COPY} or {@link HgRepository#TIP}
120 * @return <code>this</code> for convenience 120 * @return <code>this</code> for convenience
121 * @throws IllegalArgumentException if local revision number doesn't specify legitimate revision. 121 * @throws IllegalArgumentException if local revision number doesn't specify legitimate revision.
122 */ 122 */
123 public HgStatusCommand revision(int revision) { 123 public HgStatusCommand revision(int changesetRevisionIndex) {
124 if (revision == BAD_REVISION) { 124 if (changesetRevisionIndex == BAD_REVISION) {
125 revision = WORKING_COPY; 125 changesetRevisionIndex = WORKING_COPY;
126 } 126 }
127 if (wrongLocalRevision(revision)) { 127 if (wrongRevisionIndex(changesetRevisionIndex)) {
128 throw new IllegalArgumentException(String.valueOf(revision)); 128 throw new IllegalArgumentException(String.valueOf(changesetRevisionIndex));
129 } 129 }
130 endRevision = revision; 130 endRevision = changesetRevisionIndex;
131 return this; 131 return this;
132 } 132 }
133 133
134 /** 134 /**
135 * Shorthand for {@link #base(int) cmd.base(BAD_REVISION)}{@link #change(int) .revision(revision)} 135 * Shorthand for {@link #base(int) cmd.base(BAD_REVISION)}{@link #change(int) .revision(revision)}
192 } 192 }
193 } catch (HgCallbackTargetException.Wrap ex) { 193 } catch (HgCallbackTargetException.Wrap ex) {
194 // seems too general to catch RuntimeException, i.e. 194 // seems too general to catch RuntimeException, i.e.
195 // unless catch is for very narrow piece of code, it's better not to catch any RTE (which may happen elsewhere, not only in handler) 195 // unless catch is for very narrow piece of code, it's better not to catch any RTE (which may happen elsewhere, not only in handler)
196 // XXX Perhaps, need more detailed explanation in handlers that are expected to throw Wrap/RTE (i.e. HgChangesetHandler) 196 // XXX Perhaps, need more detailed explanation in handlers that are expected to throw Wrap/RTE (i.e. HgChangesetHandler)
197 throw new HgCallbackTargetException(ex).setRevisionNumber(endRevision); 197 throw new HgCallbackTargetException(ex).setRevisionIndex(endRevision);
198 } finally { 198 } finally {
199 mediator.done(); 199 mediator.done();
200 } 200 }
201 } 201 }
202 202