repo git: Split log parse and sort logic
This commit is contained in:
parent
3783330774
commit
0d0dddd033
|
@ -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");
|
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
|
||||||
git_status.Start ();
|
git_status.Start ();
|
||||||
|
|
||||||
while (!git_status.StandardOutput.EndOfStream) {
|
while (!git_status.StandardOutput.EndOfStream) {
|
||||||
string line = git_status.StandardOutput.ReadLine ();
|
string line = git_status.StandardOutput.ReadLine ();
|
||||||
line = line.Trim ();
|
line = line.Trim ();
|
||||||
|
|
||||||
if (line.EndsWith (".empty") || line.EndsWith (".empty\""))
|
if (line.EndsWith (".empty") || line.EndsWith (".empty\""))
|
||||||
line = line.Replace (".empty", "");
|
line = line.Replace (".empty", "");
|
||||||
|
|
||||||
|
SparkleChange change;
|
||||||
|
|
||||||
if (line.StartsWith ("R")) {
|
if (line.StartsWith ("R")) {
|
||||||
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
|
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
|
||||||
string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).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";
|
if (line.StartsWith ("M")) {
|
||||||
message += "> ‘" + EnsureSpecialCharacters (moved_to_path) + "’\n";
|
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 {
|
} else {
|
||||||
if (line.StartsWith ("M")) {
|
if (change.Type == SparkleChangeType.Edited) {
|
||||||
message += "/";
|
message += "/";
|
||||||
|
|
||||||
} else if (line.StartsWith ("D")) {
|
} else if (change.Type == SparkleChangeType.Deleted) {
|
||||||
message += "-";
|
message += "-";
|
||||||
|
|
||||||
} else {
|
} else if (change.Type == SparkleChangeType.Added) {
|
||||||
message += "+";
|
message += "+";
|
||||||
}
|
}
|
||||||
|
|
||||||
string path = line.Substring (3).Trim ("\"".ToCharArray ());
|
message += " ‘" + change.Path + "’\n";
|
||||||
message += " ‘" + EnsureSpecialCharacters (path) + "’\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
|
||||||
if (count == 10) {
|
|
||||||
message += "...\n";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
git_status.StandardOutput.ReadToEnd ();
|
|
||||||
git_status.WaitForExit ();
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace (message))
|
if (string.IsNullOrWhiteSpace (message))
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue