diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2017-08-01 10:18:48 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-08-01 10:18:48 -0400 |
commit | 4085646f6d51d1331c04ca74f82a6f805c414962 (patch) | |
tree | 09bcfc64f280cb714d84f08eb8a8dbb8f34f4710 /org.eclipse.jgit/src | |
parent | 8c6a9a286e18468a87d47a061a8510a4d634c4bc (diff) | |
parent | a551b64694c24fff58014ae5ca298b47539cf96d (diff) | |
download | jgit-4085646f6d51d1331c04ca74f82a6f805c414962.tar.gz jgit-4085646f6d51d1331c04ca74f82a6f805c414962.zip |
Merge changes I424295df,Ib003f7c8
* changes:
Treat RawText of binary data as file with one single line.
Trim boilerplate in RawParseUtils_LineMapTest.
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java | 29 |
1 files changed, 24 insertions, 5 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 86777b9cdc..ad138bbf18 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -618,6 +618,10 @@ 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 * buffer to scan. @@ -629,14 +633,29 @@ public final class RawParseUtils { * @return a line map indexing the start position of each line. */ public static final IntList lineMap(final byte[] buf, int ptr, int end) { + int start = ptr; + // 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. - // - final IntList map = new IntList((end - ptr) / 36); - map.fillTo(1, Integer.MIN_VALUE); - for (; ptr < end; ptr = nextLF(buf, ptr)) - map.add(ptr); + IntList map = new IntList((end - ptr) / 36); + map.add(Integer.MIN_VALUE); + boolean foundLF = true; + for (; ptr < end; ptr++) { + if (foundLF) { + map.add(ptr); + } + + if (buf[ptr] == '\0') { + // binary data. + map = new IntList(3); + map.add(Integer.MIN_VALUE); + map.add(start); + break; + } + + foundLF = (buf[ptr] == '\n'); + } map.add(end); return map; } |