repo git: Simplify log parsing
This commit is contained in:
parent
a33c894b02
commit
c4c933ebf7
|
@ -764,6 +764,7 @@ namespace SparkleLib.Git {
|
||||||
string [] lines = output.Split ("\n".ToCharArray ());
|
string [] lines = output.Split ("\n".ToCharArray ());
|
||||||
List<string> entries = new List <string> ();
|
List<string> entries = new List <string> ();
|
||||||
|
|
||||||
|
// Split up commit entries
|
||||||
int line_number = 0;
|
int line_number = 0;
|
||||||
bool first_pass = true;
|
bool first_pass = true;
|
||||||
string entry = "", last_entry = "";
|
string entry = "", last_entry = "";
|
||||||
|
@ -777,8 +778,8 @@ namespace SparkleLib.Git {
|
||||||
first_pass = false;
|
first_pass = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only parse 250 files to prevent memory issues
|
// Only parse first 250 files to prevent memory issues
|
||||||
if (line_number < 254) {
|
if (line_number < 250) {
|
||||||
entry += line + "\n";
|
entry += line + "\n";
|
||||||
line_number++;
|
line_number++;
|
||||||
}
|
}
|
||||||
|
@ -788,11 +789,13 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
entries.Add (last_entry);
|
entries.Add (last_entry);
|
||||||
|
|
||||||
|
// Parse commit entries
|
||||||
foreach (string log_entry in entries) {
|
foreach (string log_entry in entries) {
|
||||||
Match match = this.log_regex.Match (log_entry);
|
Match match = this.log_regex.Match (log_entry);
|
||||||
|
|
||||||
if (match.Success) {
|
if (!match.Success)
|
||||||
|
continue;
|
||||||
|
|
||||||
SparkleChangeSet change_set = new SparkleChangeSet ();
|
SparkleChangeSet change_set = new SparkleChangeSet ();
|
||||||
|
|
||||||
change_set.Folder = new SparkleFolder (Name);
|
change_set.Folder = new SparkleFolder (Name);
|
||||||
|
@ -813,18 +816,20 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
||||||
|
|
||||||
|
// Parse file list. Lines containing file changes start with ":"
|
||||||
foreach (string entry_line in entry_lines) {
|
foreach (string entry_line in entry_lines) {
|
||||||
if (entry_line.StartsWith (":")) {
|
// Skip lines containing backspace characters
|
||||||
if (entry_line.Contains ("\\177"))
|
if (!entry_line.StartsWith (":") || entry_line.Contains ("\\177"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string type_letter = entry_line [37].ToString ();
|
|
||||||
string file_path = entry_line.Substring (39);
|
string file_path = entry_line.Substring (39);
|
||||||
bool change_is_folder = false;
|
|
||||||
|
|
||||||
if (file_path.Equals (".sparkleshare"))
|
if (file_path.Equals (".sparkleshare"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
string type_letter = entry_line [37].ToString ();
|
||||||
|
bool change_is_folder = false;
|
||||||
|
|
||||||
if (file_path.EndsWith (".empty")) {
|
if (file_path.EndsWith (".empty")) {
|
||||||
file_path = file_path.Substring (0, file_path.Length - ".empty".Length);
|
file_path = file_path.Substring (0, file_path.Length - ".empty".Length);
|
||||||
change_is_folder = true;
|
change_is_folder = true;
|
||||||
|
@ -833,6 +838,13 @@ namespace SparkleLib.Git {
|
||||||
file_path = EnsureSpecialCharacters (file_path);
|
file_path = EnsureSpecialCharacters (file_path);
|
||||||
file_path = file_path.Replace ("\\\"", "\"");
|
file_path = file_path.Replace ("\\\"", "\"");
|
||||||
|
|
||||||
|
SparkleChange change = new SparkleChange () {
|
||||||
|
Path = file_path,
|
||||||
|
IsFolder = change_is_folder,
|
||||||
|
Timestamp = change_set.Timestamp,
|
||||||
|
Type = SparkleChangeType.Added
|
||||||
|
};
|
||||||
|
|
||||||
if (type_letter.Equals ("R")) {
|
if (type_letter.Equals ("R")) {
|
||||||
int tab_pos = entry_line.LastIndexOf ("\t");
|
int tab_pos = entry_line.LastIndexOf ("\t");
|
||||||
file_path = entry_line.Substring (42, tab_pos - 42);
|
file_path = entry_line.Substring (42, tab_pos - 42);
|
||||||
|
@ -854,38 +866,21 @@ namespace SparkleLib.Git {
|
||||||
change_is_folder = true;
|
change_is_folder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
change_set.Changes.Add (
|
change.Path = file_path;
|
||||||
new SparkleChange () {
|
change.MovedToPath = to_file_path;
|
||||||
Path = file_path,
|
change.Type = SparkleChangeType.Moved;
|
||||||
IsFolder = change_is_folder,
|
|
||||||
MovedToPath = to_file_path,
|
|
||||||
Timestamp = change_set.Timestamp,
|
|
||||||
Type = SparkleChangeType.Moved
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
} else if (type_letter.Equals ("M")) {
|
||||||
SparkleChangeType change_type = SparkleChangeType.Added;
|
change.Type = SparkleChangeType.Edited;
|
||||||
|
|
||||||
if (type_letter.Equals ("M")) {
|
|
||||||
change_type = SparkleChangeType.Edited;
|
|
||||||
|
|
||||||
} else if (type_letter.Equals ("D")) {
|
} else if (type_letter.Equals ("D")) {
|
||||||
change_type = SparkleChangeType.Deleted;
|
change.Type = SparkleChangeType.Deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
change_set.Changes.Add (
|
change_set.Changes.Add (change);
|
||||||
new SparkleChange () {
|
|
||||||
Path = file_path,
|
|
||||||
IsFolder = change_is_folder,
|
|
||||||
Timestamp = change_set.Timestamp,
|
|
||||||
Type = change_type
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Group commits per user, per day
|
||||||
if (change_sets.Count > 0 && path == null) {
|
if (change_sets.Count > 0 && path == null) {
|
||||||
SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];
|
SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];
|
||||||
|
|
||||||
|
@ -910,6 +905,7 @@ namespace SparkleLib.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// Don't show removals or moves in the revision list of a file
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
List<SparkleChange> changes_to_skip = new List<SparkleChange> ();
|
List<SparkleChange> changes_to_skip = new List<SparkleChange> ();
|
||||||
|
|
||||||
|
@ -928,7 +924,6 @@ namespace SparkleLib.Git {
|
||||||
change_sets.Add (change_set);
|
change_sets.Add (change_set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return change_sets;
|
return change_sets;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue