From d9f7cdb521ec90f4d6eec8ae2533b87a7b996aef Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 12 Sep 2011 17:10:15 +0400 Subject: [PATCH] Hg encoding fix for commit Don't pass "--encoding" to the commit command. Default encoding is fine: it is cp1251/UTF-8 for Win/Unix or HGENCODING if it is set: being set for IDEA it is inherited by the hg process spawned by IDEA. Together with 7eab3d8f8f it fixes IDEA-67158. Remove redundant HgEncodingUtil.getDefaultCharsetName Add javadocs and @NotNulls --- .../org/zmlx/hg4idea/command/HgCommitCommand.java | 2 -- .../src/org/zmlx/hg4idea/util/HgEncodingUtil.java | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java index 630c0ee46a66..fcc60365e383 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java @@ -66,8 +66,6 @@ public class HgCommitCommand { for (HgFile hgFile : myFiles) { parameters.add(hgFile.getRelativePath()); } - parameters.add("--encoding"); - parameters.add(HgEncodingUtil.getDefaultCharsetName()); ensureSuccess(new HgCommandExecutor(myProject).executeInCurrentThread(myRoot, "commit", parameters)); final MessageBus messageBus = myProject.getMessageBus(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java index aaf11d01b3f6..cf209ceb3ba3 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgEncodingUtil.java @@ -16,14 +16,19 @@ public class HgEncodingUtil { private HgEncodingUtil() { } + /** + * Returns the default charset for Mercurial. + * It is cp1251 for Windows, and UTF-8 for Unix-like systems. + * The {@code HGENCODING} environment variable is not considered, because being set for IDEA it is inherited by the hg process + * spawned by IDEA. + * @return cp1251 for windows / UTF-8 for Unix-like systems. + */ + @NotNull public static Charset getDefaultCharset() { return SystemInfo.isWindows ? getCharsetForNameOrDefault(WINDOWS_DEFAULT_CHARSET) : getCharsetForNameOrDefault(UNIX_DEFAULT_CHARSET); } - - public static String getDefaultCharsetName() { - return SystemInfo.isWindows ? WINDOWS_DEFAULT_CHARSET : UNIX_DEFAULT_CHARSET; - } + @NotNull private static Charset getCharsetForNameOrDefault(@NotNull String name) { try { return Charset.forName(name); @@ -32,5 +37,4 @@ public class HgEncodingUtil { return Charset.defaultCharset(); } } - }