diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 7d220e18..e2eda251 100755 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -195,7 +195,7 @@ namespace SparkleLib { if (match.Success) { number = double.Parse (match.Groups [1].Value); - // The cloning progress consists of two stages: the "Compressing + // The pushing progress consists of two stages: the "Compressing // objects" stage which we count as 20% of the total progress, and // the "Writing objects" stage which we count as the last 80% if (line.StartsWith ("Compressing")) { @@ -241,10 +241,63 @@ namespace SparkleLib { public override bool SyncDown () { - SparkleGit git = new SparkleGit (LocalPath, "fetch -v"); + SparkleGit git = new SparkleGit (LocalPath, "fetch --progress"); + + git.StartInfo.RedirectStandardError = true; git.Start (); + + double percentage = 1.0; + Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled); + + DateTime last_change = DateTime.Now; + TimeSpan change_interval = new TimeSpan (0, 0, 0, 1); + + while (!git.StandardError.EndOfStream) { + string line = git.StandardError.ReadLine (); + Match match = progress_regex.Match (line); + string speed = ""; + double number = 0.0; + + if (match.Success) { + number = double.Parse (match.Groups [1].Value); + + // The fetching progress consists of two stages: the "Compressing + // objects" stage which we count as 20% of the total progress, and + // the "Receiving objects" stage which we count as the last 80% + if (line.StartsWith ("Compressing")) { + // "Compressing objects" stage + number = (number / 100 * 20); + + } else { + // "Writing objects" stage + number = (number / 100 * 80 + 20); + + if (line.Contains ("|")) { + speed = line.Substring (line.IndexOf ("|") + 1).Trim (); + speed = speed.Replace (", done.", "").Trim (); + speed = speed.Replace ("i", ""); + speed = speed.Replace ("KB/s", "ᴋʙ/s"); + speed = speed.Replace ("MB/s", "ᴍʙ/s"); + } + } + } + + if (number >= percentage) { + percentage = number; + + if (percentage == 100.0) + percentage = 99.0; + + if (DateTime.Compare (last_change, DateTime.Now.Subtract (change_interval)) < 0) { + base.OnSyncProgressChanged (percentage, speed); + last_change = DateTime.Now; + } + } + } + git.WaitForExit (); + if (git.ExitCode == 0) { Rebase (); return true; diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 67f4d735..05fad586 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -623,6 +623,8 @@ namespace SparkleLib { protected void OnSyncProgressChanged (double progress_percentage, string progress_speed) { + // Console.WriteLine ("OnProgressChanged: " + progress_percentage + " " + progress_speed); + this.progress_percentage = progress_percentage; this.progress_speed = progress_speed;