Mercurial > hg4j
changeset 710:cf200271439a
KeywordFilter: 'IllegalStateException: need buffer of at least...' during status op for a small file
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 07 Oct 2013 01:56:05 +0200 |
parents | 497e697636fc |
children | a62079bc422b |
files | src/org/tmatesoft/hg/internal/KeywordFilter.java src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java |
diffstat | 2 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/KeywordFilter.java Wed Aug 21 16:23:27 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/KeywordFilter.java Mon Oct 07 01:56:05 2013 +0200 @@ -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 @@ -84,11 +84,15 @@ * start with them */ public ByteBuffer filter(ByteBuffer src) { - if (src.capacity() < minBufferLen) { + int keywordStart = indexOf(src, '$', src.position(), false); + if (keywordStart != -1 && src.capacity() < minBufferLen) { + // FIXME this check is unlucky when small files are read for status 'areTheSame' check - small buffer is allocated. + // the check for keywordStart('$') is a temp solution to minimize the chances to get this exception. + // Complete solution requires complete rewriting of this method to respect cases when keywords are split between buffers. + // With 'honest' partial kw handling, need for this check would be gone. throw new IllegalStateException(String.format("Need buffer of at least %d bytes to ensure filter won't hang", minBufferLen)); } ByteBuffer rv = null; - int keywordStart = -1; int x = src.position(); int copyFrom = x; // needs to be updated each time we copy a slice, but not each time we modify source index (x) while (x < src.limit()) {
--- a/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Wed Aug 21 16:23:27 2013 +0200 +++ b/src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java Mon Oct 07 01:56:05 2013 +0200 @@ -564,7 +564,8 @@ Check check = new Check(); try { is = f.newInputChannel(); - ByteBuffer fb = ByteBuffer.allocate(min(1 + data.length * 2 /*to fit couple of lines appended; never zero*/, 8192)); +// ByteBuffer fb = ByteBuffer.allocate(min(1 + data.length * 2 /*to fit couple of lines appended; never zero*/, 8192)); + ByteBuffer fb = ByteBuffer.allocate(8192); // FIXME temp fix to ensure big enough buffer for KeywordFilter FilterByteChannel filters = new FilterByteChannel(check, repo.getFiltersFromWorkingDirToRepo(p)); Preview preview = Adaptable.Factory.getAdapter(filters, Preview.class, null); if (preview != null) {