repo: abstract syncdown parts
This commit is contained in:
parent
bc3e5dcec6
commit
cf54ba0ddd
|
@ -230,13 +230,9 @@ namespace SparkleLib {
|
||||||
!this.is_buffering) {
|
!this.is_buffering) {
|
||||||
|
|
||||||
while (this.listener.ChangesQueue > 0) {
|
while (this.listener.ChangesQueue > 0) {
|
||||||
Fetch ();
|
SyncDown ();
|
||||||
this.listener.DecrementChangesQueue ();
|
this.listener.DecrementChangesQueue ();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.watcher.EnableRaisingEvents = false;
|
|
||||||
Rebase ();
|
|
||||||
this.watcher.EnableRaisingEvents = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -303,11 +299,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (!remote_revision.StartsWith (this.revision)) {
|
if (!remote_revision.StartsWith (this.revision)) {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_revision + ")");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_revision + ")");
|
||||||
Fetch ();
|
SyncDown ();
|
||||||
|
|
||||||
this.watcher.EnableRaisingEvents = false;
|
|
||||||
Rebase ();
|
|
||||||
this.watcher.EnableRaisingEvents = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,7 +468,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
|
|
||||||
// Commits the made changes
|
// Commits the made changes
|
||||||
public void Commit (string message)
|
private void Commit (string message)
|
||||||
{
|
{
|
||||||
if (!AnyDifferences)
|
if (!AnyDifferences)
|
||||||
return;
|
return;
|
||||||
|
@ -493,44 +485,58 @@ namespace SparkleLib {
|
||||||
CollectGarbage ();
|
CollectGarbage ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void SyncDownBase ()
|
||||||
// Fetches changes from the remote repository
|
|
||||||
public void Fetch ()
|
|
||||||
{
|
{
|
||||||
|
SparkleHelpers.DebugInfo ("Sync", "[" + Name + "] Initiated");
|
||||||
this.remote_timer.Stop ();
|
this.remote_timer.Stop ();
|
||||||
|
|
||||||
if (SyncStatusChanged != null)
|
if (SyncStatusChanged != null)
|
||||||
SyncStatusChanged (SyncStatus.SyncDown);
|
SyncStatusChanged (SyncStatus.SyncDown);
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes");
|
if (SyncDown ()) {
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
SparkleHelpers.DebugInfo ("Sync", "[" + Name + "] Done");
|
||||||
|
|
||||||
git.Start ();
|
|
||||||
git.WaitForExit ();
|
|
||||||
|
|
||||||
if (git.ExitCode != 0) {
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes not fetched");
|
|
||||||
this.server_online = false;
|
|
||||||
|
|
||||||
if (SyncStatusChanged != null)
|
|
||||||
SyncStatusChanged (SyncStatus.Error);
|
|
||||||
} else {
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched");
|
|
||||||
this.server_online = true;
|
this.server_online = true;
|
||||||
this.revision = GetRevision ();
|
this.revision = GetRevision ();
|
||||||
|
|
||||||
if (SyncStatusChanged != null)
|
if (SyncStatusChanged != null)
|
||||||
SyncStatusChanged (SyncStatus.Idle);
|
SyncStatusChanged (SyncStatus.Idle);
|
||||||
|
} else {
|
||||||
|
SparkleHelpers.DebugInfo ("Sync", "[" + Name + "] Error");
|
||||||
|
this.server_online = false;
|
||||||
|
|
||||||
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.Idle);
|
||||||
|
|
||||||
this.remote_timer.Start ();
|
this.remote_timer.Start ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Fetches changes from the remote repository
|
||||||
|
public bool SyncDown ()
|
||||||
|
{
|
||||||
|
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
||||||
|
|
||||||
|
git.Start ();
|
||||||
|
git.WaitForExit ();
|
||||||
|
|
||||||
|
if (git.ExitCode == 0) {
|
||||||
|
Rebase ();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
public void Rebase ()
|
private void Rebase ()
|
||||||
{
|
{
|
||||||
|
DisableWatching ();
|
||||||
|
|
||||||
if (AnyDifferences) {
|
if (AnyDifferences) {
|
||||||
Add ();
|
Add ();
|
||||||
|
|
||||||
|
@ -563,6 +569,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (NewChangeSet != null)
|
if (NewChangeSet != null)
|
||||||
NewChangeSet (GetChangeSets (1) [0], LocalPath);
|
NewChangeSet (GetChangeSets (1) [0], LocalPath);
|
||||||
|
|
||||||
|
EnableWatching ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue