*/\r
package com.gitblit.utils;\r
\r
+import static org.eclipse.jgit.lib.Constants.encode;\r
+\r
import java.io.ByteArrayOutputStream;\r
import java.io.IOException;\r
import java.io.OutputStream;\r
\r
import org.eclipse.jgit.diff.RawText;\r
+import org.eclipse.jgit.util.RawParseUtils;\r
\r
/**\r
* Generates an html snippet of a diff in Gitblit's style.\r
break;\r
}\r
os.write(prefix);\r
- ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
- text.writeLine(bos, cur);\r
- String line = bos.toString();\r
+ String line = text.getString(cur);\r
line = StringUtils.escapeForHtml(line, false);\r
- os.write(line.getBytes());\r
+ os.write(encode(line));\r
switch (prefix) {\r
case '+':\r
case '-':\r
*/\r
@Override\r
public String getHtml() {\r
- String html = os.toString();\r
+ ByteArrayOutputStream bos = (ByteArrayOutputStream) os;\r
+ String html = RawParseUtils.decode(bos.toByteArray());\r
String[] lines = html.split("\n");\r
StringBuilder sb = new StringBuilder();\r
boolean inFile = false;\r
*/\r
package com.gitblit.utils;\r
\r
+import static org.eclipse.jgit.lib.Constants.encode;\r
import static org.eclipse.jgit.lib.Constants.encodeASCII;\r
\r
import java.io.ByteArrayOutputStream;\r
\r
import org.eclipse.jgit.diff.DiffFormatter;\r
import org.eclipse.jgit.diff.RawText;\r
+import org.eclipse.jgit.util.RawParseUtils;\r
\r
/**\r
* Returns an html snippet of the diff in the standard Gitweb style.\r
break;\r
}\r
os.write(prefix);\r
- ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
- text.writeLine(bos, cur);\r
- String line = bos.toString();\r
+ String line = text.getString(cur);\r
line = StringUtils.escapeForHtml(line, false);\r
- os.write(line.getBytes());\r
+ os.write(encode(line));\r
switch (prefix) {\r
case '+':\r
case '-':\r
* @return\r
*/\r
public String getHtml() {\r
- String html = os.toString();\r
+ ByteArrayOutputStream bos = (ByteArrayOutputStream) os;\r
+ String html = RawParseUtils.decode(bos.toByteArray());\r
String[] lines = html.split("\n");\r
StringBuilder sb = new StringBuilder();\r
sb.append("<div class=\"diff\">");\r
\r
import org.eclipse.jgit.api.CloneCommand;\r
import org.eclipse.jgit.api.Git;\r
+import org.eclipse.jgit.lib.Constants;\r
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;\r
import org.eclipse.jgit.util.FileUtils;\r
import org.junit.AfterClass;\r
public void testAnonymousPush() throws Exception {\r
Git git = Git.open(ticgitFolder);\r
File file = new File(ticgitFolder, "TODO");\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);\r
BufferedWriter w = new BufferedWriter(os);\r
- w.write("// " + new Date().toString() + "\n");\r
+ w.write("// hellol中文 " + new Date().toString() + "\n");\r
w.close();\r
git.add().addFilepattern(file.getName()).call();\r
git.commit().setMessage("test commit").call();\r
\r
Git git = Git.open(jgitFolder);\r
File file = new File(jgitFolder, "TODO");\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);\r
BufferedWriter w = new BufferedWriter(os);\r
w.write("// " + new Date().toString() + "\n");\r
w.close();\r
\r
Git git = Git.open(jgit2Folder);\r
File file = new File(jgit2Folder, "NONBARE");\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);\r
BufferedWriter w = new BufferedWriter(os);\r
w.write("// " + new Date().toString() + "\n");\r
w.close();\r