Mercurial > jhg
diff src/org/tmatesoft/hg/repo/HgDataFile.java @ 323:4c7e3ba67213
Exception when analyzing metadata of an empty renamed file
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 30 Sep 2011 08:44:48 +0200 |
parents | d68dcb3b5f49 |
children | a674b8590362 |
line wrap: on
line diff
--- 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;