# HG changeset patch # User Artem Tikhomirov # Date 1381103765 -7200 # Node ID cf200271439a7ec256151b30bc4360b21db3542e # Parent 497e697636fccf6678b54532d44f7a0c03406f73 KeywordFilter: 'IllegalStateException: need buffer of at least...' during status op for a small file diff -r 497e697636fc -r cf200271439a src/org/tmatesoft/hg/internal/KeywordFilter.java --- 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()) { diff -r 497e697636fc -r cf200271439a src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java --- 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) {