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