# HG changeset patch # User Artem Tikhomirov # Date 1332454151 -3600 # Node ID fdd7d756dea0aa95152536db03ddf4b7759e2d31 # Parent 6c22bdc0bdfdbaa9d60ffe817dfa3f4bd9a0f56b Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/internal/DataAccess.java --- 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(); } diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/internal/FilterDataAccess.java --- 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; } diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/internal/InflaterDataAccess.java --- 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 diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/internal/Internals.java --- 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); } } diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/repo/HgDirstate.java --- 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(); - added = new LinkedHashMap(); - removed = new LinkedHashMap(); - merged = new LinkedHashMap(); try { + if (da.isEmpty()) { + return; + } + // not sure linked is really needed here, just for ease of debug + normal = new LinkedHashMap(); + added = new LinkedHashMap(); + removed = new LinkedHashMap(); + merged = new LinkedHashMap(); + 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(NULL, NULL); } DataAccess da = repo.getDataAccess().create(dirstateFile); - if (da.isEmpty()) { - return new Pair(NULL, NULL); - } try { + if (da.isEmpty()) { + return new Pair(NULL, NULL); + } return internalReadParents(da); } catch (IOException ex) { throw new HgInvalidControlFileException("Error reading working copy parents from dirstate", ex, dirstateFile); diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/repo/HgManifest.java --- 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); } } diff -r 6c22bdc0bdfd -r fdd7d756dea0 src/org/tmatesoft/hg/repo/HgRepository.java --- 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: