diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 78c6218b..b1327f74 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -19,8 +19,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Security.Cryptography; -using System.Text; using System.Text.RegularExpressions; using System.Xml; @@ -122,8 +120,6 @@ namespace SparkleLib { return true; } else { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching notes"); - SyncDown (); return false; } } @@ -386,7 +382,7 @@ namespace SparkleLib { List change_sets = new List (); - SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso --show-notes=*"); + SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso"); Console.OutputEncoding = System.Text.Encoding.Unicode; git_log.Start (); @@ -488,29 +484,10 @@ namespace SparkleLib { change_set.MovedFrom.Add (file_path); change_set.MovedTo.Add (to_file_path); } - - } else if (entry_line.StartsWith (" ")) { - - Regex regex_notes = new Regex (@"(.+).*" + - "(.+).*" + - "([0-9]+).*" + - "(.+)", RegexOptions.Compiled); - - Match match_notes = regex_notes.Match (entry_line); - - if (match_notes.Success) { - SparkleNote note = new SparkleNote () { - UserName = match_notes.Groups [1].Value, - UserEmail = match_notes.Groups [2].Value, - Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)), - Body = match_notes.Groups [4].Value - }; - - change_set.Notes.Add (note); - } } } + change_set.Notes.AddRange (GetNotes (change_set.Revision)); change_sets.Add (change_set); } } @@ -587,59 +564,6 @@ namespace SparkleLib { } - public override void AddNote (string revision, string note) - { - string url = SparkleConfig.DefaultConfig.GetUrlForFolder (Name); - - if (url.StartsWith ("git") || url.StartsWith ("http")) - return; - - int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds; - - // Create the note in one line for easier merging - note = "" + - " " + - " " + SparkleConfig.DefaultConfig.UserName + "" + - " " + SparkleConfig.DefaultConfig.UserEmail + "" + - " " + - " " + timestamp + "" + - " " + note + "" + - ""; - - string note_namespace = SHA1 (timestamp.ToString () + note); - SparkleGit git_notes = new SparkleGit (LocalPath, - "notes --ref=" + note_namespace + " append -m \"" + note + "\" " + revision); - git_notes.Start (); - git_notes.WaitForExit (); - - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Added note to " + revision); - SyncUpNotes (); - } - - - public override void SyncUpNotes () - { - while (Status != SyncStatus.Idle) { - System.Threading.Thread.Sleep (5 * 20); - } - - SparkleGit git_push = new SparkleGit (LocalPath, "push origin refs/notes/*"); - git_push.Start (); - git_push.WaitForExit (); - - if (git_push.ExitCode == 0) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Notes pushed"); - - } else { - HasUnsyncedChanges = true; - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing notes failed, trying again later"); - } - - SparkleAnnouncement announcement = new SparkleAnnouncement (Identifier, SHA1 (DateTime.Now.ToString ())); - base.listener.Announce (announcement); - } - - public override bool UsesNotificationCenter { get { @@ -654,15 +578,5 @@ namespace SparkleLib { base.CreateInitialChangeSet (); SyncUp (); } - - - // Creates a 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/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 056b4cb3..4584badf 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -18,6 +18,8 @@ using System; using System.Collections.Generic; using System.IO; +using System.Security.Cryptography; +using System.Text; using System.Text.RegularExpressions; using System.Timers; using System.Xml; @@ -109,10 +111,8 @@ namespace SparkleLib { // In the unlikely case that we haven't synced up our // changes or the server was down, sync up again - if (HasUnsyncedChanges) { + if (HasUnsyncedChanges) SyncUpBase (); - SyncUpNotes (); - } }; // Sync up everything that changed @@ -239,10 +239,8 @@ namespace SparkleLib { SyncDownBase (); // Push changes that were made since the last disconnect - if (HasUnsyncedChanges) { + if (HasUnsyncedChanges) SyncUpBase (); - SyncUpNotes (); - } }; // Start polling when the connection to the irc channel is lost @@ -337,6 +335,42 @@ namespace SparkleLib { } + public List GetNotes (string revision) { + List notes = new List (); + + string notes_path = Path.Combine (LocalPath, ".notes"); + + if (!Directory.Exists (notes_path)) + Directory.CreateDirectory (notes_path); + + Regex regex_notes = new Regex (@"(.+).*" + + "(.+).*" + + "([0-9]+).*" + + "(.+)", RegexOptions.Compiled); + + foreach (string file_name in Directory.GetFiles (notes_path)) { + if (file_name.StartsWith (revision)) { + string note_xml = String.Join ("", File.ReadAllLines (file_name)); + + Match match_notes = regex_notes.Match (note_xml); + + if (match_notes.Success) { + SparkleNote note = new SparkleNote () { + UserName = match_notes.Groups [1].Value, + UserEmail = match_notes.Groups [2].Value, + Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)), + Body = match_notes.Groups [4].Value + }; + + notes.Add (note); + } + } + } + + return notes; + } + + private void SyncUpBase () { try { @@ -452,15 +486,34 @@ namespace SparkleLib { } - public virtual void AddNote (string revision, string note) + public void AddNote (string revision, string note) { + string notes_path = Path.Combine (LocalPath, ".notes"); - } + if (!Directory.Exists (notes_path)) + Directory.CreateDirectory (notes_path); + // Add a timestamp in seconds since unix epoch + int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds; - public virtual void SyncUpNotes () - { + string n = Environment.NewLine; + note = "" + n + + " " + n + + " " + SparkleConfig.DefaultConfig.UserName + "" + n + + " " + SparkleConfig.DefaultConfig.UserEmail + "" + n + + " " + n + + " " + timestamp + "" + n + + " " + note + "" + n + + "" + n; + string note_name = revision + SHA1 (timestamp.ToString () + note); + string note_path = Path.Combine (notes_path, note_name); + + StreamWriter writer = new StreamWriter (note_path); + writer.Write (note); + writer.Close (); + + SparkleHelpers.DebugInfo ("Note", "Added note to " + revision); } @@ -489,5 +542,15 @@ namespace SparkleLib { return size; } + + + // Creates a 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/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index e4d812f4..978fe1f6 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -460,10 +460,6 @@ namespace SparkleShare { string html = event_log_html.Replace ("", event_log) .Replace ("", UserName); - System.IO.StreamWriter file = new System.IO.StreamWriter (Path.Combine (SparklePaths.SparkleConfigPath, "log-debug.html")); - file.WriteLine (html); - file.Close (); - return html; } diff --git a/data/Makefile.am b/data/Makefile.am index 69b419e6..6f452209 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -3,8 +3,6 @@ SUBDIRS = \ html dist_pixmaps_DATA = \ - sparkleshare-gnome.svg \ - sparkleshare-mist.svg \ side-splash.png \ about.png