notes: stop using git-notes, use files instead
This commit is contained in:
parent
4d66ad4722
commit
03d547e0c7
|
@ -19,8 +19,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
|
@ -122,8 +120,6 @@ namespace SparkleLib {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching notes");
|
|
||||||
SyncDown ();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +382,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
|
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
|
||||||
|
|
||||||
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;
|
Console.OutputEncoding = System.Text.Encoding.Unicode;
|
||||||
git_log.Start ();
|
git_log.Start ();
|
||||||
|
|
||||||
|
@ -488,29 +484,10 @@ namespace SparkleLib {
|
||||||
change_set.MovedFrom.Add (file_path);
|
change_set.MovedFrom.Add (file_path);
|
||||||
change_set.MovedTo.Add (to_file_path);
|
change_set.MovedTo.Add (to_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (entry_line.StartsWith (" <note>")) {
|
|
||||||
|
|
||||||
Regex regex_notes = new Regex (@"<name>(.+)</name>.*" +
|
|
||||||
"<email>(.+)</email>.*" +
|
|
||||||
"<timestamp>([0-9]+)</timestamp>.*" +
|
|
||||||
"<body>(.+)</body>", 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);
|
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 = "<note>" +
|
|
||||||
" <user>" +
|
|
||||||
" <name>" + SparkleConfig.DefaultConfig.UserName + "</name>" +
|
|
||||||
" <email>" + SparkleConfig.DefaultConfig.UserEmail + "</email>" +
|
|
||||||
" </user>" +
|
|
||||||
" <timestamp>" + timestamp + "</timestamp>" +
|
|
||||||
" <body>" + note + "</body>" +
|
|
||||||
"</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
|
public override bool UsesNotificationCenter
|
||||||
{
|
{
|
||||||
get {
|
get {
|
||||||
|
@ -654,15 +578,5 @@ namespace SparkleLib {
|
||||||
base.CreateInitialChangeSet ();
|
base.CreateInitialChangeSet ();
|
||||||
SyncUp ();
|
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 ("-", "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
@ -109,10 +111,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
// In the unlikely case that we haven't synced up our
|
// In the unlikely case that we haven't synced up our
|
||||||
// changes or the server was down, sync up again
|
// changes or the server was down, sync up again
|
||||||
if (HasUnsyncedChanges) {
|
if (HasUnsyncedChanges)
|
||||||
SyncUpBase ();
|
SyncUpBase ();
|
||||||
SyncUpNotes ();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sync up everything that changed
|
// Sync up everything that changed
|
||||||
|
@ -239,10 +239,8 @@ namespace SparkleLib {
|
||||||
SyncDownBase ();
|
SyncDownBase ();
|
||||||
|
|
||||||
// Push changes that were made since the last disconnect
|
// Push changes that were made since the last disconnect
|
||||||
if (HasUnsyncedChanges) {
|
if (HasUnsyncedChanges)
|
||||||
SyncUpBase ();
|
SyncUpBase ();
|
||||||
SyncUpNotes ();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start polling when the connection to the irc channel is lost
|
// Start polling when the connection to the irc channel is lost
|
||||||
|
@ -337,6 +335,42 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<SparkleNote> GetNotes (string revision) {
|
||||||
|
List<SparkleNote> notes = new List<SparkleNote> ();
|
||||||
|
|
||||||
|
string notes_path = Path.Combine (LocalPath, ".notes");
|
||||||
|
|
||||||
|
if (!Directory.Exists (notes_path))
|
||||||
|
Directory.CreateDirectory (notes_path);
|
||||||
|
|
||||||
|
Regex regex_notes = new Regex (@"<name>(.+)</name>.*" +
|
||||||
|
"<email>(.+)</email>.*" +
|
||||||
|
"<timestamp>([0-9]+)</timestamp>.*" +
|
||||||
|
"<body>(.+)</body>", 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 ()
|
private void SyncUpBase ()
|
||||||
{
|
{
|
||||||
try {
|
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 = "<note>" + n +
|
||||||
|
" <user>" + n +
|
||||||
|
" <name>" + SparkleConfig.DefaultConfig.UserName + "</name>" + n +
|
||||||
|
" <email>" + SparkleConfig.DefaultConfig.UserEmail + "</email>" + n +
|
||||||
|
" </user>" + n +
|
||||||
|
" <timestamp>" + timestamp + "</timestamp>" + n +
|
||||||
|
" <body>" + note + "</body>" + n +
|
||||||
|
"</note>" + 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;
|
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 ("-", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -460,10 +460,6 @@ namespace SparkleShare {
|
||||||
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log)
|
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log)
|
||||||
.Replace ("<!-- $username -->", UserName);
|
.Replace ("<!-- $username -->", UserName);
|
||||||
|
|
||||||
System.IO.StreamWriter file = new System.IO.StreamWriter (Path.Combine (SparklePaths.SparkleConfigPath, "log-debug.html"));
|
|
||||||
file.WriteLine (html);
|
|
||||||
file.Close ();
|
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ SUBDIRS = \
|
||||||
html
|
html
|
||||||
|
|
||||||
dist_pixmaps_DATA = \
|
dist_pixmaps_DATA = \
|
||||||
sparkleshare-gnome.svg \
|
|
||||||
sparkleshare-mist.svg \
|
|
||||||
side-splash.png \
|
side-splash.png \
|
||||||
about.png
|
about.png
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue