aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-09-29 15:45:12 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-09-30 16:04:25 +0900
commit4316e1c3a9e36e386da8d8d6c663477178a4b663 (patch)
tree29ff4329ca232724be29a2c7996efce6169fdf57 /org.eclipse.jgit.pgm
parent74789e77866d8aac7285149472c13a417b4aaa69 (diff)
downloadjgit-4316e1c3a9e36e386da8d8d6c663477178a4b663.tar.gz
jgit-4316e1c3a9e36e386da8d8d6c663477178a4b663.zip
TextBuiltin: Default to UTF-8 when i18n.logOutputEncoding is not set
Change-Id: I69d82086c052b7ba601e0daab133573ec37c25cf Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java50
1 files changed, 25 insertions, 25 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
index 7e5b5451b6..b84a0fd7d4 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.pgm;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.eclipse.jgit.lib.Constants.R_REMOTES;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
@@ -56,6 +57,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.ResourceBundle;
@@ -177,33 +179,31 @@ public abstract class TextBuiltin {
* {@code repository} is null.
*/
protected void init(Repository repository, String gitDir) {
- try {
- final String outputEncoding = repository != null ? repository
- .getConfig().getString("i18n", null, "logOutputEncoding") : null; //$NON-NLS-1$ //$NON-NLS-2$
- if (ins == null)
- ins = new FileInputStream(FileDescriptor.in);
- if (outs == null)
- outs = new FileOutputStream(FileDescriptor.out);
- if (errs == null)
- errs = new FileOutputStream(FileDescriptor.err);
- BufferedWriter outbufw;
- if (outputEncoding != null)
- outbufw = new BufferedWriter(new OutputStreamWriter(outs,
- outputEncoding));
- else
- outbufw = new BufferedWriter(new OutputStreamWriter(outs));
- outw = new ThrowingPrintWriter(outbufw);
- BufferedWriter errbufw;
- if (outputEncoding != null)
- errbufw = new BufferedWriter(new OutputStreamWriter(errs,
- outputEncoding));
- else
- errbufw = new BufferedWriter(new OutputStreamWriter(errs));
- errw = new ThrowingPrintWriter(errbufw);
- } catch (IOException e) {
- throw die(CLIText.get().cannotCreateOutputStream);
+ Charset charset = UTF_8;
+ if (repository != null) {
+ String logOutputEncoding = repository.getConfig().getString("i18n", //$NON-NLS-1$
+ null,
+ "logOutputEncoding");//$NON-NLS-1$
+ if (logOutputEncoding != null) {
+ try {
+ charset = Charset.forName(logOutputEncoding);
+ } catch (IllegalArgumentException e) {
+ throw die(CLIText.get().cannotCreateOutputStream);
+ }
+ }
}
+ if (ins == null)
+ ins = new FileInputStream(FileDescriptor.in);
+ if (outs == null)
+ outs = new FileOutputStream(FileDescriptor.out);
+ if (errs == null)
+ errs = new FileOutputStream(FileDescriptor.err);
+ outw = new ThrowingPrintWriter(new BufferedWriter(
+ new OutputStreamWriter(outs, charset)));
+ errw = new ThrowingPrintWriter(new BufferedWriter(
+ new OutputStreamWriter(errs, charset)));
+
if (repository != null && repository.getDirectory() != null) {
db = repository;
gitdir = repository.getDirectory().getAbsolutePath();