Redo GetCommits method withoug GitSharp. hopefully solves memory problem
This commit is contained in:
parent
c717d5efb1
commit
a35b203406
|
@ -930,48 +930,90 @@ namespace SparkleLib {
|
||||||
public List <SparkleCommit> GetCommits (int count)
|
public List <SparkleCommit> GetCommits (int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (count <= 0)
|
if (count < 1)
|
||||||
return null;
|
count = 30;
|
||||||
|
|
||||||
List <SparkleCommit> commits = new List <SparkleCommit> ();
|
List <SparkleCommit> commits = new List <SparkleCommit> ();
|
||||||
|
|
||||||
string commit_ref = "HEAD";
|
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw --date=iso");
|
||||||
|
git_log.Start ();
|
||||||
|
git_log.WaitForExit ();
|
||||||
|
|
||||||
try {
|
string output = git_log.StandardOutput.ReadToEnd ();
|
||||||
|
string [] lines = output.Split ("\n".ToCharArray ());
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
List <string> entries = new List <string> ();
|
||||||
|
|
||||||
Commit commit = new Commit (this, commit_ref);
|
int j = 0;
|
||||||
|
string entry = "";
|
||||||
|
foreach (string line in lines) {
|
||||||
|
|
||||||
SparkleCommit sparkle_commit = new SparkleCommit ();
|
if (line.StartsWith ("commit") && j > 0) {
|
||||||
|
|
||||||
sparkle_commit.UserName = commit.Author.Name;
|
entries.Add (entry);
|
||||||
sparkle_commit.UserEmail = commit.Author.EmailAddress;
|
entry = "";
|
||||||
sparkle_commit.DateTime = commit.CommitDate.DateTime;
|
|
||||||
sparkle_commit.Hash = commit.Hash;
|
|
||||||
|
|
||||||
foreach (Change change in commit.Changes) {
|
|
||||||
|
|
||||||
if (change.ChangeType.ToString ().Equals ("Added"))
|
|
||||||
sparkle_commit.Added.Add (change.Path);
|
|
||||||
|
|
||||||
if (change.ChangeType.ToString ().Equals ("Modified"))
|
|
||||||
sparkle_commit.Edited.Add (change.Path);
|
|
||||||
|
|
||||||
if (change.ChangeType.ToString ().Equals ("Deleted"))
|
|
||||||
sparkle_commit.Deleted.Add (change.Path);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commits.Add (sparkle_commit);
|
entry += line + "\n";
|
||||||
commit_ref += "^";
|
j++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (System.NullReferenceException) {
|
|
||||||
|
|
||||||
// FIXME: Doesn't show the first commit because it throws
|
foreach (string log_entry in entries) {
|
||||||
// this exception before getting to it. Seems to be a bug in GitSharp
|
|
||||||
|
Regex regex = new Regex (@"^commit ([a-z0-9]+)\n" +
|
||||||
|
"Author: (.+) <(.+)>\n" +
|
||||||
|
"Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
|
||||||
|
"([0-9]{2}):([0-9]{2}):([0-9]{2}) \\+([0-9]{4})\n" +
|
||||||
|
"*");
|
||||||
|
|
||||||
|
Match match = regex.Match (log_entry);
|
||||||
|
|
||||||
|
if (match.Success) {
|
||||||
|
|
||||||
|
SparkleCommit commit = new SparkleCommit ();
|
||||||
|
|
||||||
|
commit.Hash = match.Groups [1].Value;
|
||||||
|
commit.UserName = match.Groups [2].Value;
|
||||||
|
commit.UserEmail = match.Groups [3].Value;
|
||||||
|
|
||||||
|
commit.DateTime = new DateTime (int.Parse (match.Groups [4].Value),
|
||||||
|
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
||||||
|
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
|
||||||
|
int.Parse (match.Groups [9].Value));
|
||||||
|
|
||||||
|
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
||||||
|
foreach (string entry_line in entry_lines) {
|
||||||
|
|
||||||
|
if (entry_line.StartsWith (":")) {
|
||||||
|
|
||||||
|
string change_type = entry_line.Substring (37, 1);
|
||||||
|
string file_path = entry_line.Substring (39, entry_line.Length - 39);
|
||||||
|
|
||||||
|
if (change_type.Equals ("A")) {
|
||||||
|
|
||||||
|
commit.Added.Add (file_path);
|
||||||
|
|
||||||
|
} else if (change_type.Equals ("M")) {
|
||||||
|
|
||||||
|
commit.Edited.Add (file_path);
|
||||||
|
|
||||||
|
} else if (change_type.Equals ("D")) {
|
||||||
|
|
||||||
|
commit.Deleted.Add (file_path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
commits.Add (commit);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue