aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2022-06-08 07:22:04 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2022-06-17 09:44:14 +0200
commit87391ccee97dd2d51871838f7b065bf6cf9a07a8 (patch)
tree96d1054d0096e4277d8f70517179a6dd159945a9 /org.eclipse.jgit.pgm/src/org
parent6674abb167cec7d3bb455ad99fb41f9b0f823fe7 (diff)
downloadjgit-87391ccee97dd2d51871838f7b065bf6cf9a07a8.tar.gz
jgit-87391ccee97dd2d51871838f7b065bf6cf9a07a8.zip
Fix DefaultCharset bug pattern flagged by error prone
See more details in: [1]. [1] https://errorprone.info/bugpattern/DefaultCharset Change-Id: I3de0be57a2d74490a5b4e66801e9767b38f13bf9
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java9
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java14
2 files changed, 18 insertions, 5 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java
index 3113eeb640..87c71795ec 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTool.java
@@ -19,6 +19,7 @@ import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
@@ -244,11 +245,15 @@ class DiffTool extends TextBuiltin {
// TODO: check how to return the exit-code of the tool
// to jgit / java runtime ?
// int rc =...
+ Charset defaultCharset = SystemReader.getInstance()
+ .getDefaultCharset();
outw.println(
- new String(result.getStdout().toByteArray()));
+ new String(result.getStdout().toByteArray(),
+ defaultCharset));
outw.flush();
errw.println(
- new String(result.getStderr().toByteArray()));
+ new String(result.getStderr().toByteArray(),
+ defaultCharset));
errw.flush();
}
} catch (ToolException e) {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java
index 2a411b81fe..a382fab757 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/MergeTool.java
@@ -18,6 +18,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
@@ -55,6 +56,7 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeOptions;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.FS.ExecutionResult;
+import org.eclipse.jgit.util.SystemReader;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.RestOfArgumentsHandler;
@@ -108,7 +110,9 @@ class MergeTool extends TextBuiltin {
protected void init(Repository repository, String gitDir) {
super.init(repository, gitDir);
mergeTools = new MergeTools(repository);
- inputReader = new BufferedReader(new InputStreamReader(ins));
+ inputReader = new BufferedReader(
+ new InputStreamReader(ins,
+ SystemReader.getInstance().getDefaultCharset()));
}
enum MergeResult {
@@ -285,9 +289,13 @@ class MergeTool extends TextBuiltin {
gui, this::promptForLaunch, this::informUserNoTool);
if (optionalResult.isPresent()) {
ExecutionResult result = optionalResult.get();
- outw.println(new String(result.getStdout().toByteArray()));
+ Charset defaultCharset = SystemReader.getInstance()
+ .getDefaultCharset();
+ outw.println(new String(result.getStdout().toByteArray(),
+ defaultCharset));
outw.flush();
- errw.println(new String(result.getStderr().toByteArray()));
+ errw.println(new String(result.getStderr().toByteArray(),
+ defaultCharset));
errw.flush();
} else {
return MergeResult.ABORTED;