repo: block on commands in methods instead of starting in a new thread afterwards
This commit is contained in:
parent
e13b4d8501
commit
9a4c950823
|
@ -37,13 +37,9 @@ namespace SparkleLib {
|
|||
|
||||
public class SparkleRepo {
|
||||
|
||||
private Timer remote_timer;
|
||||
private Timer local_timer;
|
||||
private FileSystemWatcher watcher;
|
||||
private SparkleListenerBase listener;
|
||||
private List <double> sizebuffer;
|
||||
private bool has_changed = false;
|
||||
private Object change_lock = new Object ();
|
||||
public readonly SparkleBackend Backend;
|
||||
public readonly string LocalPath;
|
||||
public readonly string Name;
|
||||
|
||||
protected SyncStatus status;
|
||||
protected string revision;
|
||||
|
@ -51,10 +47,13 @@ namespace SparkleLib {
|
|||
protected bool is_polling = true;
|
||||
protected bool server_online = true;
|
||||
|
||||
public readonly SparkleBackend Backend;
|
||||
|
||||
public readonly string LocalPath;
|
||||
public readonly string Name;
|
||||
private Timer remote_timer;
|
||||
private Timer local_timer;
|
||||
private FileSystemWatcher watcher;
|
||||
private SparkleListenerBase listener;
|
||||
private List <double> sizebuffer;
|
||||
private bool has_changed = false;
|
||||
private Object change_lock = new Object ();
|
||||
|
||||
|
||||
// TODO: make this a regexp
|
||||
|
@ -294,7 +293,9 @@ namespace SparkleLib {
|
|||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes...");
|
||||
SparkleGit git = new SparkleGit (LocalPath, "ls-remote origin master");
|
||||
|
||||
git.Exited += delegate {
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
if (git.ExitCode != 0)
|
||||
return;
|
||||
|
||||
|
@ -308,10 +309,6 @@ namespace SparkleLib {
|
|||
Rebase ();
|
||||
this.watcher.EnableRaisingEvents = true;
|
||||
}
|
||||
};
|
||||
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -502,15 +499,14 @@ namespace SparkleLib {
|
|||
{
|
||||
this.remote_timer.Stop ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes");
|
||||
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
||||
|
||||
if (SyncStatusChanged != null)
|
||||
SyncStatusChanged (SyncStatus.SyncDown);
|
||||
|
||||
git.Exited += delegate {
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes");
|
||||
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
||||
|
||||
this.revision = GetRevision ();
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
if (git.ExitCode != 0) {
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes not fetched");
|
||||
|
@ -521,19 +517,17 @@ namespace SparkleLib {
|
|||
} else {
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched");
|
||||
this.server_online = true;
|
||||
this.revision = GetRevision ();
|
||||
|
||||
if (SyncStatusChanged != null)
|
||||
SyncStatusChanged (SyncStatus.Idle);
|
||||
}
|
||||
|
||||
this.remote_timer.Start ();
|
||||
};
|
||||
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Merges the fetched changes
|
||||
public void Rebase ()
|
||||
{
|
||||
|
@ -546,7 +540,9 @@ namespace SparkleLib {
|
|||
|
||||
SparkleGit git = new SparkleGit (LocalPath, "rebase -v FETCH_HEAD");
|
||||
|
||||
git.Exited += delegate {
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
if (git.ExitCode != 0) {
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected. Trying to get out...");
|
||||
DisableWatching ();
|
||||
|
@ -564,12 +560,6 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
this.revision = GetRevision ();
|
||||
};
|
||||
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
this.revision = GetRevision ();
|
||||
|
||||
if (NewChangeSet != null)
|
||||
NewChangeSet (GetChangeSets (1) [0], LocalPath);
|
||||
|
@ -680,7 +670,9 @@ namespace SparkleLib {
|
|||
if (SyncStatusChanged != null)
|
||||
SyncStatusChanged (SyncStatus.SyncUp);
|
||||
|
||||
git.Exited += delegate {
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
if (git.ExitCode != 0) {
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes not pushed");
|
||||
|
||||
|
@ -700,13 +692,6 @@ namespace SparkleLib {
|
|||
|
||||
this.listener.Announce (this.revision);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
git.Start ();
|
||||
git.WaitForExit ();
|
||||
|
||||
// TODO put exit events here instead of in a new Exited thread, for the oter methods too
|
||||
}
|
||||
|
||||
|
||||
|
@ -990,7 +975,7 @@ namespace SparkleLib {
|
|||
return message + "..." + n;
|
||||
}
|
||||
|
||||
return message;
|
||||
return message.TrimEnd ();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue