repo: Also report progress on fetch

This commit is contained in:
Hylke Bons 2011-12-30 15:00:15 +01:00
parent a8e7c05589
commit 394cd39b57
2 changed files with 57 additions and 2 deletions

View file

@ -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;

View file

@ -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;