repo git: Split log parse and sort logic

This commit is contained in:
Hylke Bons 2014-10-28 22:21:55 +01:00
parent 3783330774
commit 0d0dddd033

View file

@ -1086,54 +1086,89 @@ namespace SparkleLib.Git {
}
// Creates a pretty commit message based on what has changed
private string FormatCommitMessage ()
{
int count = 0;
string message = "";
private List<SparkleChange> ParseStatus ()
{
List<SparkleChange> changes = new List<SparkleChange> ();
int count = 0;
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
git_status.Start ();
while (!git_status.StandardOutput.EndOfStream) {
string line = git_status.StandardOutput.ReadLine ();
line = line.Trim ();
if (line.EndsWith (".empty") || line.EndsWith (".empty\""))
line = line.Replace (".empty", "");
SparkleChange change;
if (line.StartsWith ("R")) {
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).Trim ("\"".ToCharArray ());
change = new SparkleChange () {
Type = SparkleChangeType.Moved,
Path = EnsureSpecialCharacters (path),
MovedToPath = EnsureSpecialCharacters (moved_to_path)
};
} else {
string path = line.Substring (3).Trim ("\"".ToCharArray ());
change = new SparkleChange () { Path = EnsureSpecialCharacters (path) };
change.Type = SparkleChangeType.Added;
message += "< " + EnsureSpecialCharacters (path) + "\n";
message += "> " + EnsureSpecialCharacters (moved_to_path) + "\n";
if (line.StartsWith ("M")) {
change.Type = SparkleChangeType.Edited;
} else if (line.StartsWith ("D")) {
change.Type = SparkleChangeType.Deleted;
}
}
changes.Add (change);
count++;
if (count == 10)
break;
}
git_status.StandardOutput.ReadToEnd ();
git_status.WaitForExit ();
if (changes.Count == 0)
return null;
else
return changes;
}
// Creates a pretty commit message based on what has changed
private string FormatCommitMessage ()
{
string message = "";
foreach (SparkleChange change in ParseStatus ()) {
if (change.Type == SparkleChangeType.Moved) {
message += "< " + EnsureSpecialCharacters (change.Path) + "\n";
message += "> " + EnsureSpecialCharacters (change.MovedToPath) + "\n";
} else {
if (line.StartsWith ("M")) {
if (change.Type == SparkleChangeType.Edited) {
message += "/";
} else if (line.StartsWith ("D")) {
} else if (change.Type == SparkleChangeType.Deleted) {
message += "-";
} else {
} else if (change.Type == SparkleChangeType.Added) {
message += "+";
}
string path = line.Substring (3).Trim ("\"".ToCharArray ());
message += " " + EnsureSpecialCharacters (path) + "\n";
}
count++;
if (count == 10) {
message += "...\n";
break;
message += " " + change.Path + "\n";
}
}
git_status.StandardOutput.ReadToEnd ();
git_status.WaitForExit ();
if (string.IsNullOrWhiteSpace (message))
return null;
else