From f01a3b41e46468803740d4c04db18a263f108845 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 28 Apr 2011 13:49:14 +0200 Subject: [PATCH 1/4] save work on conflict resolution fix --- SparkleLib/SparkleRepo.cs | 105 ++++++++++++++++++++---------- SparkleShare/SparkleController.cs | 70 +++++++++++++------- data/html/event-log.html | 10 ++- 3 files changed, 124 insertions(+), 61 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 6fe5bfe6..95250794 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -303,7 +303,7 @@ namespace SparkleLib { string remote_hash = git.StandardOutput.ReadToEnd (); if (!remote_hash.StartsWith (_CurrentHash)) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found."); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found." + _CurrentHash + " " + remote_hash); Fetch (); Watcher.EnableRaisingEvents = false; @@ -400,10 +400,8 @@ namespace SparkleLib { CommitEndedUpEmpty (this, args); } } finally { - RemoteTimer.Start (); LocalTimer.Start (); - } } @@ -447,13 +445,19 @@ namespace SparkleLib { private string GetCurrentHash () { + // Remove stale rebase-apply files because it + // makes the method return the wrong hashes. + string rebase_apply_file = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply"); + if (File.Exists (rebase_apply_file)) + File.Delete (rebase_apply_file); + SparkleGit git = new SparkleGit (LocalPath, "log -1 --format=%H"); git.Start (); git.WaitForExit (); string output = git.StandardOutput.ReadToEnd (); string hash = output.Trim (); - + Console.WriteLine (hash+"!!!!!!!!!!!!!!!!"); return hash; } @@ -575,42 +579,27 @@ namespace SparkleLib { SparkleGit git = new SparkleGit (LocalPath, "rebase -v FETCH_HEAD"); git.Exited += delegate { -/* if (Status.MergeConflict.Count > 0) { + if (git.ExitCode != 0) { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected..."); - foreach (string problem_file_name in Status.MergeConflict) { - SparkleGit git_ours = new SparkleGit (LocalPath, - "checkout --ours " + problem_file_name); - git_ours.Start (); - git_ours.WaitForExit (); - - string timestamp = DateTime.Now.ToString ("H:mm d MMM"); - string new_file_name = problem_file_name + " (" + UserName + ", " + timestamp + ")"; + while (AnyDifferences) { + ResolveConflict (); + Add (); - File.Move (problem_file_name, new_file_name); - - SparkleGit git_theirs = new SparkleGit (LocalPath, - "checkout --theirs " + problem_file_name); - git_theirs.Start (); - git_theirs.WaitForExit (); - - SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); - - if (ConflictDetected != null) - ConflictDetected (this, args); + SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); + git_continue.Start (); + git_continue.WaitForExit (); } - Add (); - - SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); - git_continue.Start (); - git_continue.WaitForExit (); - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved."); -*/ - _CurrentHash = GetCurrentHash (); -// Push (); -// } + + SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); + if (ConflictDetected != null) + ConflictDetected (this, args); + } + + _CurrentHash = GetCurrentHash (); + Push (); }; git.Start (); @@ -625,6 +614,44 @@ namespace SparkleLib { } + private void ResolveConflict () + { + SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain"); + git_status.Start (); + git_status.WaitForExit (); + + string output = git_status.StandardOutput.ReadToEnd ().TrimEnd (); + string [] lines = output.Split ("\n".ToCharArray ()); + + // We're going to recover the two original versions of + // each conflicting path, and put a timestamp on our versions + foreach (string line in lines) { + if (line.StartsWith ("UU")) { + string conflicting_path = line.Substring (3); + + File.Delete (conflicting_path); + + // Recover our version + SparkleGit git_ours = new SparkleGit (LocalPath, + "checkout --ours " + conflicting_path); + git_ours.Start (); + git_ours.WaitForExit (); + + // Append a timestamp to our version + string timestamp = DateTime.Now.ToString ("HH:mm d MMM"); + string our_path = conflicting_path + " (" + UserName + ", " + timestamp + ")"; + File.Move (conflicting_path, our_path); + + // Recover the server's version + SparkleGit git_theirs = new SparkleGit (LocalPath, + "checkout --theirs " + conflicting_path); + git_theirs.Start (); + git_theirs.WaitForExit (); + } + } + } + + // Pushes the changes to the remote repo public void Push () { @@ -811,7 +838,7 @@ namespace SparkleLib { List commits = new List (); - SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw --date=iso"); + SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso"); Console.OutputEncoding = System.Text.Encoding.Unicode; git_log.Start (); @@ -883,6 +910,7 @@ namespace SparkleLib { string change_type = entry_line [37].ToString (); string file_path = entry_line.Substring (39); + string to_file_path; if (change_type.Equals ("A")) { commit.Added.Add (file_path); @@ -890,6 +918,13 @@ namespace SparkleLib { commit.Edited.Add (file_path); } else if (change_type.Equals ("D")) { commit.Deleted.Add (file_path); + } else if (change_type.Equals ("R")) { + int tab_pos = entry_line.LastIndexOf ("\t"); + file_path = entry_line.Substring (42, tab_pos - 42); + to_file_path = entry_line.Substring (tab_pos + 1); + + commit.MovedFrom.Add (file_path); + commit.MovedTo.Add (to_file_path); } } } diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index c30a2e9b..347f4c31 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -379,29 +379,53 @@ namespace SparkleShare { } - if (change_set.Deleted.Count > 0) { - - event_entry += "
Deleted
"; - - foreach (string file_path in change_set.Deleted) { - - string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, - name, file_path); - - if (File.Exists (absolute_file_path)) { - - event_entry += "
" + file_path + "
"; - - } else { - - event_entry += "
" + file_path + "
"; - - } - - } - - } - + if (change_set.Deleted.Count > 0) { + + event_entry += "
Deleted
"; + + foreach (string file_path in change_set.Deleted) { + + string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, file_path); + + if (File.Exists (absolute_file_path)) { + + event_entry += "
" + file_path + "
"; + + } else { + + event_entry += "
" + file_path + "
"; + + } + + } + + } + + if (change_set.MovedFrom.Count > 0) { + event_entry += "
Moved
"; + + int i = 0; + foreach (string file_path in change_set.MovedFrom) { + string to_file_path = change_set.MovedTo [i]; + string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, file_path); + string absolute_to_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, to_file_path); + + if (File.Exists (absolute_file_path)) + event_entry += "
" + file_path + "
"; + else + event_entry += "
" + file_path + "
"; + + if (File.Exists (absolute_to_file_path)) + event_entry += "" + to_file_path + "
"; + else + event_entry += to_file_path + ""; + + i++; + } + } } event_entry += ""; diff --git a/data/html/event-log.html b/data/html/event-log.html index 0f6877a9..158ea70f 100644 --- a/data/html/event-log.html +++ b/data/html/event-log.html @@ -18,9 +18,13 @@ } small { - font-size: ; - color: ; - } + font-size: ; + color: ; + } + + .moved-arrow { + color: ; + } .day-entry-header { font-size: ; From d584367340b1075b0be35cf4d9a5a648ff15d141 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 29 Apr 2011 00:32:16 +0200 Subject: [PATCH 2/4] use absolute paths to move our version of conflicting file --- SparkleLib/SparkleRepo.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 95250794..7e9db713 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -423,7 +423,7 @@ namespace SparkleLib { string [] lines = output.Split ("\n".ToCharArray ()); foreach (string line in lines) { - if (line.Length > 1 &&!line [1].Equals (" ")) + if (line.Length > 1 && !line [1].Equals (" ")) return true; } @@ -582,14 +582,14 @@ namespace SparkleLib { if (git.ExitCode != 0) { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected..."); - while (AnyDifferences) { + // while (AnyDifferences) { ResolveConflict (); Add (); SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); git_continue.Start (); git_continue.WaitForExit (); - } + //} SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved."); @@ -599,7 +599,7 @@ namespace SparkleLib { } _CurrentHash = GetCurrentHash (); - Push (); + // Push (); }; git.Start (); @@ -636,17 +636,23 @@ namespace SparkleLib { "checkout --ours " + conflicting_path); git_ours.Start (); git_ours.WaitForExit (); + Console.WriteLine ("1111111111111111111111"); // Append a timestamp to our version string timestamp = DateTime.Now.ToString ("HH:mm d MMM"); string our_path = conflicting_path + " (" + UserName + ", " + timestamp + ")"; - File.Move (conflicting_path, our_path); + string path1 = SparkleHelpers.CombineMore (LocalPath, conflicting_path); + string path2 = SparkleHelpers.CombineMore (LocalPath, our_path); + + File.Move (path1, path2); + Console.WriteLine ("2222222222222222222"); // Recover the server's version SparkleGit git_theirs = new SparkleGit (LocalPath, "checkout --theirs " + conflicting_path); git_theirs.Start (); git_theirs.WaitForExit (); + Console.WriteLine ("33333333333333333333"); } } } From d91a9227827f3f7f7074864f334b2bbcd1f90f92 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 30 Apr 2011 02:42:48 +0200 Subject: [PATCH 3/4] repo: resolve any kind of rebase conflict --- SparkleLib/SparkleRepo.cs | 116 ++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 36 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 7e9db713..31f79ad0 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -303,7 +303,7 @@ namespace SparkleLib { string remote_hash = git.StandardOutput.ReadToEnd (); if (!remote_hash.StartsWith (_CurrentHash)) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found." + _CurrentHash + " " + remote_hash); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_hash + ")"); Fetch (); Watcher.EnableRaisingEvents = false; @@ -457,7 +457,7 @@ namespace SparkleLib { string output = git.StandardOutput.ReadToEnd (); string hash = output.Trim (); - Console.WriteLine (hash+"!!!!!!!!!!!!!!!!"); + return hash; } @@ -580,18 +580,14 @@ namespace SparkleLib { git.Exited += delegate { if (git.ExitCode != 0) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected..."); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected. Trying to get out..."); + Watcher.EnableRaisingEvents = false; - // while (AnyDifferences) { + while (AnyDifferences) ResolveConflict (); - Add (); - - SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); - git_continue.Start (); - git_continue.WaitForExit (); - //} SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved."); + Watcher.EnableRaisingEvents = true; SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); if (ConflictDetected != null) @@ -599,7 +595,6 @@ namespace SparkleLib { } _CurrentHash = GetCurrentHash (); - // Push (); }; git.Start (); @@ -616,43 +611,92 @@ namespace SparkleLib { private void ResolveConflict () { + // This is al list of conflict status codes that Git uses, their + // meaning, and how SparkleShare should handle them. + // + // DD unmerged, both deleted -> Do nothing + // AU unmerged, added by us -> Use theirs, save ours as a timestamped copy + // UD unmerged, deleted by them -> Use ours + // UA unmerged, added by them -> Use theirs, save ours as a timestamped copy + // DU unmerged, deleted by us -> Use theirs + // AA unmerged, both added -> Use theirs, save ours as a timestamped copy + // UU unmerged, both modified -> Use theirs, save ours as a timestamped copy + // + // Note that a rebase merge works by replaying each commit from the working branch on + // top of the upstream branch. Because of this, when a merge conflict happens the + // side reported as 'ours' is the so-far rebased series, starting with upstream, + // and 'theirs' is the working branch. In other words, the sides are swapped. + // + // So: 'ours' means the 'server's version' and 'theirs' means the 'local version' + SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain"); git_status.Start (); git_status.WaitForExit (); - string output = git_status.StandardOutput.ReadToEnd ().TrimEnd (); + string output = git_status.StandardOutput.ReadToEnd ().TrimEnd (); string [] lines = output.Split ("\n".ToCharArray ()); - // We're going to recover the two original versions of - // each conflicting path, and put a timestamp on our versions foreach (string line in lines) { - if (line.StartsWith ("UU")) { - string conflicting_path = line.Substring (3); + string conflicting_path = line.Substring (3); + conflicting_path = conflicting_path.Trim ("\"".ToCharArray ()); - File.Delete (conflicting_path); + // Both the local and server version have been modified + if (line.StartsWith ("UU") || line.StartsWith ("AA") || + line.StartsWith ("AU") || line.StartsWith ("UA")) { - // Recover our version - SparkleGit git_ours = new SparkleGit (LocalPath, - "checkout --ours " + conflicting_path); - git_ours.Start (); - git_ours.WaitForExit (); - Console.WriteLine ("1111111111111111111111"); - - // Append a timestamp to our version - string timestamp = DateTime.Now.ToString ("HH:mm d MMM"); - string our_path = conflicting_path + " (" + UserName + ", " + timestamp + ")"; - - string path1 = SparkleHelpers.CombineMore (LocalPath, conflicting_path); - string path2 = SparkleHelpers.CombineMore (LocalPath, our_path); - - File.Move (path1, path2); - Console.WriteLine ("2222222222222222222"); - // Recover the server's version + // Recover local version SparkleGit git_theirs = new SparkleGit (LocalPath, - "checkout --theirs " + conflicting_path); + "checkout --theirs \"" + conflicting_path + "\""); git_theirs.Start (); git_theirs.WaitForExit (); - Console.WriteLine ("33333333333333333333"); + + // Append a timestamp to local version + string timestamp = DateTime.Now.ToString ("HH:mm MMM d"); + string their_path = conflicting_path + " (" + UserName + ", " + timestamp + ")"; + string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path); + string abs_their_path = Path.Combine (LocalPath, their_path); + + File.Move (abs_conflicting_path, abs_their_path); + + // Recover server version + SparkleGit git_ours = new SparkleGit (LocalPath, + "checkout --ours \"" + conflicting_path + "\""); + git_ours.Start (); + git_ours.WaitForExit (); + + Add (); + + SparkleGit git_rebase_continue = new SparkleGit (LocalPath, "rebase --continue"); + git_rebase_continue.Start (); + git_rebase_continue.WaitForExit (); + } + + // The local version has been modified, but the server version was removed + if (line.StartsWith ("DU")) { + + // The modified local version is already in the + // checkout, so it just needs to be added. + // + // We need to specifically mention the file, so + // we can't reuse the Add () method + SparkleGit git_add = new SparkleGit (LocalPath, + "add " + conflicting_path); + git_add.Start (); + git_add.WaitForExit (); + + SparkleGit git_rebase_continue = new SparkleGit (LocalPath, "rebase --continue"); + git_rebase_continue.Start (); + git_rebase_continue.WaitForExit (); + } + + // The server version has been modified, but the local version was removed + if (line.StartsWith ("UD")) { + + // We can just skip here, the server version is + // already in the checkout + SparkleGit git_rebase_skip = new SparkleGit (LocalPath, "rebase --skip"); + git_rebase_skip.Start (); + git_rebase_skip.WaitForExit (); } } } From f9b2fbe7245e90887dc59c2449767f5d0b33670b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 1 May 2011 15:40:46 +0200 Subject: [PATCH 4/4] Fix coding style and whitespace of all of SparkleLib --- SparkleLib/Makefile.am | 1 - SparkleLib/SparkleCommit.cs | 41 ++---- SparkleLib/SparkleEvents.cs | 15 +-- SparkleLib/SparkleFetcher.cs | 200 ++++++++++++++---------------- SparkleLib/SparkleGit.cs | 24 ++-- SparkleLib/SparkleListener.cs | 183 ++++++++++++--------------- SparkleLib/SparklePaths.cs | 34 ++--- SparkleLib/SparklePlatform.cs | 28 ----- SparkleShare/SparkleController.cs | 10 +- SparkleShare/SparkleIntro.cs | 11 ++ 10 files changed, 226 insertions(+), 321 deletions(-) delete mode 100644 SparkleLib/SparklePlatform.cs diff --git a/SparkleLib/Makefile.am b/SparkleLib/Makefile.am index 94a456e7..f46f7b52 100644 --- a/SparkleLib/Makefile.am +++ b/SparkleLib/Makefile.am @@ -13,7 +13,6 @@ SOURCES = \ SparkleListener.cs \ SparkleOptions.cs \ SparklePaths.cs \ - SparklePlatform.cs \ SparkleRepo.cs SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file)) diff --git a/SparkleLib/SparkleCommit.cs b/SparkleLib/SparkleCommit.cs index ea91c0e6..f6ff7cc7 100644 --- a/SparkleLib/SparkleCommit.cs +++ b/SparkleLib/SparkleCommit.cs @@ -14,39 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + using System; using System.Collections.Generic; namespace SparkleLib { - public class SparkleCommit - { + public class SparkleCommit { - public string UserName; - public string UserEmail; - public DateTime DateTime; - public string Hash; - public bool IsMerge; - - public List Added; - public List Deleted; - public List Edited; - public List MovedFrom; - public List MovedTo; - - public SparkleCommit () - { - - Edited = new List (); - Added = new List (); - Deleted = new List (); - MovedFrom = new List (); - MovedTo = new List (); - - IsMerge = false; - - } - - } + public string UserName; + public string UserEmail; + public string Hash; + public DateTime DateTime; + public bool IsMerge = false; + public List Added = new List (); + public List Deleted = new List (); + public List Edited = new List (); + public List MovedFrom = new List (); + public List MovedTo = new List (); + } } diff --git a/SparkleLib/SparkleEvents.cs b/SparkleLib/SparkleEvents.cs index 41d0bb9d..ff60ca91 100644 --- a/SparkleLib/SparkleEvents.cs +++ b/SparkleLib/SparkleEvents.cs @@ -19,26 +19,21 @@ using System; namespace SparkleLib { // Arguments for most events - public class SparkleEventArgs : System.EventArgs { - + public class SparkleEventArgs : EventArgs { + public string Type; public string Message; - public SparkleEventArgs (string type) { - Type = type; - } - } // Arguments for the NewCommit event - public class NewCommitArgs : System.EventArgs { + public class NewCommitArgs : EventArgs { - public string Author; public string Email; public string Message; @@ -46,14 +41,10 @@ namespace SparkleLib { public NewCommitArgs (string author, string email, string message, string repository_path) { - Author = author; Email = email; Message = message; RepositoryPath = repository_path; - } - } - } diff --git a/SparkleLib/SparkleFetcher.cs b/SparkleLib/SparkleFetcher.cs index 89e8b7f4..3af82401 100644 --- a/SparkleLib/SparkleFetcher.cs +++ b/SparkleLib/SparkleFetcher.cs @@ -18,96 +18,86 @@ using System; using System.IO; using System.Diagnostics; -using System.Timers; namespace SparkleLib { - // A helper class that fetches and configures - // a remote repository - public class SparkleFetcher { + // A helper class that fetches and configures + // a remote repository + public class SparkleFetcher { - public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args); - public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args); - public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args); + // TODO: remove 'cloning' prefix + public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args); + public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args); + public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args); - public event CloningStartedEventHandler CloningStarted; - public event CloningFinishedEventHandler CloningFinished; - public event CloningFailedEventHandler CloningFailed; + public event CloningStartedEventHandler CloningStarted; + public event CloningFinishedEventHandler CloningFinished; + public event CloningFailedEventHandler CloningFailed; - private string TargetFolder; - private string RemoteOriginUrl; + private string TargetFolder; + private string RemoteOriginUrl; - public SparkleFetcher (string url, string folder) - { - - TargetFolder = folder; - RemoteOriginUrl = url; - - } + public SparkleFetcher (string url, string folder) + { + TargetFolder = folder; + RemoteOriginUrl = url; + } - // Clones the remote repository - public void Start () - { + // Clones the remote repository + public void Start () + { + SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning Repository"); - if (Directory.Exists (TargetFolder)) - Directory.Delete (TargetFolder, true); - - SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning Repository"); - - if (CloningStarted != null) - CloningStarted (this, new SparkleEventArgs ("CloningStarted")); + if (Directory.Exists (TargetFolder)) + Directory.Delete (TargetFolder, true); - SparkleGit git = new SparkleGit (SparklePaths.SparkleTmpPath, + + if (CloningStarted != null) + CloningStarted (this, new SparkleEventArgs ("CloningStarted")); + + SparkleGit git = new SparkleGit (SparklePaths.SparkleTmpPath, "clone \"" + RemoteOriginUrl + "\" " + "\"" + TargetFolder + "\""); - git.Exited += delegate { + git.Exited += delegate { + SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ()); - SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ()); + if (git.ExitCode != 0) { + SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning failed"); - if (git.ExitCode != 0) { + if (CloningFailed != null) + CloningFailed (this, new SparkleEventArgs ("CloningFailed")); + } else { + InstallConfiguration (); + InstallExcludeRules (); + + SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Repository cloned"); - SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning failed"); + if (CloningFinished != null) + CloningFinished (this, new SparkleEventArgs ("CloningFinished")); + } + }; - if (CloningFailed != null) - CloningFailed (this, new SparkleEventArgs ("CloningFailed")); - - } else { - - InstallConfiguration (); - InstallExcludeRules (); - - SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Repository cloned"); - - if (CloningFinished != null) - CloningFinished (this, new SparkleEventArgs ("CloningFinished")); - - } - - }; - - git.Start (); - - } + git.Start (); + } - // Install the user's name and email and some config into - // the newly cloned repository - private void InstallConfiguration () - { - - string global_config_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, "config"); + // Install the user's name and email and some config into + // the newly cloned repository + private void InstallConfiguration () + { + string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config"); if (File.Exists (global_config_file_path)) { - StreamReader reader = new StreamReader (global_config_file_path); string user_info = reader.ReadToEnd (); reader.Close (); string repo_config_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "config"); - string config = String.Join ("\n", File.ReadAllLines (repo_config_file_path)); + + // Be case sensitive explicitly to work on Mac config = config.Replace ("ignorecase = true", "ignorecase = false"); config += Environment.NewLine + user_info; @@ -116,60 +106,54 @@ namespace SparkleLib { writer.Close (); SparkleHelpers.DebugInfo ("Config", "Added configuration to '" + repo_config_file_path + "'"); - } - } - // Add a .gitignore file to the repo - private void InstallExcludeRules () - { + // Add a .gitignore file to the repo + private void InstallExcludeRules () + { + string exlude_rules_file_path = SparkleHelpers.CombineMore ( + TargetFolder, ".git", "info", "exclude"); - string exlude_rules_file_path = SparkleHelpers.CombineMore - (TargetFolder, ".git", "info", "exclude"); + TextWriter writer = new StreamWriter (exlude_rules_file_path); - TextWriter writer = new StreamWriter (exlude_rules_file_path); + // gedit and emacs + writer.WriteLine ("*~"); - // gedit and emacs - writer.WriteLine ("*~"); + // vi(m) + writer.WriteLine (".*.sw[a-z]"); + writer.WriteLine ("*.un~"); + writer.WriteLine ("*.swp"); + writer.WriteLine ("*.swo"); + + // KDE + writer.WriteLine (".directory"); + + // Mac OSX + writer.WriteLine (".DS_Store"); + writer.WriteLine ("Icon?"); + writer.WriteLine ("._*"); + writer.WriteLine (".Spotlight-V100"); + writer.WriteLine (".Trashes"); - // vi(m) - writer.WriteLine (".*.sw[a-z]"); - writer.WriteLine ("*.un~"); - writer.WriteLine ("*.swp"); - writer.WriteLine ("*.swo"); - - // KDE - writer.WriteLine (".directory"); - - // Mac OSX - writer.WriteLine (".DS_Store"); - writer.WriteLine ("Icon?"); - writer.WriteLine ("._*"); - writer.WriteLine (".Spotlight-V100"); - writer.WriteLine (".Trashes"); + // Mac OSX + writer.WriteLine ("*(Autosaved).graffle"); + + // Windows + writer.WriteLine ("Thumbs.db"); + writer.WriteLine ("Desktop.ini"); - // Mac OSX - writer.WriteLine ("*(Autosaved).graffle"); - - // Windows - writer.WriteLine ("Thumbs.db"); - writer.WriteLine ("Desktop.ini"); + // CVS + writer.WriteLine ("*/CVS/*"); + writer.WriteLine (".cvsignore"); + writer.WriteLine ("*/.cvsignore"); + + // Subversion + writer.WriteLine ("/.svn/*"); + writer.WriteLine ("*/.svn/*"); - // CVS - writer.WriteLine ("*/CVS/*"); - writer.WriteLine (".cvsignore"); - writer.WriteLine ("*/.cvsignore"); - - // Subversion - writer.WriteLine ("/.svn/*"); - writer.WriteLine ("*/.svn/*"); - - writer.Close (); - - } - - } - + writer.Close (); + } + } } diff --git a/SparkleLib/SparkleGit.cs b/SparkleLib/SparkleGit.cs index ddfe3b65..a648603a 100644 --- a/SparkleLib/SparkleGit.cs +++ b/SparkleLib/SparkleGit.cs @@ -20,17 +20,17 @@ using System.Diagnostics; namespace SparkleLib { - public class SparkleGit : Process { + public class SparkleGit : Process { - public SparkleGit (string path, string args) : base () - { - EnableRaisingEvents = true; - StartInfo.FileName = SparklePaths.GitPath; - StartInfo.Arguments = args; - StartInfo.RedirectStandardOutput = true; - StartInfo.UseShellExecute = false; - StartInfo.WorkingDirectory = path; - } + public SparkleGit (string path, string args) : base () + { + EnableRaisingEvents = true; + StartInfo.FileName = SparklePaths.GitPath; + StartInfo.Arguments = args; + StartInfo.RedirectStandardOutput = true; + StartInfo.UseShellExecute = false; + StartInfo.WorkingDirectory = path; + } new public void Start () @@ -38,5 +38,5 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("Cmd", StartInfo.FileName + " " + StartInfo.Arguments); base.Start (); } - } -} \ No newline at end of file + } +} diff --git a/SparkleLib/SparkleListener.cs b/SparkleLib/SparkleListener.cs index 78c70761..3cd15736 100644 --- a/SparkleLib/SparkleListener.cs +++ b/SparkleLib/SparkleListener.cs @@ -25,126 +25,105 @@ using Meebey.SmartIrc4net; namespace SparkleLib { - public enum NotificationServerType - { - - Own, - Central - - } + public enum NotificationServerType + { + Own, + Central + } - // A persistent connection to the server that - // listens for change notifications - public class SparkleListener { + // A persistent connection to the server that + // listens for change notifications + public class SparkleListener { - // FIXME: The IrcClient is a public property because - // extending it causes crashes - public IrcClient Client; - private Thread Thread; - public readonly string Server; - public readonly string FallbackServer; - public readonly string Channel; - public readonly string Nick; + private Thread Thread; + + // FIXME: The IrcClient is a public property because + // extending it causes crashes + public IrcClient Client; + public readonly string Server; + public readonly string FallbackServer; + public readonly string Channel; + public readonly string Nick; - public SparkleListener (string server, string folder_name, - string user_email, NotificationServerType type) - { + public SparkleListener (string server, string folder_name, + string user_email, NotificationServerType type) + { + if (type == NotificationServerType.Own) { + Server = server; + } else { - if (type == NotificationServerType.Own) { + // This is SparkleShare's centralized notification service. + // Don't worry, we only use this server as a backup if you + // don't have your own. All data needed to connect is hashed and + // we don't store any personal information ever. + Server = "204.62.14.135"; + } - Server = server; + if (!String.IsNullOrEmpty (user_email)) + Nick = SHA1 (folder_name + user_email + "sparkles"); + else + Nick = SHA1 (DateTime.Now.ToString () + "sparkles"); - } else { + Nick = "s" + Nick.Substring (0, 7); + Channel = "#" + SHA1 (server + folder_name + "sparkles"); - // This is SparkleShare's centralized notification service. - // Don't worry, we only use this server as a backup if you - // don't have your own. All data needed to connect is hashed and - // we don't store any personal information ever. - Server = "204.62.14.135"; - - } - - if (!user_email.Equals ("") && user_email != null) - Nick = GetSHA1 (folder_name + user_email + "sparkles"); - else - Nick = GetSHA1 (DateTime.Now.ToString () + "sparkles"); - - Nick = "s" + Nick.Substring (0, 7); - Channel = "#" + GetSHA1 (server + folder_name + "sparkles"); - - Client = new IrcClient () { - PingTimeout = 180, - PingInterval = 90 - }; - - } + Client = new IrcClient () { + PingTimeout = 180, + PingInterval = 90 + }; + } - // Starts a new thread and listens to the channel - public void Listen () - { + // Starts a new thread and listens to the channel + public void Listen () + { + Thread = new Thread ( + new ThreadStart (delegate { + try { - Thread = new Thread ( - new ThreadStart (delegate { + // Connect, login, and join the channel + Client.Connect (new string [] {Server}, 6667); + Client.Login (Nick, Nick); + Client.RfcJoin (Channel); - try { + // List to the channel, this blocks the thread + Client.Listen (); + Client.Disconnect (); + } catch (Meebey.SmartIrc4net.ConnectionException e) { + Console.WriteLine ("Could not connect: " + e.Message); + } + }) + ); - // Connect to the server - Client.Connect (new string [] {Server}, 6667); - - // Login to the server - Client.Login (Nick, Nick); - - // Join the channel - Client.RfcJoin (Channel); - - Client.Listen (); - - Client.Disconnect (); - - } catch (Meebey.SmartIrc4net.ConnectionException e) { - - Console.WriteLine ("Could not connect: " + e.Message); - - } - - }) - ); - - Thread.Start (); - - } - - - public void Announce (string message) - { - - Client.SendMessage (SendType.Message, Channel, message); - - } + Thread.Start (); + } - // Frees all resources for this Listener - public void Dispose () - { + public void Announce (string message) + { + Client.SendMessage (SendType.Message, Channel, message); + } - Thread.Abort (); - Thread.Join (); - } + // Frees all resources for this Listener + public void Dispose () + { + Thread.Abort (); + Thread.Join (); + } - - // Creates an SHA-1 hash of input - private static string GetSHA1 (string s) - { - SHA1 sha1 = new SHA1CryptoServiceProvider (); - Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); - Byte[] encoded_bytes = sha1.ComputeHash (bytes); - return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); - } - - } + + // Creates an SHA-1 hash of input + private string SHA1 (string s) + { + SHA1 sha1 = new SHA1CryptoServiceProvider (); + Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); + Byte[] encoded_bytes = sha1.ComputeHash (bytes); + return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); + } + + } } diff --git a/SparkleLib/SparklePaths.cs b/SparkleLib/SparklePaths.cs index cb0f085d..c901f9b1 100644 --- a/SparkleLib/SparklePaths.cs +++ b/SparkleLib/SparklePaths.cs @@ -26,9 +26,7 @@ namespace SparkleLib { public static string Name = "Git"; public static string Path { - get { - string [] possible_git_paths = {"/usr/bin/git", "/usr/local/git/bin/git", "/usr/local/bin/git"}; @@ -38,37 +36,29 @@ namespace SparkleLib { return git_path; return null; - } - } public static bool IsPresent { - get { - return (Path != null); - } - } - } - - public static class SparklePaths { - - public static string GitPath = Backend.Path; - public static string HomePath = new UnixUserInfo (UnixEnvironment.UserName).HomeDirectory; - public static string SparklePath = Path.Combine (HomePath ,"SparkleShare"); - public static string SparkleTmpPath = Path.Combine (SparklePath, ".tmp"); - public static string SparkleConfigPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare"); - public static string SparkleKeysPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare"); - public static string SparkleInstallPath = Path.Combine (Defines.PREFIX, "sparkleshare"); - public static string SparkleLocalIconPath = SparkleHelpers.CombineMore (SparkleConfigPath, "icons"); - public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare", "icons"); - } + public static class SparklePaths { + public static string GitPath = Backend.Path; + public static string HomePath = new UnixUserInfo (UnixEnvironment.UserName).HomeDirectory; + public static string SparklePath = Path.Combine (HomePath ,"SparkleShare"); + public static string SparkleTmpPath = Path.Combine (SparklePath, ".tmp"); + public static string SparkleConfigPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare"); + public static string SparkleKeysPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare"); + public static string SparkleInstallPath = Path.Combine (Defines.PREFIX, "sparkleshare"); + public static string SparkleLocalIconPath = SparkleHelpers.CombineMore (SparkleConfigPath, "icons"); + public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare", "icons"); + + } } diff --git a/SparkleLib/SparklePlatform.cs b/SparkleLib/SparklePlatform.cs deleted file mode 100644 index b42282b2..00000000 --- a/SparkleLib/SparklePlatform.cs +++ /dev/null @@ -1,28 +0,0 @@ -// SparkleShare, an instant update workflow to Git. -// Copyright (C) 2010 Hylke Bons -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System; - -namespace SparkleShare { - - public static class SparklePlatform { - - // Detect OSX, Windows, GNOME or KDE here - public static string Name = "GNOME"; - - } - -} diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 347f4c31..5df67db6 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -682,29 +682,23 @@ namespace SparkleShare { public bool NotificationsEnabled { - get { - - string notify_setting_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "sparkleshare.notify"); return File.Exists (notify_setting_file_path); - } - } public void ToggleNotifications () { - - string notify_setting_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "sparkleshare.notify"); if (File.Exists (notify_setting_file_path)) File.Delete (notify_setting_file_path); else File.Create (notify_setting_file_path); - } diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index ebb15056..db27bdcd 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -645,6 +645,7 @@ namespace SparkleShare { }; + Button button = new Button () { Sensitive = false, Label = _("Finish") @@ -671,6 +672,16 @@ namespace SparkleShare { box.PackStart (table, false, false, 0); + Progressbar bar = new Progressbar (); + box.PackStart (bar, true, true, 0); + Timer timer = new Timer () { + Interval = 500 + }; + timer.Elapsed += delegate { + bar.Pulse (); + }; + timer.Start (); + layout_vertical.PackStart (box, false, false, 0); Add (layout_vertical);