Browse Source

TextBuiltin#init: Factor out a method to get the log output encoding

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

33
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java

@ -172,29 +172,40 @@ public abstract class TextBuiltin {
} }
/** /**
* Initialize the command to work with a repository. * Get the log output encoding specified in the repository's
* {@code i18n.logOutputEncoding} configuration.
* *
* @param repository * @param repository
* the opened repository that the command should work on. * the repository.
* @param gitDir * @return Charset corresponding to {@code i18n.logOutputEncoding}, or
* value of the {@code --git-dir} command line option, if * {@code UTF_8}.
* {@code repository} is null.
*/ */
protected void init(Repository repository, String gitDir) { private Charset getLogOutputEncodingCharset(Repository repository) {
Charset charset = UTF_8;
if (repository != null) { if (repository != null) {
String logOutputEncoding = repository.getConfig().getString( String logOutputEncoding = repository.getConfig().getString(
CONFIG_SECTION_I18N, CONFIG_SECTION_I18N, null, CONFIG_KEY_LOG_OUTPUT_ENCODING);
null,
CONFIG_KEY_LOG_OUTPUT_ENCODING);
if (logOutputEncoding != null) { if (logOutputEncoding != null) {
try { try {
charset = Charset.forName(logOutputEncoding); return Charset.forName(logOutputEncoding);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw die(CLIText.get().cannotCreateOutputStream); throw die(CLIText.get().cannotCreateOutputStream);
} }
} }
} }
return UTF_8;
}
/**
* Initialize the command to work with a repository.
*
* @param repository
* the opened repository that the command should work on.
* @param gitDir
* value of the {@code --git-dir} command line option, if
* {@code repository} is null.
*/
protected void init(Repository repository, String gitDir) {
Charset charset = getLogOutputEncodingCharset(repository);
if (ins == null) if (ins == null)
ins = new FileInputStream(FileDescriptor.in); ins = new FileInputStream(FileDescriptor.in);

Loading…
Cancel
Save