Mercurial > jhg
changeset 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 | 283b294d1079 |
files | src/org/tmatesoft/hg/repo/HgDataFile.java src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java |
diffstat | 2 files changed, 8 insertions(+), 4 deletions(-) [+] |
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;
--- 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());