aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java87
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java120
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java29
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java19
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java10
13 files changed, 191 insertions, 100 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
index cd5d8f1bfe..a63387c24c 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
@@ -173,7 +173,7 @@ class DiffAlgorithms extends TextBuiltin {
} catch (LargeObjectException tooBig) {
continue;
}
- if (RawText.isBinary(raw0))
+ if (RawText.isBinary(raw0, raw0.length, true))
continue;
byte[] raw1;
@@ -183,7 +183,7 @@ class DiffAlgorithms extends TextBuiltin {
} catch (LargeObjectException tooBig) {
continue;
}
- if (RawText.isBinary(raw1))
+ if (RawText.isBinary(raw1, raw1.length, true))
continue;
RawText txt0 = new RawText(raw0);
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
index f777f277f4..1ca3034f4f 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
@@ -286,7 +286,7 @@ class TextHashFunctions extends TextBuiltin {
continue;
}
- if (RawText.isBinary(raw))
+ if (RawText.isBinary(raw, raw.length, true))
continue;
RawText txt = new RawText(raw);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
index 673aa1e9c0..f8a6632918 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
@@ -81,7 +81,8 @@ public class EolStreamTypeUtilTest {
testCheckout(TEXT_CRLF, AUTO_CRLF, "\n", "\r\n");
testCheckout(TEXT_CRLF, AUTO_CRLF, "\r\n", "\r\n");
- testCheckout(TEXT_CRLF, AUTO_CRLF, "\n\r", "\r\n\r");
+ testCheckout(TEXT_CRLF, null, "\n\r", "\r\n\r");
+ testCheckout(null, AUTO_CRLF, "\n\r", "\n\r"); // Lone CR
testCheckout(null, AUTO_CRLF, "\n\r\n", "\n\r\n");
testCheckout(TEXT_CRLF, null, "\n\r\n", "\r\n\r\n");
@@ -89,7 +90,8 @@ public class EolStreamTypeUtilTest {
testCheckout(TEXT_CRLF, AUTO_CRLF, "a\nb\n", "a\r\nb\r\n");
testCheckout(TEXT_CRLF, AUTO_CRLF, "a\rb\r", "a\rb\r");
- testCheckout(TEXT_CRLF, AUTO_CRLF, "a\n\rb\n\r", "a\r\n\rb\r\n\r");
+ testCheckout(TEXT_CRLF, null, "a\n\rb\n\r", "a\r\n\rb\r\n\r");
+ testCheckout(null, AUTO_CRLF, "a\n\rb\n\r", "a\n\rb\n\r"); // Lone CR
testCheckout(TEXT_CRLF, AUTO_CRLF, "a\r\nb\r\n", "a\r\nb\r\n");
}
@@ -199,7 +201,8 @@ public class EolStreamTypeUtilTest {
testCheckin(TEXT_LF, AUTO_LF, "\n\r", "\n\r");
testCheckin(TEXT_LF, AUTO_LF, "\n\r\n", "\n\n");
- testCheckin(TEXT_LF, AUTO_LF, "\r\n\r", "\n\r");
+ testCheckin(TEXT_LF, null, "\r\n\r", "\n\r");
+ testCheckin(null, AUTO_LF, "\r\n\r", "\r\n\r"); // Lone CR
testCheckin(TEXT_LF, AUTO_LF, "a\nb\n", "a\nb\n");
testCheckin(TEXT_LF, AUTO_LF, "a\rb\r", "a\rb\r");
@@ -214,14 +217,16 @@ public class EolStreamTypeUtilTest {
testCheckin(TEXT_CRLF, AUTO_CRLF, "\n", "\r\n");
testCheckin(TEXT_CRLF, AUTO_CRLF, "\r\n", "\r\n");
- testCheckin(TEXT_CRLF, AUTO_CRLF, "\n\r", "\r\n\r");
+ testCheckin(TEXT_CRLF, null, "\n\r", "\r\n\r");
+ testCheckin(null, AUTO_CRLF, "\n\r", "\n\r"); // Lone CR
testCheckin(TEXT_CRLF, AUTO_CRLF, "\n\r\n", "\r\n\r\n");
testCheckin(TEXT_CRLF, AUTO_CRLF, "\r\n\r", "\r\n\r");
testCheckin(TEXT_CRLF, AUTO_CRLF, "a\nb\n", "a\r\nb\r\n");
testCheckin(TEXT_CRLF, AUTO_CRLF, "a\rb\r", "a\rb\r");
- testCheckin(TEXT_CRLF, AUTO_CRLF, "a\n\rb\n\r", "a\r\n\rb\r\n\r");
+ testCheckin(TEXT_CRLF, null, "a\n\rb\n\r", "a\r\n\rb\r\n\r");
+ testCheckin(null, AUTO_CRLF, "a\n\rb\n\r", "a\n\rb\n\r"); // Lone CR
testCheckin(TEXT_CRLF, AUTO_CRLF, "a\r\nb\r\n", "a\r\nb\r\n");
}
@@ -257,47 +262,55 @@ public class EolStreamTypeUtilTest {
byte[] inputBytes = input.getBytes(UTF_8);
byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
- // test using input text and assuming it was declared TEXT
- try (InputStream in = EolStreamTypeUtil.wrapInputStream(
- new ByteArrayInputStream(inputBytes),
- streamTypeText)) {
- byte[] b = new byte[1024];
- int len = IO.readFully(in, b, 0);
- assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len));
+ if (streamTypeText != null) {
+ // test using input text and assuming it was declared TEXT
+ try (InputStream in = EolStreamTypeUtil.wrapInputStream(
+ new ByteArrayInputStream(inputBytes), streamTypeText)) {
+ byte[] b = new byte[1024];
+ int len = IO.readFully(in, b, 0);
+ assertArrayEquals(expectedConversionBytes,
+ Arrays.copyOf(b, len));
+ }
}
- // test using input text and assuming it was declared AUTO, using binary
- // detection
- try (InputStream in = EolStreamTypeUtil.wrapInputStream(
- new ByteArrayInputStream(inputBytes),
- streamTypeWithBinaryCheck)) {
- byte[] b = new byte[1024];
- int len = IO.readFully(in, b, 0);
- assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len));
+ if (streamTypeWithBinaryCheck != null) {
+ // test using input text and assuming it was declared AUTO, using
+ // binary detection
+ try (InputStream in = EolStreamTypeUtil.wrapInputStream(
+ new ByteArrayInputStream(inputBytes),
+ streamTypeWithBinaryCheck)) {
+ byte[] b = new byte[1024];
+ int len = IO.readFully(in, b, 0);
+ assertArrayEquals(expectedConversionBytes,
+ Arrays.copyOf(b, len));
+ }
}
-
// now pollute input text with some binary bytes
inputBytes = extendWithBinaryData(inputBytes);
expectedConversionBytes = extendWithBinaryData(expectedConversionBytes);
- // again, test using input text and assuming it was declared TEXT
- try (InputStream in = EolStreamTypeUtil.wrapInputStream(
- new ByteArrayInputStream(inputBytes), streamTypeText)) {
- byte[] b = new byte[1024];
- int len = IO.readFully(in, b, 0);
- assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len));
+ if (streamTypeText != null) {
+ // again, test using input text and assuming it was declared TEXT
+ try (InputStream in = EolStreamTypeUtil.wrapInputStream(
+ new ByteArrayInputStream(inputBytes), streamTypeText)) {
+ byte[] b = new byte[1024];
+ int len = IO.readFully(in, b, 0);
+ assertArrayEquals(expectedConversionBytes,
+ Arrays.copyOf(b, len));
+ }
}
- // again, test using input text and assuming it was declared AUTO, using
- // binary
- // detection
- try (InputStream in = EolStreamTypeUtil.wrapInputStream(
- new ByteArrayInputStream(inputBytes),
- streamTypeWithBinaryCheck)) {
- byte[] b = new byte[1024];
- int len = IO.readFully(in, b, 0);
- // expect no conversion
- assertArrayEquals(inputBytes, Arrays.copyOf(b, len));
+ if (streamTypeWithBinaryCheck != null) {
+ // again, test using input text and assuming it was declared AUTO,
+ // using binary detection
+ try (InputStream in = EolStreamTypeUtil.wrapInputStream(
+ new ByteArrayInputStream(inputBytes),
+ streamTypeWithBinaryCheck)) {
+ byte[] b = new byte[1024];
+ int len = IO.readFully(in, b, 0);
+ // expect no conversion
+ assertArrayEquals(inputBytes, Arrays.copyOf(b, len));
+ }
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java
index cd4e503390..94429924b0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java
@@ -30,10 +30,10 @@ public class AutoCRLFInputStreamTest {
assertNoCrLf("\r\n", "\n");
assertNoCrLf("\r\n", "\r\n");
assertNoCrLf("\r\r", "\r\r");
- assertNoCrLf("\r\n\r", "\n\r");
+ assertNoCrLf("\n\r", "\n\r"); // Lone CR
assertNoCrLf("\r\n\r\r", "\r\n\r\r");
assertNoCrLf("\r\n\r\n", "\r\n\r\n");
- assertNoCrLf("\r\n\r\n\r", "\n\r\n\r");
+ assertNoCrLf("\n\r\n\r", "\n\r\n\r"); // Lone CR
assertNoCrLf("\0\n", "\0\n");
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
index 150df08453..791727f734 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
@@ -32,7 +32,7 @@ public class AutoCRLFOutputStreamTest {
assertNoCrLf("\r\n", "\n");
assertNoCrLf("\r\n", "\r\n");
assertNoCrLf("\r\r", "\r\r");
- assertNoCrLf("\r\n\r", "\n\r");
+ assertNoCrLf("\n\r", "\n\r"); // Lone CR
assertNoCrLf("\r\n\r\r", "\r\n\r\r");
assertNoCrLf("\r\n\r\n", "\r\n\r\n");
assertNoCrLf("\n\r\n\r", "\n\r\n\r");
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
index 914fa5f6f7..aeb3c4563b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
@@ -246,18 +246,6 @@ public class RawText extends Sequence {
}
/**
- * Determine heuristically whether a byte array represents binary (as
- * opposed to text) content.
- *
- * @param raw
- * the raw file content.
- * @return true if raw is likely to be a binary file, false otherwise
- */
- public static boolean isBinary(byte[] raw) {
- return isBinary(raw, raw.length);
- }
-
- /**
* Obtains the buffer size to use for analyzing whether certain content is
* text or binary, or what line endings are used if it's text.
*
@@ -308,7 +296,19 @@ public class RawText extends Sequence {
break;
cnt += n;
}
- return isBinary(buffer, cnt);
+ return isBinary(buffer, cnt, cnt < buffer.length);
+ }
+
+ /**
+ * Determine heuristically whether a byte array represents binary (as
+ * opposed to text) content.
+ *
+ * @param raw
+ * the raw file content.
+ * @return true if raw is likely to be a binary file, false otherwise
+ */
+ public static boolean isBinary(byte[] raw) {
+ return isBinary(raw, raw.length);
}
/**
@@ -324,20 +324,64 @@ public class RawText extends Sequence {
* @return true if raw is likely to be a binary file, false otherwise
*/
public static boolean isBinary(byte[] raw, int length) {
- // Same heuristic as C Git (except for the buffer size)
+ return isBinary(raw, length, false);
+ }
+
+ /**
+ * Determine heuristically whether a byte array represents binary (as
+ * opposed to text) content.
+ *
+ * @param raw
+ * the raw file content.
+ * @param length
+ * number of bytes in {@code raw} to evaluate. This should be
+ * {@code raw.length} unless {@code raw} was over-allocated by
+ * the caller.
+ * @param complete
+ * whether {@code raw} contains the whole data
+ * @return true if raw is likely to be a binary file, false otherwise
+ * @since 6.0
+ */
+ public static boolean isBinary(byte[] raw, int length, boolean complete) {
+ // Similar heuristic as C Git. Differences:
+ // - limited buffer size; may be only the beginning of a large blob
+ // - no counting of printable vs. non-printable bytes < 0x20 and 0x7F
int maxLength = getBufferSize();
if (length > maxLength) {
length = maxLength;
}
+ byte last = 'x'; // Just something inconspicuous.
for (int ptr = 0; ptr < length; ptr++) {
- if (raw[ptr] == '\0') {
+ byte curr = raw[ptr];
+ if (isBinary(curr, last)) {
return true;
}
+ last = curr;
+ }
+ if (complete) {
+ // Buffer contains everything...
+ return last == '\r'; // ... so this must be a lone CR
}
return false;
}
/**
+ * Determines from the last two bytes read from a source if it looks like
+ * binary content.
+ *
+ * @param curr
+ * the last byte, read after {@code prev}
+ * @param prev
+ * the previous byte, read before {@code last}
+ * @return {@code true} if either byte is NUL, or if prev is CR and curr is
+ * not LF, {@code false} otherwise
+ * @since 6.0
+ */
+ public static boolean isBinary(byte curr, byte prev) {
+ return curr == '\0' || curr != '\n' && prev == '\r' || prev == '\0';
+ }
+
+ /**
* Determine heuristically whether a byte array represents text content
* using CR-LF as line separator.
*
@@ -394,13 +438,44 @@ public class RawText extends Sequence {
* @since 5.3
*/
public static boolean isCrLfText(byte[] raw, int length) {
+ return isCrLfText(raw, length, false);
+ }
+
+ /**
+ * Determine heuristically whether a byte array represents text content
+ * using CR-LF as line separator.
+ *
+ * @param raw
+ * the raw file content.
+ * @param length
+ * number of bytes in {@code raw} to evaluate.
+ * @return {@code true} if raw is likely to be CR-LF delimited text,
+ * {@code false} otherwise
+ * @param complete
+ * whether {@code raw} contains the whole data
+ * @since 6.0
+ */
+ public static boolean isCrLfText(byte[] raw, int length, boolean complete) {
boolean has_crlf = false;
- for (int ptr = 0; ptr < length - 1; ptr++) {
- if (raw[ptr] == '\0') {
- return false; // binary
- } else if (raw[ptr] == '\r' && raw[ptr + 1] == '\n') {
+ byte last = 'x'; // Just something inconspicuous
+ for (int ptr = 0; ptr < length; ptr++) {
+ byte curr = raw[ptr];
+ if (isBinary(curr, last)) {
+ return false;
+ }
+ if (curr == '\n' && last == '\r') {
has_crlf = true;
}
+ last = curr;
+ }
+ if (last == '\r') {
+ if (complete) {
+ // Lone CR: it's binary after all.
+ return false;
+ }
+ // Tough call. If the next byte, which we don't have, would be a
+ // '\n', it'd be a CR-LF text, otherwise it'd be binary. Just decide
+ // based on what we already scanned; it wasn't binary until now.
}
return has_crlf;
}
@@ -452,7 +527,7 @@ public class RawText extends Sequence {
int bufferSize = getBufferSize();
if (sz <= bufferSize) {
byte[] data = ldr.getCachedBytes(bufferSize);
- if (isBinary(data)) {
+ if (isBinary(data, data.length, true)) {
throw new BinaryBlobException();
}
return new RawText(data);
@@ -462,6 +537,7 @@ public class RawText extends Sequence {
try (InputStream stream = ldr.openStream()) {
int off = 0;
int left = head.length;
+ byte last = 'x'; // Just something inconspicuous
while (left > 0) {
int n = stream.read(head, off, left);
if (n < 0) {
@@ -470,9 +546,11 @@ public class RawText extends Sequence {
left -= n;
while (n > 0) {
- if (head[off] == '\0') {
+ byte curr = head[off];
+ if (isBinary(curr, last)) {
throw new BinaryBlobException();
}
+ last = curr;
off++;
n--;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
index 661369b86a..34581aefb5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
@@ -108,7 +108,8 @@ public class SimilarityIndex {
return RawText.isBinary(in1);
}
}
- return RawText.isBinary(obj.getCachedBytes());
+ byte[] raw = obj.getCachedBytes();
+ return RawText.isBinary(raw, raw.length, true);
}
void hash(ObjectLoader obj) throws MissingObjectException, IOException,
@@ -132,7 +133,7 @@ public class SimilarityIndex {
}
void hash(byte[] raw, int ptr, int end) throws TableFullException {
- final boolean text = !RawText.isBinary(raw);
+ final boolean text = !RawText.isBinary(raw, raw.length, true);
hashedCnt = 0;
while (ptr < end) {
int hash = 5381;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index 0b7c0a9e4b..50ce15ebc9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -1513,7 +1513,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
ObjectLoader loader = reader.open(blobId,
Constants.OBJ_BLOB);
try {
- return RawText.isCrLfText(loader.getCachedBytes());
+ byte[] raw = loader.getCachedBytes();
+ return RawText.isCrLfText(raw, raw.length, true);
} catch (LargeObjectException e) {
try (InputStream in = loader.openStream()) {
return RawText.isCrLfText(in);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
index 93bf847196..0e8e9b3d84 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
@@ -30,6 +30,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jgit.annotations.Nullable;
+import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.errors.BinaryBlobException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.PersonIdent;
@@ -679,36 +680,30 @@ public final class RawParseUtils {
* 1 past the end of the content within <code>buf</code>.
* @return a line map indicating the starting position of each line.
* @throws BinaryBlobException
- * if a NUL byte is found.
+ * if a NUL byte or a lone CR is found.
* @since 5.0
*/
public static final IntList lineMapOrBinary(byte[] buf, int ptr, int end)
throws BinaryBlobException {
- IntList map = lineMapOrNull(buf, ptr, end);
- if (map == null) {
- throw new BinaryBlobException();
- }
- return map;
- }
-
- @Nullable
- private static IntList lineMapOrNull(byte[] buf, int ptr, int end) {
// Experimentally derived from multiple source repositories
// the average number of bytes/line is 36. Its a rough guess
// to initially size our map close to the target.
IntList map = new IntList((end - ptr) / 36);
map.add(Integer.MIN_VALUE);
- boolean foundLF = true;
+ byte last = '\n'; // Must be \n to add the initial ptr
for (; ptr < end; ptr++) {
- if (foundLF) {
+ if (last == '\n') {
map.add(ptr);
}
-
- if (buf[ptr] == '\0') {
- return null;
+ byte curr = buf[ptr];
+ if (RawText.isBinary(curr, last)) {
+ throw new BinaryBlobException();
}
-
- foundLF = (buf[ptr] == '\n');
+ last = curr;
+ }
+ if (last == '\r') {
+ // Counts as binary
+ throw new BinaryBlobException();
}
map.add(end);
return map;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
index 1b03d097b6..cedb159827 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
@@ -123,7 +123,7 @@ public class AutoCRLFInputStream extends InputStream {
return false;
}
if (detectBinary) {
- isBinary = RawText.isBinary(buf, cnt);
+ isBinary = RawText.isBinary(buf, cnt, cnt < buf.length);
detectBinary = false;
}
ptr = 0;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
index 05e271febd..e638b2de3a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
@@ -122,22 +122,24 @@ public class AutoCRLFOutputStream extends OutputStream {
}
private int buffer(byte[] b, int off, int len) throws IOException {
- if (binbufcnt > binbuf.length)
+ if (binbufcnt > binbuf.length) {
return len;
+ }
int copy = Math.min(binbuf.length - binbufcnt, len);
System.arraycopy(b, off, binbuf, binbufcnt, copy);
binbufcnt += copy;
int remaining = len - copy;
- if (remaining > 0)
- decideMode();
+ if (remaining > 0) {
+ decideMode(false);
+ }
return remaining;
}
- private void decideMode() throws IOException {
+ private void decideMode(boolean complete) throws IOException {
if (detectBinary) {
- isBinary = RawText.isBinary(binbuf, binbufcnt);
+ isBinary = RawText.isBinary(binbuf, binbufcnt, complete);
if (!isBinary) {
- isBinary = RawText.isCrLfText(binbuf, binbufcnt);
+ isBinary = RawText.isCrLfText(binbuf, binbufcnt, complete);
}
detectBinary = false;
}
@@ -149,8 +151,9 @@ public class AutoCRLFOutputStream extends OutputStream {
/** {@inheritDoc} */
@Override
public void flush() throws IOException {
- if (binbufcnt <= binbuf.length)
- decideMode();
+ if (binbufcnt <= binbuf.length) {
+ decideMode(true);
+ }
buf = -1;
out.flush();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
index b6d1848b3a..7db882c074 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
@@ -262,14 +262,14 @@ public class AutoLFInputStream extends InputStream {
return false;
}
if (detectBinary) {
- isBinary = RawText.isBinary(buf, cnt);
+ isBinary = RawText.isBinary(buf, cnt, cnt < buf.length);
passAsIs = isBinary;
detectBinary = false;
if (isBinary && abortIfBinary) {
throw new IsBinaryException();
}
if (!passAsIs && forCheckout) {
- passAsIs = RawText.isCrLfText(buf, cnt);
+ passAsIs = RawText.isCrLfText(buf, cnt, cnt < buf.length);
}
}
ptr = 0;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
index e08a53f502..a0e9fb68c5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
@@ -146,16 +146,16 @@ public class AutoLFOutputStream extends OutputStream {
binbufcnt += copy;
int remaining = len - copy;
if (remaining > 0) {
- decideMode();
+ decideMode(false);
}
return remaining;
}
- private void decideMode() throws IOException {
+ private void decideMode(boolean complete) throws IOException {
if (detectBinary) {
- isBinary = RawText.isBinary(binbuf, binbufcnt);
+ isBinary = RawText.isBinary(binbuf, binbufcnt, complete);
if (!isBinary) {
- isBinary = RawText.isCrLfText(binbuf, binbufcnt);
+ isBinary = RawText.isCrLfText(binbuf, binbufcnt, complete);
}
detectBinary = false;
}
@@ -168,7 +168,7 @@ public class AutoLFOutputStream extends OutputStream {
@Override
public void flush() throws IOException {
if (binbufcnt <= binbuf.length) {
- decideMode();
+ decideMode(true);
}
out.flush();
}