summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2016-11-08 13:42:34 +0100
committerChristian Halstrick <christian.halstrick@sap.com>2016-11-24 17:26:56 +0100
commit1572964ecb24137a112c22555ae7ab3d16a3ea12 (patch)
tree30132031cf1884bed9c2712517b037c1e844b0d5 /org.eclipse.jgit.lfs
parentfe329f5db4328a58e2cd1c7d1cec6f2676412745 (diff)
downloadjgit-1572964ecb24137a112c22555ae7ab3d16a3ea12.tar.gz
jgit-1572964ecb24137a112c22555ae7ab3d16a3ea12.zip
Fix encoding of LFSPointer files
LFS pointer files have to be UTF-8 with \n as line ending character. That is described in [1]. Fix JGit to follow this rules. [1] https://github.com/github/git-lfs/blob/master/docs/spec.md Bug: 507120 Change-Id: Ib6bd13f1cc17f1a3de125249b4f250b7b0692396
Diffstat (limited to 'org.eclipse.jgit.lfs')
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
index c0cf2337be..bbea53567f 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
@@ -48,6 +48,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
@@ -109,13 +112,18 @@ public class LfsPointer {
* written
*/
public void encode(OutputStream out) {
- try (PrintStream ps = new PrintStream(out)) {
+ try (PrintStream ps = new PrintStream(out, false,
+ StandardCharsets.UTF_8.name())) {
ps.print("version "); //$NON-NLS-1$
- ps.println(VERSION);
+ ps.print(VERSION + "\n"); //$NON-NLS-1$
ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$
- ps.println(oid.name());
+ ps.print(oid.name() + "\n"); //$NON-NLS-1$
ps.print("size "); //$NON-NLS-1$
- ps.println(size);
+ ps.print(size + "\n"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ // should not happen, we are using a standard charset
+ throw new UnsupportedCharsetException(
+ StandardCharsets.UTF_8.name());
}
}
@@ -137,7 +145,7 @@ public class LfsPointer {
long sz = -1;
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(in))) {
+ new InputStreamReader(in, StandardCharsets.UTF_8.name()))) {
for (String s = br.readLine(); s != null; s = br.readLine()) {
if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$
continue;