# HG changeset patch # User Artem Tikhomirov # Date 1317365088 -7200 # Node ID 4c7e3ba672132f4c544312fa8d401bb9f1b2e614 # Parent d68dcb3b5f4903816807101d75631ee77099060d Exception when analyzing metadata of an empty renamed file diff -r d68dcb3b5f49 -r 4c7e3ba67213 src/org/tmatesoft/hg/repo/HgDataFile.java --- a/src/org/tmatesoft/hg/repo/HgDataFile.java Fri Sep 30 08:00:04 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgDataFile.java Fri Sep 30 08:44:48 2011 +0200 @@ -221,7 +221,7 @@ } catch (HgDataStreamException ex) { throw ex; } catch (IOException ex) { - throw new HgDataStreamException(getPath(), ex); + throw new HgDataStreamException(getPath(), ex).setRevisionNumber(revision); } catch (HgException ex) { // shall not happen, unless we changed ContentPipe or its subclass throw new HgDataStreamException(getPath(), ex.getClass().getName(), ex); @@ -439,8 +439,6 @@ }); } catch (CancelledException ex) { // it's ok, we did that - } catch (Exception ex) { - throw new HgDataStreamException(getPath(), "Can't initialize metadata", ex).setRevisionNumber(localRev); } } @@ -573,12 +571,15 @@ ByteArrayOutputStream bos = new ByteArrayOutputStream(); String key = null, value = null; boolean byteOne = false; + boolean metadataIsComplete = false; for (int i = 2; i < daLength; i++) { byte b = data.readByte(); if (b == '\n') { if (byteOne) { // i.e. \n follows 1 lastEntryStart = i+1; + metadataIsComplete = true; // XXX is it possible to have here incomplete key/value (i.e. if last pair didn't end with \n) + // if yes, need to set metadataIsComplete to true in that case as well break; } if (key == null || lastColon == -1 || i <= lastColon) { @@ -610,7 +611,9 @@ bos.write(b); } } - if (data.isEmpty() || !byteOne) { + // data.isEmpty is not reliable, renamed files of size==0 keep only metadata + if (!metadataIsComplete) { + // XXX perhaps, worth a testcase (empty file, renamed, read or ask ifCopy throw new HgDataStreamException(fname, "Metadata is not closed properly", null); } return lastEntryStart; diff -r d68dcb3b5f49 -r 4c7e3ba67213 src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java --- a/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Fri Sep 30 08:00:04 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Fri Sep 30 08:44:48 2011 +0200 @@ -394,6 +394,7 @@ } catch (CancelledException ex) { // silently ignore - can't happen, ByteArrayChannel is not cancellable } catch (HgException ex) { + repo.getContext().getLog().warn(getClass(), ex, null); ioFailed = true; } return !ioFailed && areTheSame(f, bac.toArray(), dataFile.getPath());