From 6f22466eac4b7f9115320ea18ad96ce654b41f3c Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 14 Oct 2012 23:22:55 +0100 Subject: [PATCH] history: fix some edge cases and general improvements --- SparkleLib/Git/SparkleRepoGit.cs | 7 +- SparkleLib/SparkleFetcherBase.cs | 5 +- SparkleShare/Common/HTML/event-log.html | 1 + SparkleShare/SparkleEventLogController.cs | 113 ++++++++++++++-------- 4 files changed, 77 insertions(+), 49 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 4af6e93f..b24e0e1e 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -553,8 +553,9 @@ namespace SparkleLib.Git { if (revision == null) throw new ArgumentNullException ("revision"); - + path = path.Replace ("\\", "/"); + SparkleLogger.LogInfo ("Git", Name + " | Restoring \"" + path + "\" (revision " + revision + ")"); // FIXME: git-show doesn't decrypt objects, so we can't use it to retrieve @@ -581,9 +582,7 @@ namespace SparkleLib.Git { // The correct way } else { - path = path.Replace (" ", "\\ "); - - SparkleGit git = new SparkleGit (LocalPath, "show " + revision + ":" + path + ""); + SparkleGit git = new SparkleGit (LocalPath, "show " + revision + ":\"" + path + "\""); git.Start (); FileStream stream = File.OpenWrite (target_file_path); diff --git a/SparkleLib/SparkleFetcherBase.cs b/SparkleLib/SparkleFetcherBase.cs index 9a9433d9..70f77cea 100755 --- a/SparkleLib/SparkleFetcherBase.cs +++ b/SparkleLib/SparkleFetcherBase.cs @@ -220,9 +220,8 @@ namespace SparkleLib { "Any files you add or change in this folder will be automatically synced to " + n + uri_builder.ToString () + " and everyone connected to it." + n + n + - "SparkleShare is an Open Source software program that helps people " + n + - "collaborate and share files. If you like what we do, please consider a small " + n + - "donation to support the project: http://www.sparkleshare.org/" + n + + "SparkleShare is an Open Source software program that helps people collaborate and " + n + + "share files. If you like what we do, consider buying us a beer: http://www.sparkleshare.org/" + n + n + "Have fun! :)" + n; } diff --git a/SparkleShare/Common/HTML/event-log.html b/SparkleShare/Common/HTML/event-log.html index 0e5bd3ab..cef0f3b2 100755 --- a/SparkleShare/Common/HTML/event-log.html +++ b/SparkleShare/Common/HTML/event-log.html @@ -166,6 +166,7 @@ td.name { width: 45%; + font-weight: bold; } td.time { diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index f5ae2563..b427bbfb 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -47,6 +47,7 @@ namespace SparkleShare { private string selected_folder; private RevisionInfo restore_revision_info; + private bool history_view_active; public bool WindowIsOpen { get; private set; } @@ -62,10 +63,10 @@ namespace SparkleShare { ContentLoadingEvent (); UpdateSizeInfoEvent ("…", "…"); - Stopwatch watch = new Stopwatch (); - watch.Start (); - new Thread (() => { + Stopwatch watch = new Stopwatch (); + watch.Start (); + string html = HTML; watch.Stop (); @@ -85,6 +86,8 @@ namespace SparkleShare { public string HTML { get { + this.history_view_active = false; + List change_sets = GetLog (this.selected_folder); string html = GetHTMLLog (change_sets); @@ -178,6 +181,9 @@ namespace SparkleShare { }; Program.Controller.OnIdle += delegate { + if (this.history_view_active) + return; + ContentLoadingEvent (); UpdateSizeInfoEvent ("…", "…"); @@ -228,18 +234,21 @@ namespace SparkleShare { } else if (url.StartsWith ("restore://") && this.restore_revision_info == null) { - Regex regex = new Regex ("restore://(.+)/([a-f0-9]+)/(.+)", RegexOptions.Compiled); + Regex regex = new Regex ("restore://(.+)/([a-f0-9]+)/(.+)/(.{3} [0-9]+ [0-9]+h[0-9]+)/(.+)", RegexOptions.Compiled); Match match = regex.Match (url); if (match.Success) { + string author_name = match.Groups [3].Value; + string timestamp = match.Groups [4].Value; + this.restore_revision_info = new RevisionInfo () { Folder = new SparkleFolder (match.Groups [1].Value), Revision = match.Groups [2].Value, - FilePath = match.Groups [3].Value + FilePath = match.Groups [5].Value }; string file_name = Path.GetFileNameWithoutExtension (this.restore_revision_info.FilePath) + - " (restored)" + Path.GetExtension (this.restore_revision_info.FilePath); + " (" + author_name + " " + timestamp + ")" + Path.GetExtension (this.restore_revision_info.FilePath); string target_folder_path = Path.Combine (this.restore_revision_info.Folder.FullPath, Path.GetDirectoryName (this.restore_revision_info.FilePath)); @@ -253,6 +262,9 @@ namespace SparkleShare { } else if (url.StartsWith ("history://")) { + this.history_view_active = true; + + ContentLoadingEvent (); UpdateSizeInfoEvent ("…", "…"); string html = ""; @@ -263,51 +275,68 @@ namespace SparkleShare { foreach (SparkleRepoBase repo in Program.Controller.Repositories) { if (repo.Name.Equals (folder)) { - List change_sets = repo.GetChangeSets (path, 30); - - html += "
Revisions for “" - + Path.GetFileName (path) + "”
"; - - - html += ""; - int count = 0; - foreach (SparkleChangeSet change_set in change_sets) { - count++; - if (count == 1) - continue; - - foreach (SparkleChange change in change_set.Changes) { - if (change.Type == SparkleChangeType.Deleted && change.Path.Equals (path)) - continue; // TODO: in repo? + new Thread (() => { + Stopwatch watch = new Stopwatch (); + + watch.Start (); + + List change_sets = repo.GetChangeSets (path, 30); + + if (change_sets.Count > 1) { + html += "
Revisions for “"; + html += Path.GetFileName (path) + "”
"; + + } else { + html += "
No revisions yet for “"; + html += Path.GetFileName (path) + "”
"; } - string change_set_avatar = Program.Controller.GetAvatar (change_set.User.Email, 24); + html += "« Back"; + html += "
"; + + int count = 0; + foreach (SparkleChangeSet change_set in change_sets) { + count++; + if (count == 1) + continue; + + string change_set_avatar = Program.Controller.GetAvatar (change_set.User.Email, 24); + + if (change_set_avatar != null) + change_set_avatar = "file://" + change_set_avatar.Replace ("\\", "/"); + else + change_set_avatar = "file:///user-icon-default.png"; + + html += "" + + "" + + "" + + "" + + "" + + "" + + ""; + + count++; + } + + html += "
" + change_set.User.Name + "" + change_set.Timestamp.ToString ("d MMM yyyy") + "" + change_set.Timestamp.ToString ("HH:mm") + "" + + "Restore…
"; + watch.Stop (); - if (change_set_avatar != null) - change_set_avatar = "file://" + change_set_avatar.Replace ("\\", "/"); - else - change_set_avatar = "file:///user-icon-default.png"; + int delay = 500; + + if (watch.ElapsedMilliseconds < delay) + Thread.Sleep (delay - (int) watch.ElapsedMilliseconds); - html += "" + - "" + - "" + change_set.User.Name + "" + - "" + change_set.Timestamp.ToString ("d MMM yyyy") + "" + - "" + change_set.Timestamp.ToString ("HH:mm") + "" + - "Restore..." + - ""; - - count++; - } - - - html += ""; + UpdateContentEvent (Program.Controller.EventLogHTML.Replace ("", html)); + }).Start (); break; } } - - UpdateContentEvent (Program.Controller.EventLogHTML.Replace ("", html)); } }