diff 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
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()) {