changeset 421:fdd7d756dea0 v0.8.5

Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 22 Mar 2012 23:09:11 +0100
parents 6c22bdc0bdfd
children 5d1cc7366d04
files src/org/tmatesoft/hg/internal/DataAccess.java src/org/tmatesoft/hg/internal/FilterDataAccess.java src/org/tmatesoft/hg/internal/InflaterDataAccess.java src/org/tmatesoft/hg/internal/Internals.java src/org/tmatesoft/hg/repo/HgDirstate.java src/org/tmatesoft/hg/repo/HgManifest.java src/org/tmatesoft/hg/repo/HgRepository.java
diffstat 7 files changed, 43 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/DataAccess.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/DataAccess.java	Thu Mar 22 23:09:11 2012 +0100
@@ -29,19 +29,19 @@
  * @author TMate Software Ltd.
  */
 public class DataAccess {
-	public boolean isEmpty() {
+	public boolean isEmpty() throws IOException {
 		return true;
 	}
-	// TODO throws IOException (few subclasses have non-trivial length() operation)
+	// IOException due to few subclasses that have non-trivial length() operation
 	// long length and offset are needed only in RevlogStream, makes no sense elsewhere
 	// because chunks Mercurial operates with fit into int (4 bytes actualLength field)
 	// For those that may face large pieces of data (actual data streams) there are #longLength 
 	// and #longSeek() to implement
-	public int length() {
+	public int length() throws IOException {
 		return 0;
 	}
 	
-	public long longLength() {
+	public long longLength() throws IOException {
 		return length();
 	}
 	
--- a/src/org/tmatesoft/hg/internal/FilterDataAccess.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/FilterDataAccess.java	Thu Mar 22 23:09:11 2012 +0100
@@ -39,7 +39,7 @@
 		count = length;
 	}
 
-	protected int available() {
+	protected int available() throws IOException {
 		return count;
 	}
 
@@ -50,12 +50,12 @@
 	}
 	
 	@Override
-	public boolean isEmpty() {
+	public boolean isEmpty() throws IOException {
 		return count <= 0;
 	}
 	
 	@Override
-	public int length() {
+	public int length() throws IOException {
 		return length;
 	}
 
--- a/src/org/tmatesoft/hg/internal/InflaterDataAccess.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/InflaterDataAccess.java	Thu Mar 22 23:09:11 2012 +0100
@@ -67,50 +67,45 @@
 	}
 	
 	@Override
-	protected int available() {
+	protected int available() throws IOException {
 		return length() - decompressedPos;
 	}
 	
 	@Override
-	public boolean isEmpty() {
+	public boolean isEmpty() throws IOException {
 		// can't use super.available() <= 0 because even when 0 < super.count < 6(?)
 		// decompressedPos might be already == length() 
 		return available() <= 0;
 	}
 	
 	@Override
-	public int length() {
+	public int length() throws IOException {
 		if (decompressedLength != -1) {
 			return decompressedLength;
 		}
 		decompressedLength = 0; // guard to avoid endless loop in case length() would get invoked from below. 
 		int c = 0;
-		try {
-			int oldPos = decompressedPos;
-			byte[] dummy = new byte[buffer.length];
-			int toRead;
-			while ((toRead = super.available()) > 0) {
-				if (toRead > buffer.length) {
-					toRead = buffer.length;
+		int oldPos = decompressedPos;
+		byte[] dummy = new byte[buffer.length];
+		int toRead;
+		while ((toRead = super.available()) > 0) {
+			if (toRead > buffer.length) {
+				toRead = buffer.length;
+			}
+			super.readBytes(buffer, 0, toRead);
+			inflater.setInput(buffer, 0, toRead);
+			try {
+				while (!inflater.needsInput()) {
+					c += inflater.inflate(dummy, 0, dummy.length);
 				}
-				super.readBytes(buffer, 0, toRead);
-				inflater.setInput(buffer, 0, toRead);
-				try {
-					while (!inflater.needsInput()) {
-						c += inflater.inflate(dummy, 0, dummy.length);
-					}
-				} catch (DataFormatException ex) {
-					throw new HgBadStateException(ex);
-				}
+			} catch (DataFormatException ex) {
+				throw new HgBadStateException(ex);
 			}
-			decompressedLength = c + oldPos;
-			reset();
-			seek(oldPos);
-			return decompressedLength;
-		} catch (IOException ex) {
-			decompressedLength = -1; // better luck next time?
-			throw new HgBadStateException(ex); // XXX perhaps, checked exception
 		}
+		decompressedLength = c + oldPos;
+		reset();
+		seek(oldPos);
+		return decompressedLength;
 	}
 	
 	@Override
--- a/src/org/tmatesoft/hg/internal/Internals.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/Internals.java	Thu Mar 22 23:09:11 2012 +0100
@@ -90,7 +90,7 @@
 		try {
 			new RequiresFile().parse(this, requiresFile);
 		} catch (IOException ex) {
-			// FIXME not quite sure error reading requires file shall be silently logged only.
+			// FIXME EXCEPTIONS not quite sure error reading requires file shall be silently logged only.
 			HgInternals.getContext(hgRepo).getLog().error(getClass(), ex, null);
 		}
 	}
--- a/src/org/tmatesoft/hg/repo/HgDirstate.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgDirstate.java	Thu Mar 22 23:09:11 2012 +0100
@@ -87,15 +87,16 @@
 			return;
 		}
 		DataAccess da = repo.getDataAccess().create(dirstateFile);
-		if (da.isEmpty()) {
-			return;
-		}
-		// not sure linked is really needed here, just for ease of debug
-		normal = new LinkedHashMap<Path, Record>();
-		added = new LinkedHashMap<Path, Record>();
-		removed = new LinkedHashMap<Path, Record>();
-		merged = new LinkedHashMap<Path, Record>();
 		try {
+			if (da.isEmpty()) {
+				return;
+			}
+			// not sure linked is really needed here, just for ease of debug
+			normal = new LinkedHashMap<Path, Record>();
+			added = new LinkedHashMap<Path, Record>();
+			removed = new LinkedHashMap<Path, Record>();
+			merged = new LinkedHashMap<Path, Record>();
+			
 			parents = internalReadParents(da);
 			// hg init; hg up produces an empty repository where dirstate has parents (40 bytes) only
 			while (!da.isEmpty()) {
@@ -179,10 +180,10 @@
 			return new Pair<Nodeid,Nodeid>(NULL, NULL);
 		}
 		DataAccess da = repo.getDataAccess().create(dirstateFile);
-		if (da.isEmpty()) {
-			return new Pair<Nodeid,Nodeid>(NULL, NULL);
-		}
 		try {
+			if (da.isEmpty()) {
+				return new Pair<Nodeid,Nodeid>(NULL, NULL);
+			}
 			return internalReadParents(da);
 		} catch (IOException ex) {
 			throw new HgInvalidControlFileException("Error reading working copy parents from dirstate", ex, dirstateFile);
--- a/src/org/tmatesoft/hg/repo/HgManifest.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgManifest.java	Thu Mar 22 23:09:11 2012 +0100
@@ -624,7 +624,7 @@
 						changelog2manifest[u] = repo.getManifest().getRevisionIndex(manifest);
 					}
 				} catch (HgInvalidControlFileException ex) {
-					// FIXME need to propagate the error up to client  
+					// FIXME EXCEPTIONS need to propagate the error up to client  
 					repo.getContext().getLog().error(getClass(), ex, null);
 				}
 			}
--- a/src/org/tmatesoft/hg/repo/HgRepository.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgRepository.java	Thu Mar 22 23:09:11 2012 +0100
@@ -192,7 +192,7 @@
 						getContext().getLog().debug(getClass(), ex, null);
 					} catch (HgException ex) {
 						getContext().getLog().error(getClass(), ex, null);
-						// FIXME need to react
+						// FIXME EXCEPTIONS need to react
 					} catch (IOException ex) {
 						// UnsupportedEncodingException can't happen (UTF8)
 						// only from readGlobal. Need to reconsider exceptions thrown from there: