aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-09-30 17:19:39 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-09-30 17:19:39 +0900
commit7d19b18c7d9afa33032b83ca196c1dab25d02f91 (patch)
tree4ea9be4e1cf1cff54ade2bdac69e2bcf384c139e /org.eclipse.jgit.pgm/src
parenta5c0a8dfa57a66bdbeb65138dd565df3154ea9bd (diff)
downloadjgit-7d19b18c7d9afa33032b83ca196c1dab25d02f91.tar.gz
jgit-7d19b18c7d9afa33032b83ca196c1dab25d02f91.zip
TextBuiltin#init: Factor out a method to get the log output encoding
Change-Id: I87c5774722bd36ea6fe18c4b7ce22342578fa290 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java33
1 files changed, 22 insertions, 11 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 392d1131c4..66c84aff94 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
@@ -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
- * 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.
+ * the repository.
+ * @return Charset corresponding to {@code i18n.logOutputEncoding}, or
+ * {@code UTF_8}.
*/
- protected void init(Repository repository, String gitDir) {
- Charset charset = UTF_8;
+ private Charset getLogOutputEncodingCharset(Repository repository) {
if (repository != null) {
String logOutputEncoding = repository.getConfig().getString(
- CONFIG_SECTION_I18N,
- null,
- CONFIG_KEY_LOG_OUTPUT_ENCODING);
+ CONFIG_SECTION_I18N, null, CONFIG_KEY_LOG_OUTPUT_ENCODING);
if (logOutputEncoding != null) {
try {
- charset = Charset.forName(logOutputEncoding);
+ return Charset.forName(logOutputEncoding);
} catch (IllegalArgumentException e) {
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)
ins = new FileInputStream(FileDescriptor.in);