repo git: reuse regex objects
This commit is contained in:
parent
9df6eef30f
commit
cdf28e8d20
|
@ -34,6 +34,16 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
private string cached_branch;
|
private string cached_branch;
|
||||||
|
|
||||||
|
private Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||||
|
private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
||||||
|
|
||||||
|
private Regex log_regex = new Regex (@"commit ([a-z0-9]{40})\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" +
|
||||||
|
"*", RegexOptions.Compiled);
|
||||||
|
|
||||||
private string branch {
|
private string branch {
|
||||||
get {
|
get {
|
||||||
if (string.IsNullOrEmpty (this.cached_branch)) {
|
if (string.IsNullOrEmpty (this.cached_branch)) {
|
||||||
|
@ -224,11 +234,10 @@ namespace SparkleLib.Git {
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
double percentage = 1.0;
|
double percentage = 1.0;
|
||||||
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
while (!git.StandardError.EndOfStream) {
|
while (!git.StandardError.EndOfStream) {
|
||||||
string line = git.StandardError.ReadLine ();
|
string line = git.StandardError.ReadLine ();
|
||||||
Match match = progress_regex.Match (line);
|
Match match = this.progress_regex.Match (line);
|
||||||
double speed = 0.0;
|
double speed = 0.0;
|
||||||
double number = 0.0;
|
double number = 0.0;
|
||||||
|
|
||||||
|
@ -245,9 +254,7 @@ namespace SparkleLib.Git {
|
||||||
} else {
|
} else {
|
||||||
// "Writing objects" stage
|
// "Writing objects" stage
|
||||||
number = (number / 100 * 80 + 20);
|
number = (number / 100 * 80 + 20);
|
||||||
|
Match speed_match = this.speed_regex.Match (line);
|
||||||
Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
|
||||||
Match speed_match = speed_regex.Match (line);
|
|
||||||
|
|
||||||
if (speed_match.Success) {
|
if (speed_match.Success) {
|
||||||
speed = double.Parse (speed_match.Groups [1].Value) * 1024;
|
speed = double.Parse (speed_match.Groups [1].Value) * 1024;
|
||||||
|
@ -309,11 +316,10 @@ namespace SparkleLib.Git {
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
double percentage = 1.0;
|
double percentage = 1.0;
|
||||||
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
while (!git.StandardError.EndOfStream) {
|
while (!git.StandardError.EndOfStream) {
|
||||||
string line = git.StandardError.ReadLine ();
|
string line = git.StandardError.ReadLine ();
|
||||||
Match match = progress_regex.Match (line);
|
Match match = this.progress_regex.Match (line);
|
||||||
double speed = 0.0;
|
double speed = 0.0;
|
||||||
double number = 0.0;
|
double number = 0.0;
|
||||||
|
|
||||||
|
@ -330,9 +336,7 @@ namespace SparkleLib.Git {
|
||||||
} else {
|
} else {
|
||||||
// "Writing objects" stage
|
// "Writing objects" stage
|
||||||
number = (number / 100 * 80 + 20);
|
number = (number / 100 * 80 + 20);
|
||||||
|
Match speed_match = this.speed_regex.Match (line);
|
||||||
Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
|
||||||
Match speed_match = speed_regex.Match (line);
|
|
||||||
|
|
||||||
if (speed_match.Success) {
|
if (speed_match.Success) {
|
||||||
speed = double.Parse (speed_match.Groups [1].Value) * 1024;
|
speed = double.Parse (speed_match.Groups [1].Value) * 1024;
|
||||||
|
@ -732,15 +736,9 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
entries.Add (last_entry);
|
entries.Add (last_entry);
|
||||||
|
|
||||||
Regex regex = new Regex (@"commit ([a-z0-9]{40})\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" +
|
|
||||||
"*", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
foreach (string log_entry in entries) {
|
foreach (string log_entry in entries) {
|
||||||
Match match = regex.Match (log_entry);
|
Match match = this.log_regex.Match (log_entry);
|
||||||
|
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
SparkleChangeSet change_set = new SparkleChangeSet ();
|
SparkleChangeSet change_set = new SparkleChangeSet ();
|
||||||
|
|
Loading…
Reference in a new issue