save progress on notes

This commit is contained in:
Hylke Bons 2011-06-22 02:03:27 +01:00
parent de98e29f70
commit b7c9fe4431
8 changed files with 122 additions and 33 deletions

View file

@ -22,6 +22,7 @@ using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
namespace SparkleLib {
@ -117,8 +118,20 @@ namespace SparkleLib {
public override bool SyncDown ()
{
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
// Check if note fetching is set up
SparkleGit git_config = new SparkleGit (LocalPath, "config --get remote.origin.fetch");
git_config.Start ();
git_config.WaitForExit ();
// Add configuration for note fetching if it's
// not there yet
if (git_config.ExitCode != 0) {
git_config = new SparkleGit (LocalPath, "config --add remote.origin.fetch +refs/notes/*:refs/notes/*");
git_config.Start ();
git_config.WaitForExit ();
}
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
git.Start ();
git.WaitForExit ();
@ -349,7 +362,7 @@ namespace SparkleLib {
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso");
SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso --show-notes=*");
Console.OutputEncoding = System.Text.Encoding.Unicode;
git_log.Start ();
@ -407,11 +420,12 @@ namespace SparkleLib {
if (match.Success) {
SparkleChangeSet change_set = new SparkleChangeSet ();
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.UserName = match.Groups [2].Value;
change_set.UserEmail = match.Groups [3].Value;
change_set.IsMerge = is_merge_commit;
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.UserName = match.Groups [2].Value;
change_set.UserEmail = match.Groups [3].Value;
change_set.IsMerge = is_merge_commit;
change_set.SupportsNotes = true;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
@ -451,6 +465,26 @@ namespace SparkleLib {
change_set.MovedFrom.Add (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);
}
}
}
@ -560,13 +594,20 @@ namespace SparkleLib {
git_notes.Start ();
git_notes.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Added note to " + revision);
while (Status != SyncStatus.Idle) {
System.Threading.Thread.Sleep (5 * 20);
}
SparkleGit git_push = new SparkleGit (LocalPath, "git push origin refs/notes/*");
SparkleGit git_push = new SparkleGit (LocalPath, "push origin refs/notes/*");
git_push.Start ();
git_push.WaitForExit ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Notes pushed");
SparkleAnnouncement announcement = new SparkleAnnouncement (Identifier, note_namespace);
base.listener.Announce (announcement);
}

View file

@ -28,8 +28,8 @@ namespace SparkleLib {
public string Folder;
public string Revision;
public DateTime Timestamp;
public bool FolderSupportsNotes = false;
public bool IsMerge = false;
public bool SupportsNotes = false;
public bool IsMerge = false;
public List<string> Added = new List<string> ();
public List<string> Deleted = new List<string> ();

View file

@ -38,7 +38,6 @@ namespace SparkleLib {
private TimeSpan long_interval = new TimeSpan (0, 0, 10, 0);
private SparkleWatcher watcher;
private SparkleListenerBase listener;
private TimeSpan poll_interval;
private Timer local_timer = new Timer () { Interval = 0.25 * 1000 };
private Timer remote_timer = new Timer () { Interval = 10 * 1000 };
@ -47,6 +46,7 @@ namespace SparkleLib {
private bool has_changed = false;
private Object change_lock = new Object ();
protected SparkleListenerBase listener;
protected SyncStatus status;
protected bool is_buffering = false;
protected bool server_online = true;

View file

@ -20,6 +20,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using MonoMac.Foundation;
@ -221,19 +222,29 @@ namespace SparkleShare {
NSUrlRequest request, WebFrame frame, NSObject decision_token)
{
string url = request.Url.ToString ();
Console.WriteLine (url);
string id = url.Substring (0, url.IndexOf ("%20"));
string note = url.Substring (url.IndexOf ("%20") + 3);
Console.WriteLine (id + " " + note);
SparkleShare.Controller.Repositories [0].AddNote (id, note);
return;
if (url.StartsWith (Path.VolumeSeparatorChar.ToString ())) {
string file_path = request.Url.ToString ();
file_path = file_path.Replace ("%20", " ");
NSWorkspace.SharedWorkspace.OpenFile (file_path);
string file_path = request.Url.ToString ();
file_path = file_path.Replace ("%20", " ");
NSWorkspace.SharedWorkspace.OpenFile (file_path);
} else {
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (url);
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value;
Thread thread = new Thread (new ThreadStart (delegate {
SparkleShare.Controller.AddNoteToFolder (folder_name, revision, note);
}));
thread.Start ();
}
}
}
}
}

View file

@ -141,8 +141,8 @@ namespace SparkleShare {
html = html.Replace ("<!-- $jquery-url -->", "file://" +
Path.Combine (NSBundle.MainBundle.ResourcePath, "HTML", "jquery.js"));
Console.WriteLine (html);
return html;
return html;
}
}

View file

@ -389,7 +389,25 @@ namespace SparkleShare {
}
}
}
string comments = "";
if (change_set.SupportsNotes) {
comments = "<table class=\"comments\">";
foreach (SparkleNote note in change_set.Notes) {
comments += "<tr>" +
" <td class=\"comment-author\">" + note.UserName + "</td>" +
" <td class=\"comment-text\" rowspan=\"2\">" + note.Body + "</td>" +
"</tr>" +
"<tr>" +
" <td class=\"comment-timestamp\">" + note.Timestamp + "</td>" +
" <td></td>" +
"</tr>";
}
comments += "</table>";
}
event_entry += "</dl>";
event_entries += event_entry_html.Replace ("<!-- $event-entry-content -->", event_entry)
.Replace ("<!-- $event-user-name -->", change_set.UserName)
@ -397,7 +415,8 @@ namespace SparkleShare {
.Replace ("<!-- $event-time -->", change_set.Timestamp.ToString ("H:mm"))
.Replace ("<!-- $event-folder -->", change_set.Folder)
.Replace ("<!-- $event-revision -->", change_set.Revision)
.Replace ("<!-- $event-folder-color -->", AssignColor (change_set.Folder));
.Replace ("<!-- $event-folder-color -->", AssignColor (change_set.Folder))
.Replace ("<!-- $event-comments -->", comments);
}
string day_entry = "";
@ -1021,6 +1040,15 @@ namespace SparkleShare {
}
public void AddNoteToFolder (string folder_name, string revision, string note)
{
foreach (SparkleRepoBase repo in Repositories) {
if (repo.Name.Equals (folder_name))
repo.AddNote (revision, note);
}
}
public void CheckForNewVersion ()
{
WebClient web_client = new WebClient ();

View file

@ -16,12 +16,7 @@
-webkit-box-sizing:border-box;
-moz-box-sizing: border-box; margin-top: 3px;width:100%;padding:12px;'>
<table class="comments">
<tr><td class="comment-author">Hylke Bons</td><td class="comment-text" rowspan="2">this looks awesome!</td></tr>
<tr><td class="comment-timestamp">date</td><td></td></tr>
<tr><td class="comment-author">Hylke Bons</td><td class="comment-text" rowspan="2">this looks awesome!</td></tr>
<tr><td class="comment-timestamp">date</td><td></td></tr>
</table>
<!-- $event-comments -->
<textarea style="margin-top: 12px;box-sizing: border-box;
-webkit-box-sizing:border-box;
@ -29,7 +24,7 @@
width: 75%;float:right;height: 40px"></textarea>
<div style='clear: both'></div>
<input style="float:right; margin-top: 6px;margin-bottom: 6px;" type="button"
value="Add comment" id="<!-- $event-revision -->">
value="Add note" id="<!-- $event-folder -->~<!-- $event-revision -->">
</div>
<div style='clear: both'></div>

View file

@ -21,7 +21,7 @@
table.html (comments);
location = this.id + ' ' + text;
location = this.id + '~' + text;
});
});
</script>
@ -159,6 +159,20 @@ font-size: 12px;
background-color: #fff;
border-bottom: 1px #ccc solid;
}
.comments {
width: 100%;
}
.comment-author {
font-weight: bold;
width: 25%;
}
.comment-timestamp {
color: <!-- $secondary-font-color -->;
padding-bottom: 12px;
}
</style>
</head>
<body>