summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-10-31 01:35:52 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2021-10-31 13:02:04 +0100
commit83eddaf7fda22ca64e9c3852df67ccef0dacdaf5 (patch)
treeda257cd574e6b83c93bc277a5ea5cad742c0630d /org.eclipse.jgit.pgm/src
parent3444a3be8c8a567f944fd7b81838e615852d787a (diff)
downloadjgit-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.pgm/src')
-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
2 files changed, 3 insertions, 3 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);