comparison src/org/tmatesoft/hg/repo/HgInternals.java @ 347:8da7ade36c57

Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Nov 2011 05:25:57 +0100
parents 863356c2847e
children a0864b2892cd
comparison
equal deleted inserted replaced
346:6d2c6b2469fc 347:8da7ade36c57
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.Reader; 24 import java.io.Reader;
25 import java.net.InetAddress; 25 import java.net.InetAddress;
26 import java.net.UnknownHostException; 26 import java.net.UnknownHostException;
27 27
28 import org.tmatesoft.hg.core.HgInvalidRevisionException;
28 import org.tmatesoft.hg.core.SessionContext; 29 import org.tmatesoft.hg.core.SessionContext;
29 import org.tmatesoft.hg.internal.Experimental; 30 import org.tmatesoft.hg.internal.Experimental;
30 import org.tmatesoft.hg.internal.RelativePathRewrite; 31 import org.tmatesoft.hg.internal.RelativePathRewrite;
31 import org.tmatesoft.hg.util.FileIterator; 32 import org.tmatesoft.hg.util.FileIterator;
32 import org.tmatesoft.hg.util.FileWalker; 33 import org.tmatesoft.hg.util.FileWalker;
137 // Convenient check of local revision number for validity (not all negative values are wrong as long as we use negative constants) 138 // Convenient check of local revision number for validity (not all negative values are wrong as long as we use negative constants)
138 public static boolean wrongLocalRevision(int rev) { 139 public static boolean wrongLocalRevision(int rev) {
139 return rev < 0 && rev != TIP && rev != WORKING_COPY && rev != BAD_REVISION; 140 return rev < 0 && rev != TIP && rev != WORKING_COPY && rev != BAD_REVISION;
140 } 141 }
141 142
142 // throws IllegalArgumentException if [start..end] range is not a subrange of [0..lastRevision] 143 // throws HgInvalidRevisionException or IllegalArgumentException if [start..end] range is not a subrange of [0..lastRevision]
143 public static void checkRevlogRange(int start, int end, int lastRevision) { 144 public static void checkRevlogRange(int start, int end, int lastRevision) throws HgInvalidRevisionException {
144 if (start < 0 || start > lastRevision) { 145 if (start < 0 || start > lastRevision) {
145 throw new IllegalArgumentException(String.format("Bad left range boundary %d in [0..%d]", start, lastRevision)); 146 final String m = String.format("Bad left range boundary %d in [0..%d]", start, lastRevision);
147 throw new HgInvalidRevisionException(m, null, start).setRevisionIndex(start, 0, lastRevision);
146 } 148 }
147 if (end < 0 || end > lastRevision) { 149 if (end < 0 || end > lastRevision) {
148 throw new IllegalArgumentException(String.format("Bad right range boundary %d in [0..%d]", end, lastRevision)); 150 final String m = String.format("Bad right range boundary %d in [0..%d]", end, lastRevision);
151 throw new HgInvalidRevisionException(m, null, end).setRevisionIndex(end, 0, lastRevision);
149 } 152 }
150 if (end < start) { 153 if (end < start) {
151 throw new IllegalArgumentException(String.format("Bad range [%d..%d]", start, end)); 154 throw new IllegalArgumentException(String.format("Bad range [%d..%d]", start, end));
152 } 155 }
153 } 156 }