diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2017-10-17 15:17:34 +0200 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@google.com> | 2017-10-24 15:31:34 +0200 |
commit | f2e64cd895a6aa4f18ab3b876f13b7814fb98f04 (patch) | |
tree | b760f97fc0815817734efacfa180e7a49faadb0f /org.eclipse.jgit/src/org/eclipse/jgit/util | |
parent | ced658c445b9087c57eaa3d470f46afec4a4995f (diff) | |
download | jgit-f2e64cd895a6aa4f18ab3b876f13b7814fb98f04.tar.gz jgit-f2e64cd895a6aa4f18ab3b876f13b7814fb98f04.zip |
Throw BinaryBlobException from RawParseUtils#lineMap.
This makes detection of binaries exact for ResolveMerger and
DiffFormatter: they will classify files as binary regardless of where
the '\0' occurs in the text.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Id4342a199628d9406bfa04af1b023c27a47d4014
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java | 15 |
1 files changed, 4 insertions, 11 deletions
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 ad138bbf18..0d6a8d9612 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -63,6 +63,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jgit.annotations.Nullable; +import org.eclipse.jgit.errors.BinaryBlobException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; @@ -618,9 +619,6 @@ public final class RawParseUtils { * <p> * The last element (index <code>map.size()-1</code>) always contains * <code>end</code>. - * <p> - * If the data contains a '\0' anywhere, the whole region is considered binary - * and a LineMap corresponding to a single line is returned. * </p> * * @param buf @@ -631,10 +629,9 @@ public final class RawParseUtils { * @param end * 1 past the end of the content within <code>buf</code>. * @return a line map indexing the start position of each line. + * @throws BinaryBlobException if any '\0' is found. */ - public static final IntList lineMap(final byte[] buf, int ptr, int end) { - int start = ptr; - + public static final IntList lineMap(final byte[] buf, int ptr, int end) throws BinaryBlobException { // 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. @@ -647,11 +644,7 @@ public final class RawParseUtils { } if (buf[ptr] == '\0') { - // binary data. - map = new IntList(3); - map.add(Integer.MIN_VALUE); - map.add(start); - break; + throw new BinaryBlobException(); } foundLF = (buf[ptr] == '\n'); |