# HG changeset patch # User Artem Tikhomirov # Date 1358960593 -3600 # Node ID 95c2f43008bdba49d699a0b95aa132543edb7e36 # Parent 0f6fa88e21622ca86ff51f9ffe9d466df5e6f354 Throw specific exception when checksum calculation fails diff -r 0f6fa88e2162 -r 95c2f43008bd src/org/tmatesoft/hg/core/HgCloneCommand.java --- a/src/org/tmatesoft/hg/core/HgCloneCommand.java Wed Jan 23 17:46:12 2013 +0100 +++ b/src/org/tmatesoft/hg/core/HgCloneCommand.java Wed Jan 23 18:03:13 2013 +0100 @@ -298,8 +298,8 @@ byte[] calculated = dh.sha1(p1, p2, content).asBinary(); final Nodeid node = ge.node(); if (!node.equalsTo(calculated)) { - // TODO post-1.0 custom exception ChecksumCalculationFailed? - throw new HgInvalidStateException(String.format("Checksum failed: expected %s, calculated %s. File %s", node, calculated, filename)); + String m = String.format("Checksum failed: expected %s, calculated %s. File %s", node, calculated, filename); + throw new HgRevisionIntegrityException(m, null, new File(hgDir, filename)); } revlogHeader.nodeid(node); if (collectChangelogIndexes) { @@ -348,7 +348,7 @@ prevRevContent = new ByteArrayDataAccess(content); } catch (IOException ex) { String m = String.format("Failed to write revision %s of file %s", ge.node().shortNotation(), filename); - throw new HgInvalidControlFileException(m, ex, new File(filename)); + throw new HgInvalidControlFileException(m, ex, new File(hgDir, filename)); } return cancelException == null; } diff -r 0f6fa88e2162 -r 95c2f43008bd src/org/tmatesoft/hg/core/HgRevisionIntegrityException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/tmatesoft/hg/core/HgRevisionIntegrityException.java Wed Jan 23 18:03:13 2013 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@hg4j.com + */ +package org.tmatesoft.hg.core; + +import java.io.File; + +import org.tmatesoft.hg.repo.HgInvalidControlFileException; +import org.tmatesoft.hg.repo.HgInvalidFileException; + +/** + * Thrown to indicate integrity issues with a revision, namely, when digest (SHA1) over revision data + * doesn't match revision id. + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +@SuppressWarnings("serial") +public class HgRevisionIntegrityException extends HgInvalidControlFileException { + + /** + * See {@link HgInvalidFileException#HgInvalidFileException(String, Throwable, File)} for parameters description. + */ + public HgRevisionIntegrityException(String message, Throwable th, File file) { + super(message, th, file); + } + +} diff -r 0f6fa88e2162 -r 95c2f43008bd src/org/tmatesoft/hg/repo/HgInvalidFileException.java --- a/src/org/tmatesoft/hg/repo/HgInvalidFileException.java Wed Jan 23 17:46:12 2013 +0100 +++ b/src/org/tmatesoft/hg/repo/HgInvalidFileException.java Wed Jan 23 18:03:13 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012 TMate Software Ltd + * Copyright (c) 2011-2013 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +43,12 @@ super(message, th); } + /** + * + * @param message description of the trouble, may (although should not) be null + * @param th cause, optional + * @param file where the trouble is, may be null, can be altered later with {@link #setFile(File)} + */ public HgInvalidFileException(String message, Throwable th, File file) { super(message, th); details.setFile(file); // allows null