Browse Source

TextBuiltin: Default to UTF-8 when i18n.logOutputEncoding is not set

Change-Id: I69d82086c052b7ba601e0daab133573ec37c25cf
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.2
David Pursehouse 6 years ago
parent
commit
4316e1c3a9
  1. 50
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java

50
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();

Loading…
Cancel
Save