diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-10-31 01:35:52 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2021-10-31 13:02:04 +0100 |
commit | 83eddaf7fda22ca64e9c3852df67ccef0dacdaf5 (patch) | |
tree | da257cd574e6b83c93bc277a5ea5cad742c0630d /org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java | |
parent | 3444a3be8c8a567f944fd7b81838e615852d787a (diff) | |
download | jgit-83eddaf7fda22ca64e9c3852df67ccef0dacdaf5.tar.gz jgit-83eddaf7fda22ca64e9c3852df67ccef0dacdaf5.zip |
Binary and CR-LF detection: lone CRs -> binary
C git considers not only files containing NUL bytes as binary but also
files containing lone CRs. Implement this also for JGit.
C git additionally counts printable vs. non-printable characters and
considers files that have non_printable_count > printable_count / 128
also as binary. This is not implemented because such counting probably
only makes sense if one looks at the full file or blob content. The
Auto[CR]LF* streams in JGit look only at the first few KiB of a stream
in order not to buffer too much.
For the C git implementation, see [1].
[1] https://github.com/git/git/blob/7e27bd589d/convert.c#L35
Bug: 576971
Change-Id: Ia169b59bdbf1477f32ee2014eeb8406f81d4b1ab
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java | 4 |
1 files changed, 2 insertions, 2 deletions
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; |