public static CommitInformation GetCommitInfo(string sha1)
{
string info = GitCommands.RunCachableCmd(
Settings.GitCommand,
string.Format(
"show -s --pretty=format:\"{0}:\t\t%aN (%aE)%n{1}:\t%ar (%ad)%n{2}:\t%cN (%cE)%n{3}:\t%cr (%cd)%n{4}:\t%H%n%n%s%n%n%b\" {5}",
Strings.GetAutorText(),
Strings.GetAuthorDateText(),
Strings.GetCommitterText(),
Strings.GetCommitterDateText(),
Strings.GetCommitHashText(), sha1));
if (info.Trim().StartsWith("fatal"))
return new CommitInformation("Cannot find commit" + sha1, "");
info = RemoveRedundancies(info);
int index = info.IndexOf(sha1) + sha1.Length;
if (index < 0)
return new CommitInformation("Cannot find commit" + sha1, "");
if (index >= info.Length)
return new CommitInformation(info, "");
string commitHeader = info.Substring(0, index);
string commitMessage = info.Substring(index);
//We need to recode the commit message because of a bug in Git.
//We cannot let git recode the message to Settings.Encoding which is
//needed to allow the "git log" to print the filename in Settings.Encoding
Encoding logoutputEncoding = GitCommands.GetLogoutputEncoding();
if (logoutputEncoding != Settings.Encoding)
commitMessage = logoutputEncoding.GetString(Settings.Encoding.GetBytes(commitMessage));
return new CommitInformation(commitHeader,
commitMessage);
}