TextBuiltin#init: Factor out a method to get the log output encoding
Change-Id: I87c5774722bd36ea6fe18c4b7ce22342578fa290 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
a5c0a8dfa5
commit
7d19b18c7d
|
@ -171,6 +171,30 @@ public void initRaw(final Repository repository, final String gitDir,
|
||||||
init(repository, gitDir);
|
init(repository, gitDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the log output encoding specified in the repository's
|
||||||
|
* {@code i18n.logOutputEncoding} configuration.
|
||||||
|
*
|
||||||
|
* @param repository
|
||||||
|
* the repository.
|
||||||
|
* @return Charset corresponding to {@code i18n.logOutputEncoding}, or
|
||||||
|
* {@code UTF_8}.
|
||||||
|
*/
|
||||||
|
private Charset getLogOutputEncodingCharset(Repository repository) {
|
||||||
|
if (repository != null) {
|
||||||
|
String logOutputEncoding = repository.getConfig().getString(
|
||||||
|
CONFIG_SECTION_I18N, null, CONFIG_KEY_LOG_OUTPUT_ENCODING);
|
||||||
|
if (logOutputEncoding != null) {
|
||||||
|
try {
|
||||||
|
return Charset.forName(logOutputEncoding);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw die(CLIText.get().cannotCreateOutputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UTF_8;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the command to work with a repository.
|
* Initialize the command to work with a repository.
|
||||||
*
|
*
|
||||||
|
@ -181,20 +205,7 @@ public void initRaw(final Repository repository, final String gitDir,
|
||||||
* {@code repository} is null.
|
* {@code repository} is null.
|
||||||
*/
|
*/
|
||||||
protected void init(Repository repository, String gitDir) {
|
protected void init(Repository repository, String gitDir) {
|
||||||
Charset charset = UTF_8;
|
Charset charset = getLogOutputEncodingCharset(repository);
|
||||||
if (repository != null) {
|
|
||||||
String logOutputEncoding = repository.getConfig().getString(
|
|
||||||
CONFIG_SECTION_I18N,
|
|
||||||
null,
|
|
||||||
CONFIG_KEY_LOG_OUTPUT_ENCODING);
|
|
||||||
if (logOutputEncoding != null) {
|
|
||||||
try {
|
|
||||||
charset = Charset.forName(logOutputEncoding);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
throw die(CLIText.get().cannotCreateOutputStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ins == null)
|
if (ins == null)
|
||||||
ins = new FileInputStream(FileDescriptor.in);
|
ins = new FileInputStream(FileDescriptor.in);
|
||||||
|
|
Loading…
Reference in New Issue