Browse Source

WIP: Fix encoding issues

LibGit2Sharp
Henk Westhuis 15 years ago
parent
commit
8e893a4746
  1. 32
      GitCommands/Git/GitCommands.cs
  2. 9
      GitCommands/patch/PatchManager.cs
  3. 32
      GitUI/FormCommit.cs

32
GitCommands/Git/GitCommands.cs

@ -133,6 +133,34 @@ namespace GitCommands
r.IsMatch(arg)
? Encoding.GetEncoding(Thread.CurrentThread.CurrentCulture.TextInfo.ANSICodePage)
: Encoding.UTF8;*/
//use setting 18n.logoutputencoding
if (arg.StartsWith("log", StringComparison.CurrentCultureIgnoreCase) ||
arg.StartsWith("show", StringComparison.CurrentCultureIgnoreCase) ||
arg.StartsWith("blame", StringComparison.CurrentCultureIgnoreCase))
{
string encodingString;
encodingString = GetLocalConfig().GetValue("i18n.logoutputencoding");
if (string.IsNullOrEmpty(encodingString))
encodingString = GetGlobalConfig().GetValue("i18n.logoutputencoding");
if (!string.IsNullOrEmpty(encodingString))
{
try
{
return Encoding.GetEncoding(encodingString);
}
catch (ArgumentException ex)
{
throw new Exception(ex.Message + Environment.NewLine + "Unsupported encoding set in git config file: " + encodingString + Environment.NewLine + "Please check the setting i18n.commitencoding in your local and/or global config files. Command aborted.", ex);
}
}
else
{
return Encoding.UTF8;
}
}
return Settings.Encoding;
}
@ -1499,7 +1527,7 @@ namespace GitCommands
to = FixPath(to);
var patchManager = new PatchManager();
var arguments = string.Format("diff{0} \"{1}\" \"{2}\" -- \"{3}\"", extraDiffArguments, to, from, filter);
var arguments = string.Format("diff{0} -z \"{1}\" \"{2}\" -- \"{3}\"", extraDiffArguments, to, from, filter);
patchManager.LoadPatch(RunCachableCmd(Settings.GitCommand, arguments), false);
return patchManager.patches.Count > 0 ? patchManager.patches[0] : null;
@ -1508,7 +1536,7 @@ namespace GitCommands
public static List<Patch> GetDiff(string from, string to, string extraDiffArguments)
{
var patchManager = new PatchManager();
var arguments = string.Format("diff{0} \"{1}\" \"{2}\"", extraDiffArguments, from, to);
var arguments = string.Format("diff{0} -z \"{1}\" \"{2}\"", extraDiffArguments, from, to);
patchManager.LoadPatch(RunCachableCmd(Settings.GitCommand, arguments), false);
return patchManager.patches;

9
GitCommands/patch/PatchManager.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using GitCommands;
using System.Text.RegularExpressions;
namespace PatchApply
{
@ -297,8 +298,12 @@ namespace PatchApply
patch = new Patch();
patches.Add(patch);
patch.FileNameA = input.Substring(input.LastIndexOf(" a/") + 3, input.LastIndexOf(" b/") - (input.LastIndexOf(" a/") + 3));
patch.FileNameB = input.Substring(input.LastIndexOf(" b/") + 3);
Match match = Regex.Match(input, "[ ][\"]{0,1}[a]/(.*)[\"]{0,1}[ ][\"]{0,1}[b]/(.*)[\"]{0,1}");
patch.FileNameA = match.Groups[1].Value;
patch.FileNameB = match.Groups[2].Value;
//patch.FileNameA = input.Substring(input.LastIndexOf(" a/") + 3, input.LastIndexOf(" b/") - (input.LastIndexOf(" a/") + 3));
//patch.FileNameB = input.Substring(input.LastIndexOf(" b/") + 3);
//The next line tells us what kind of patch
//new file mode xxxxxx means new file

32
GitUI/FormCommit.cs

@ -592,7 +592,37 @@ namespace GitUI
Settings.LastCommitMessage = commitMessageText;
var path = Settings.WorkingDirGitDir() + "\\COMMITMESSAGE";
using (var textWriter = new StreamWriter(path, false, Settings.Encoding))
//Commit messages are UTF-8 by default unless otherwise in the config file.
//The git manual states:
// git commit and git commit-tree issues a warning if the commit log message
// given to it does not look like a valid UTF-8 string, unless you
// explicitly say your project uses a legacy encoding. The way to say
// this is to have i18n.commitencoding in .git/config file, like this:...
Encoding encoding;
string encodingString;
encodingString = GitCommands.GitCommands.GetLocalConfig().GetValue("i18n.commitencoding");
if (string.IsNullOrEmpty(encodingString))
encodingString = GitCommands.GitCommands.GetGlobalConfig().GetValue("i18n.commitencoding");
if (!string.IsNullOrEmpty(encodingString))
{
try
{
encoding = Encoding.GetEncoding(encodingString);
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message + Environment.NewLine + "Unsupported encoding set in git config file: " + encodingString + Environment.NewLine + "Please check the setting i18n.commitencoding in your local and/or global config files. Commit aborted.");
return;
}
}
else
{
encoding = Encoding.UTF8;
}
using (var textWriter = new StreamWriter(path, false, encoding))
{
var lineNumber = 0;
foreach (var line in commitMessageText.Split('\n'))

Loading…
Cancel
Save