Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/KeywordFilter.java @ 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 | b3c16d1aede0 |
children | a62079bc422b |
comparison
equal
deleted
inserted
replaced
709:497e697636fc | 710:cf200271439a |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011-2012 TMate Software Ltd | 2 * Copyright (c) 2011-2013 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
82 * @return buffer ready to be read and original buffer's position modified to reflect consumed bytes. IOW, if source buffer | 82 * @return buffer ready to be read and original buffer's position modified to reflect consumed bytes. IOW, if source buffer |
83 * on return has remaining bytes, they are assumed not-read (not processed) and next chunk passed to filter is supposed to | 83 * on return has remaining bytes, they are assumed not-read (not processed) and next chunk passed to filter is supposed to |
84 * start with them | 84 * start with them |
85 */ | 85 */ |
86 public ByteBuffer filter(ByteBuffer src) { | 86 public ByteBuffer filter(ByteBuffer src) { |
87 if (src.capacity() < minBufferLen) { | 87 int keywordStart = indexOf(src, '$', src.position(), false); |
88 if (keywordStart != -1 && src.capacity() < minBufferLen) { | |
89 // FIXME this check is unlucky when small files are read for status 'areTheSame' check - small buffer is allocated. | |
90 // the check for keywordStart('$') is a temp solution to minimize the chances to get this exception. | |
91 // Complete solution requires complete rewriting of this method to respect cases when keywords are split between buffers. | |
92 // With 'honest' partial kw handling, need for this check would be gone. | |
88 throw new IllegalStateException(String.format("Need buffer of at least %d bytes to ensure filter won't hang", minBufferLen)); | 93 throw new IllegalStateException(String.format("Need buffer of at least %d bytes to ensure filter won't hang", minBufferLen)); |
89 } | 94 } |
90 ByteBuffer rv = null; | 95 ByteBuffer rv = null; |
91 int keywordStart = -1; | |
92 int x = src.position(); | 96 int x = src.position(); |
93 int copyFrom = x; // needs to be updated each time we copy a slice, but not each time we modify source index (x) | 97 int copyFrom = x; // needs to be updated each time we copy a slice, but not each time we modify source index (x) |
94 while (x < src.limit()) { | 98 while (x < src.limit()) { |
95 if (keywordStart == -1) { | 99 if (keywordStart == -1) { |
96 int i = indexOf(src, '$', x, false); | 100 int i = indexOf(src, '$', x, false); |