repo git: Simplify log parsing
This commit is contained in:
parent
7a54657ee7
commit
8cf594039f
|
@ -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,145 +789,139 @@ 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)
|
||||||
SparkleChangeSet change_set = new SparkleChangeSet ();
|
continue;
|
||||||
|
|
||||||
change_set.Folder = new SparkleFolder (Name);
|
SparkleChangeSet change_set = new SparkleChangeSet ();
|
||||||
change_set.Revision = match.Groups [1].Value;
|
|
||||||
change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
|
|
||||||
change_set.RemoteUrl = RemoteUrl;
|
|
||||||
|
|
||||||
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
|
change_set.Folder = new SparkleFolder (Name);
|
||||||
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
change_set.Revision = match.Groups [1].Value;
|
||||||
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
|
change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
|
||||||
int.Parse (match.Groups [9].Value));
|
change_set.RemoteUrl = RemoteUrl;
|
||||||
|
|
||||||
string time_zone = match.Groups [10].Value;
|
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
|
||||||
int our_offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
|
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
||||||
int their_offset = int.Parse (time_zone.Substring (0, 3));
|
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
|
||||||
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
|
int.Parse (match.Groups [9].Value));
|
||||||
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
|
|
||||||
|
|
||||||
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
string time_zone = match.Groups [10].Value;
|
||||||
|
int our_offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
|
||||||
|
int their_offset = int.Parse (time_zone.Substring (0, 3));
|
||||||
|
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
|
||||||
|
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
|
||||||
|
|
||||||
foreach (string entry_line in entry_lines) {
|
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
||||||
if (entry_line.StartsWith (":")) {
|
|
||||||
if (entry_line.Contains ("\\177"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string type_letter = entry_line [37].ToString ();
|
// Parse file list. Lines containing file changes start with ":"
|
||||||
string file_path = entry_line.Substring (39);
|
foreach (string entry_line in entry_lines) {
|
||||||
bool change_is_folder = false;
|
// Skip lines containing backspace characters
|
||||||
|
if (!entry_line.StartsWith (":") || entry_line.Contains ("\\177"))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (file_path.Equals (".sparkleshare"))
|
string file_path = entry_line.Substring (39);
|
||||||
continue;
|
|
||||||
|
|
||||||
if (file_path.EndsWith (".empty")) {
|
if (file_path.Equals (".sparkleshare"))
|
||||||
file_path = file_path.Substring (0, file_path.Length - ".empty".Length);
|
continue;
|
||||||
change_is_folder = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
file_path = EnsureSpecialCharacters (file_path);
|
string type_letter = entry_line [37].ToString ();
|
||||||
file_path = file_path.Replace ("\\\"", "\"");
|
bool change_is_folder = false;
|
||||||
|
|
||||||
if (type_letter.Equals ("R")) {
|
if (file_path.EndsWith (".empty")) {
|
||||||
int tab_pos = entry_line.LastIndexOf ("\t");
|
file_path = file_path.Substring (0, file_path.Length - ".empty".Length);
|
||||||
file_path = entry_line.Substring (42, tab_pos - 42);
|
change_is_folder = true;
|
||||||
string to_file_path = entry_line.Substring (tab_pos + 1);
|
|
||||||
|
|
||||||
file_path = EnsureSpecialCharacters (file_path);
|
|
||||||
to_file_path = EnsureSpecialCharacters (to_file_path);
|
|
||||||
|
|
||||||
file_path = file_path.Replace ("\\\"", "\"");
|
|
||||||
to_file_path = to_file_path.Replace ("\\\"", "\"");
|
|
||||||
|
|
||||||
if (file_path.EndsWith (".empty")) {
|
|
||||||
file_path = file_path.Substring (0, file_path.Length - 6);
|
|
||||||
change_is_folder = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to_file_path.EndsWith (".empty")) {
|
|
||||||
to_file_path = to_file_path.Substring (0, to_file_path.Length - 6);
|
|
||||||
change_is_folder = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
change_set.Changes.Add (
|
|
||||||
new SparkleChange () {
|
|
||||||
Path = file_path,
|
|
||||||
IsFolder = change_is_folder,
|
|
||||||
MovedToPath = to_file_path,
|
|
||||||
Timestamp = change_set.Timestamp,
|
|
||||||
Type = SparkleChangeType.Moved
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SparkleChangeType change_type = SparkleChangeType.Added;
|
|
||||||
|
|
||||||
if (type_letter.Equals ("M")) {
|
|
||||||
change_type = SparkleChangeType.Edited;
|
|
||||||
|
|
||||||
} else if (type_letter.Equals ("D")) {
|
|
||||||
change_type = SparkleChangeType.Deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
change_set.Changes.Add (
|
|
||||||
new SparkleChange () {
|
|
||||||
Path = file_path,
|
|
||||||
IsFolder = change_is_folder,
|
|
||||||
Timestamp = change_set.Timestamp,
|
|
||||||
Type = change_type
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change_sets.Count > 0 && path == null) {
|
file_path = EnsureSpecialCharacters (file_path);
|
||||||
SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];
|
file_path = file_path.Replace ("\\\"", "\"");
|
||||||
|
|
||||||
if (change_set.Timestamp.Year == last_change_set.Timestamp.Year &&
|
SparkleChange change = new SparkleChange () {
|
||||||
change_set.Timestamp.Month == last_change_set.Timestamp.Month &&
|
Path = file_path,
|
||||||
change_set.Timestamp.Day == last_change_set.Timestamp.Day &&
|
IsFolder = change_is_folder,
|
||||||
change_set.User.Name.Equals (last_change_set.User.Name)) {
|
Timestamp = change_set.Timestamp,
|
||||||
|
Type = SparkleChangeType.Added
|
||||||
|
};
|
||||||
|
|
||||||
last_change_set.Changes.AddRange (change_set.Changes);
|
if (type_letter.Equals ("R")) {
|
||||||
|
int tab_pos = entry_line.LastIndexOf ("\t");
|
||||||
|
file_path = entry_line.Substring (42, tab_pos - 42);
|
||||||
|
string to_file_path = entry_line.Substring (tab_pos + 1);
|
||||||
|
|
||||||
if (DateTime.Compare (last_change_set.Timestamp, change_set.Timestamp) < 1) {
|
file_path = EnsureSpecialCharacters (file_path);
|
||||||
last_change_set.FirstTimestamp = last_change_set.Timestamp;
|
to_file_path = EnsureSpecialCharacters (to_file_path);
|
||||||
last_change_set.Timestamp = change_set.Timestamp;
|
|
||||||
last_change_set.Revision = change_set.Revision;
|
|
||||||
|
|
||||||
} else {
|
file_path = file_path.Replace ("\\\"", "\"");
|
||||||
last_change_set.FirstTimestamp = change_set.Timestamp;
|
to_file_path = to_file_path.Replace ("\\\"", "\"");
|
||||||
}
|
|
||||||
|
if (file_path.EndsWith (".empty")) {
|
||||||
|
file_path = file_path.Substring (0, file_path.Length - 6);
|
||||||
|
change_is_folder = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to_file_path.EndsWith (".empty")) {
|
||||||
|
to_file_path = to_file_path.Substring (0, to_file_path.Length - 6);
|
||||||
|
change_is_folder = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
change.Path = file_path;
|
||||||
|
change.MovedToPath = to_file_path;
|
||||||
|
change.Type = SparkleChangeType.Moved;
|
||||||
|
|
||||||
|
} else if (type_letter.Equals ("M")) {
|
||||||
|
change.Type = SparkleChangeType.Edited;
|
||||||
|
|
||||||
|
} else if (type_letter.Equals ("D")) {
|
||||||
|
change.Type = SparkleChangeType.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
change_set.Changes.Add (change);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group commits per user, per day
|
||||||
|
if (change_sets.Count > 0 && path == null) {
|
||||||
|
SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];
|
||||||
|
|
||||||
|
if (change_set.Timestamp.Year == last_change_set.Timestamp.Year &&
|
||||||
|
change_set.Timestamp.Month == last_change_set.Timestamp.Month &&
|
||||||
|
change_set.Timestamp.Day == last_change_set.Timestamp.Day &&
|
||||||
|
change_set.User.Name.Equals (last_change_set.User.Name)) {
|
||||||
|
|
||||||
|
last_change_set.Changes.AddRange (change_set.Changes);
|
||||||
|
|
||||||
|
if (DateTime.Compare (last_change_set.Timestamp, change_set.Timestamp) < 1) {
|
||||||
|
last_change_set.FirstTimestamp = last_change_set.Timestamp;
|
||||||
|
last_change_set.Timestamp = change_set.Timestamp;
|
||||||
|
last_change_set.Revision = change_set.Revision;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
change_sets.Add (change_set);
|
last_change_set.FirstTimestamp = change_set.Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (path != null) {
|
|
||||||
List<SparkleChange> changes_to_skip = new List<SparkleChange> ();
|
|
||||||
|
|
||||||
foreach (SparkleChange change in change_set.Changes) {
|
|
||||||
if ((change.Type == SparkleChangeType.Deleted || change.Type == SparkleChangeType.Moved)
|
|
||||||
&& change.Path.Equals (path)) {
|
|
||||||
|
|
||||||
changes_to_skip.Add (change);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (SparkleChange change_to_skip in changes_to_skip)
|
|
||||||
change_set.Changes.Remove (change_to_skip);
|
|
||||||
}
|
|
||||||
|
|
||||||
change_sets.Add (change_set);
|
change_sets.Add (change_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Don't show removals or moves in the revision list of a file
|
||||||
|
if (path != null) {
|
||||||
|
List<SparkleChange> changes_to_skip = new List<SparkleChange> ();
|
||||||
|
|
||||||
|
foreach (SparkleChange change in change_set.Changes) {
|
||||||
|
if ((change.Type == SparkleChangeType.Deleted || change.Type == SparkleChangeType.Moved)
|
||||||
|
&& change.Path.Equals (path)) {
|
||||||
|
|
||||||
|
changes_to_skip.Add (change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (SparkleChange change_to_skip in changes_to_skip)
|
||||||
|
change_set.Changes.Remove (change_to_skip);
|
||||||
|
}
|
||||||
|
|
||||||
|
change_sets.Add (change_set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue