Cache changesets in the backend

This commit is contained in:
Hylke Bons 2012-04-29 15:19:36 +01:00
parent bcfdb0bab4
commit 9800bcf421
10 changed files with 130 additions and 77 deletions

View file

@ -161,7 +161,7 @@ namespace SparkleLib.Git {
{
get {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes...");
SparkleGit git = new SparkleGit (LocalPath, "ls-remote \"" + Url + "\" master");
SparkleGit git = new SparkleGit (LocalPath, "ls-remote \"" + RemoteUrl + "\" master");
git.Start ();
git.WaitForExit ();
@ -196,7 +196,7 @@ namespace SparkleLib.Git {
SparkleGit git = new SparkleGit (LocalPath,
"push --progress " + // Redirects progress stats to standarderror
"\"" + Url + "\" master");
"\"" + RemoteUrl + "\" master");
git.StartInfo.RedirectStandardError = true;
git.Start ();
@ -253,6 +253,7 @@ namespace SparkleLib.Git {
git.WaitForExit ();
UpdateSizes ();
ChangeSets = GetChangeSets ();
if (git.ExitCode == 0)
return true;
@ -263,7 +264,7 @@ namespace SparkleLib.Git {
public override bool SyncDown ()
{
SparkleGit git = new SparkleGit (LocalPath, "fetch --progress \"" + Url + "\" master");
SparkleGit git = new SparkleGit (LocalPath, "fetch --progress \"" + RemoteUrl + "\" master");
git.StartInfo.RedirectStandardError = true;
git.Start ();
@ -322,10 +323,13 @@ namespace SparkleLib.Git {
Path.Combine (LocalPath, ".sparkleshare"),
FileAttributes.Hidden
);
ChangeSets = GetChangeSets ();
return true;
} else {
ChangeSets = GetChangeSets ();
return false;
}
}
@ -450,7 +454,7 @@ namespace SparkleLib.Git {
private void ResolveConflict ()
{
// This is al list of conflict status codes that Git uses, their
// This is a list of conflict status codes that Git uses, their
// meaning, and how SparkleShare should handle them.
//
// DD unmerged, both deleted -> Do nothing
@ -558,7 +562,7 @@ namespace SparkleLib.Git {
// Returns a list of the latest change sets
public override List <SparkleChangeSet> GetChangeSets (int count)
public override List<SparkleChangeSet> GetChangeSets (int count)
{
if (count < 1)
count = 30;
@ -637,7 +641,7 @@ namespace SparkleLib.Git {
change_set.Revision = match.Groups [1].Value;
change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
change_set.IsMagical = is_merge_commit;
change_set.Url = Url;
change_set.RemoteUrl = RemoteUrl;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),

View file

@ -30,7 +30,7 @@ namespace SparkleLib {
public DateTime Timestamp;
public DateTime FirstTimestamp;
public bool IsMagical = false;
public Uri Url;
public Uri RemoteUrl;
public List<string> Added = new List<string> ();
public List<string> Deleted = new List<string> ();

View file

@ -74,7 +74,8 @@ namespace SparkleLib {
public readonly string LocalPath;
public readonly string Name;
public readonly Uri Url;
public readonly Uri RemoteUrl;
public List<SparkleChangeSet> ChangeSets { get; protected set; }
public abstract string ComputeIdentifier ();
public abstract string CurrentRevision { get; }
@ -88,6 +89,9 @@ namespace SparkleLib {
public abstract bool SyncDown ();
public abstract List<SparkleChangeSet> GetChangeSets (int count);
public List<SparkleChangeSet> GetChangeSets () {
return GetChangeSets (30);
}
public bool ServerOnline {
get {
@ -157,7 +161,7 @@ namespace SparkleLib {
{
LocalPath = path;
Name = Path.GetFileName (LocalPath);
Url = new Uri (SparkleConfig.DefaultConfig.GetUrlForFolder (Name));
RemoteUrl = new Uri (SparkleConfig.DefaultConfig.GetUrlForFolder (Name));
this.poll_interval = this.short_interval;
@ -169,7 +173,8 @@ namespace SparkleLib {
if (CurrentRevision == null)
CreateInitialChangeSet ();
ChangeSets = GetChangeSets ();
CreateWatcher ();
CreateListener ();
@ -347,14 +352,12 @@ namespace SparkleLib {
this.server_online = true;
if (!pre_sync_revision.Equals (CurrentRevision)) {
List<SparkleChangeSet> change_sets = GetChangeSets (1);
if (change_sets != null &&
change_sets.Count > 0 &&
!change_sets [0].Added.Contains (".sparkleshare")) {
if (ChangeSets != null &&
ChangeSets.Count > 0 &&
!ChangeSets [0].Added.Contains (".sparkleshare")) {
if (NewChangeSet != null)
NewChangeSet (change_sets [0]);
NewChangeSet (ChangeSets [0]);
}
}
@ -541,7 +544,7 @@ namespace SparkleLib {
"Congratulations, you've successfully created a SparkleShare repository!" + n +
"" + n +
"Any files you add or change in this folder will be automatically synced to " + n +
Url + " and everyone connected to it." + n +
RemoteUrl + " and everyone connected to it." + n +
"" + n +
"SparkleShare is a Free and Open Source software program that helps people " + n +
"collaborate and share files. If you like what we do, please consider a small " + n +

View file

@ -32,6 +32,7 @@ namespace SparkleShare {
private Gdk.Pixbuf [] animation_frames;
private Menu menu;
private MenuItem recent_events_item;
private MenuItem quit_item;
private MenuItem state_item;
@ -99,13 +100,20 @@ namespace SparkleShare {
});
};
Controller.UpdateQuitItemEvent += delegate (bool quit_item_enabled) {
Controller.UpdateQuitItemEvent += delegate (bool item_enabled) {
Application.Invoke (delegate {
this.quit_item.Sensitive = quit_item_enabled;
this.quit_item.Sensitive = item_enabled;
this.quit_item.ShowAll ();
});
};
Controller.UpdateOpenRecentEventsItemEvent += delegate (bool item_enabled) {
Application.Invoke (delegate {
this.recent_events_item.Sensitive = item_enabled;
this.recent_events_item.ShowAll ();
});
};
Controller.UpdateMenuEvent += delegate (IconState state) {
Application.Invoke (delegate {
CreateMenu ();
@ -199,15 +207,15 @@ namespace SparkleShare {
this.menu.Add (sync_item);
MenuItem recent_events_item = new MenuItem (_("View Recent Changes…"));
this.recent_events_item = new MenuItem (_("View Recent Changes…"));
recent_events_item.Sensitive = (Controller.Folders.Length > 0);
this.recent_events_item.Sensitive = Controller.OpenRecentEventsItemEnabled;
recent_events_item.Activated += delegate {
this.recent_events_item.Activated += delegate {
Controller.OpenRecentEventsClicked ();
};
this.menu.Add (recent_events_item);
this.menu.Add (this.recent_events_item);
this.menu.Add (new SeparatorMenuItem ());
CheckMenuItem notify_item = new CheckMenuItem (_("Notifications")) {

View file

@ -33,13 +33,6 @@ namespace SparkleShare {
{
Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
InvokeOnMainThread (delegate {
if (!GrowlApplicationBridge.IsGrowlRunning ()) {
NSApplication.SharedApplication.RequestUserAttention (
NSRequestUserAttentionType.InformationalRequest);
return;
}
if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) {
NSApplication.SharedApplication.DockTile.BadgeLabel = "1";
@ -48,6 +41,13 @@ namespace SparkleShare {
NSApplication.SharedApplication.DockTile.BadgeLabel = (events + 1).ToString ();
}
if (!GrowlApplicationBridge.IsGrowlRunning ()) {
NSApplication.SharedApplication.RequestUserAttention (
NSRequestUserAttentionType.InformationalRequest);
return;
}
if (image_path != null) {
NSData image_data = NSData.FromFile (image_path);
GrowlApplicationBridge.Notify (title, subtext,

View file

@ -135,6 +135,15 @@ namespace SparkleShare {
});
}
};
Controller.UpdateOpenRecentEventsItemEvent += delegate (bool events_item_enabled) {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
this.recent_events_item.Enabled = events_item_enabled;
});
}
};
}
@ -173,7 +182,7 @@ namespace SparkleShare {
this.recent_events_item = new NSMenuItem () {
Title = "View Recent Changes…",
Enabled = (Controller.Folders.Length > 0)
Enabled = Controller.OpenRecentEventsItemEnabled
};
if (Controller.Folders.Length > 0) {

View file

@ -43,6 +43,8 @@ namespace SparkleShare {
}
}
public bool RepositoriesLoaded { get; private set;}
public List<SparkleRepoBase> repositories = new List<SparkleRepoBase> ();
public readonly string SparklePath = SparkleConfig.DefaultConfig.FoldersPath;
@ -220,6 +222,7 @@ namespace SparkleShare {
RemoveRepository (folder_path);
}
}
if (FolderListChanged != null)
FolderListChanged ();
}
@ -304,7 +307,7 @@ namespace SparkleShare {
List<SparkleChangeSet> list = new List<SparkleChangeSet> ();
foreach (SparkleRepoBase repo in Repositories) {
List<SparkleChangeSet> change_sets = repo.GetChangeSets (30);
List<SparkleChangeSet> change_sets = repo.ChangeSets;
if (change_sets != null)
list.AddRange (change_sets);
@ -328,11 +331,12 @@ namespace SparkleShare {
return GetLog ();
string path = new SparkleFolder (name).FullPath;
int log_size = 50;
foreach (SparkleRepoBase repo in Repositories) {
if (repo.LocalPath.Equals (path))
return repo.GetChangeSets (log_size);
lock (this.repo_lock) {
foreach (SparkleRepoBase repo in Repositories) {
if (repo.LocalPath.Equals (path))
return repo.ChangeSets;
}
}
return null;
@ -360,9 +364,9 @@ namespace SparkleShare {
bool change_set_inserted = false;
foreach (ActivityDay stored_activity_day in activity_days) {
if (stored_activity_day.DateTime.Year == change_set.Timestamp.Year &&
stored_activity_day.DateTime.Month == change_set.Timestamp.Month &&
stored_activity_day.DateTime.Day == change_set.Timestamp.Day) {
if (stored_activity_day.Date.Year == change_set.Timestamp.Year &&
stored_activity_day.Date.Month == change_set.Timestamp.Month &&
stored_activity_day.Date.Day == change_set.Timestamp.Day) {
bool squash = false;
foreach (SparkleChangeSet existing_set in stored_activity_day) {
@ -492,7 +496,7 @@ namespace SparkleShare {
.Replace ("<!-- $event-avatar-url -->", change_set_avatar)
.Replace ("<!-- $event-time -->", timestamp)
.Replace ("<!-- $event-folder -->", change_set.Folder.Name)
.Replace ("<!-- $event-url -->", change_set.Url.ToString ())
.Replace ("<!-- $event-url -->", change_set.RemoteUrl.ToString ())
.Replace ("<!-- $event-revision -->", change_set.Revision);
}
@ -500,34 +504,34 @@ namespace SparkleShare {
DateTime today = DateTime.Now;
DateTime yesterday = DateTime.Now.AddDays (-1);
if (today.Day == activity_day.DateTime.Day &&
today.Month == activity_day.DateTime.Month &&
today.Year == activity_day.DateTime.Year) {
if (today.Day == activity_day.Date.Day &&
today.Month == activity_day.Date.Month &&
today.Year == activity_day.Date.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
"<span id='today' name='" + activity_day.DateTime.ToString (_("dddd, MMMM d")) + "'>"
"<span id='today' name='" + activity_day.Date.ToString (_("dddd, MMMM d")) + "'>"
+ _("Today") + "</span>");
} else if (yesterday.Day == activity_day.DateTime.Day &&
yesterday.Month == activity_day.DateTime.Month &&
yesterday.Year == activity_day.DateTime.Year) {
} else if (yesterday.Day == activity_day.Date.Day &&
yesterday.Month == activity_day.Date.Month &&
yesterday.Year == activity_day.Date.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
"<span id='yesterday' name='" + activity_day.DateTime.ToString (_("dddd, MMMM d")) + "'>"
"<span id='yesterday' name='" + activity_day.Date.ToString (_("dddd, MMMM d")) + "'>"
+ _("Yesterday") + "</span>");
} else {
if (activity_day.DateTime.Year != DateTime.Now.Year) {
if (activity_day.Date.Year != DateTime.Now.Year) {
// TRANSLATORS: This is the date in the event logs
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
activity_day.DateTime.ToString (_("dddd, MMMM d, yyyy")));
activity_day.Date.ToString (_("dddd, MMMM d, yyyy")));
} else {
// TRANSLATORS: This is the date in the event logs, without the year
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
activity_day.DateTime.ToString (_("dddd, MMMM d")));
activity_day.Date.ToString (_("dddd, MMMM d")));
}
}
@ -638,9 +642,9 @@ namespace SparkleShare {
};
lock (this.repo_lock) {
//lock (this.repo_lock) {
this.repositories.Add (repo);
}
//}
repo.Initialize ();
}
@ -674,15 +678,19 @@ namespace SparkleShare {
// folders in the SparkleShare folder
private void PopulateRepositories ()
{
foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) {
string folder_path = new SparkleFolder (folder_name).FullPath;
lock (this.repo_lock) {
foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) {
string folder_path = new SparkleFolder (folder_name).FullPath;
if (Directory.Exists (folder_path))
AddRepository (folder_path);
else
SparkleConfig.DefaultConfig.RemoveFolder (folder_name);
if (Directory.Exists (folder_path))
AddRepository (folder_path);
else
SparkleConfig.DefaultConfig.RemoveFolder (folder_name);
}
}
RepositoriesLoaded = true;
if (FolderListChanged != null)
FolderListChanged ();
}
@ -1056,7 +1064,9 @@ namespace SparkleShare {
} TODO
*/
AddRepository (target_folder_path);
lock (this.repo_lock) {
AddRepository (target_folder_path);
}
if (FolderFetched != null)
FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
@ -1111,11 +1121,8 @@ namespace SparkleShare {
private string FormatBreadCrumbs (string path_root, string path)
{
path_root = path_root.Replace ("/",
Path.DirectorySeparatorChar.ToString ());
path = path.Replace ("/",
Path.DirectorySeparatorChar.ToString ());
path_root = path_root.Replace ("/", Path.DirectorySeparatorChar.ToString ());
path = path.Replace ("/", Path.DirectorySeparatorChar.ToString ());
string link = "";
string [] crumbs = path.Split (Path.DirectorySeparatorChar);
@ -1158,12 +1165,11 @@ namespace SparkleShare {
// All change sets that happened on a day
public class ActivityDay : List <SparkleChangeSet>
{
public DateTime DateTime;
public DateTime Date;
public ActivityDay (DateTime date_time)
{
DateTime = date_time;
DateTime = new DateTime (DateTime.Year, DateTime.Month, DateTime.Day);
Date = new DateTime (date_time.Year, date_time.Month, date_time.Day);
}
}
}

View file

@ -72,7 +72,7 @@ namespace SparkleShare {
// A short delay is less annoying than
// a flashing window
int delay = 1000;
int delay = 500;
if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);

View file

@ -46,6 +46,9 @@ namespace SparkleShare {
public event UpdateQuitItemEventHandler UpdateQuitItemEvent;
public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled);
public event UpdateOpenRecentEventsItemEventHandler UpdateOpenRecentEventsItemEvent;
public delegate void UpdateOpenRecentEventsItemEventHandler (bool open_recent_events_item_enabled);
public IconState CurrentState = IconState.Idle;
public string StateText = "Welcome to SparkleShare!";
@ -111,6 +114,14 @@ namespace SparkleShare {
}
}
public bool OpenRecentEventsItemEnabled {
get {
return (Program.Controller.RepositoriesLoaded &&
Program.Controller.Folders.Count > 0);
}
}
private Timer animation;
private int animation_frame_number;
@ -133,6 +144,9 @@ namespace SparkleShare {
if (UpdateStatusItemEvent != null)
UpdateStatusItemEvent (StateText);
if (UpdateOpenRecentEventsItemEvent != null)
UpdateOpenRecentEventsItemEvent (OpenRecentEventsItemEnabled);
if (UpdateMenuEvent != null)
UpdateMenuEvent (CurrentState);
};

View file

@ -37,7 +37,9 @@ namespace SparkleShare {
private Drawing.Bitmap error_icon;
private ContextMenu context_menu;
private SparkleMenuItem log_item;
private SparkleMenuItem state_item;
private SparkleMenuItem exit_item;
@ -84,12 +86,19 @@ namespace SparkleShare {
});
};
Controller.UpdateQuitItemEvent += delegate (bool exit_item_enabled) {
Controller.UpdateQuitItemEvent += delegate (bool item_enabled) {
Dispatcher.Invoke ((Action) delegate {
this.exit_item.IsEnabled = exit_item_enabled;
this.exit_item.IsEnabled = item_enabled;
this.exit_item.UpdateLayout ();
});
};
Controller.UpdatOpenRecentEventsItemEvent += delegate (bool item_enabled) {
Dispatcher.Invoke ((Action) delegate {
this.log_item.IsEnabled = item_enabled;
this.log_item.UpdateLayout ();
});
};
}
@ -127,12 +136,12 @@ namespace SparkleShare {
Controller.AddHostedProjectClicked ();
};
SparkleMenuItem log_item = new SparkleMenuItem () {
this.log_item = new SparkleMenuItem () {
Header = "View recent changes…",
IsEnabled = (Program.Controller.Folders.Count > 0)
IsEnabled = Controller.OpenRecentEventsItemEnabled;
};
log_item.Click += delegate {
this.log_item.Click += delegate {
Controller.OpenRecentEventsClicked ();
};
@ -246,7 +255,7 @@ namespace SparkleShare {
this.context_menu.Items.Add (new Separator ());
this.context_menu.Items.Add (add_item);
this.context_menu.Items.Add (log_item);
this.context_menu.Items.Add (this.log_item);
this.context_menu.Items.Add (new Separator ());
this.context_menu.Items.Add (notify_item);
this.context_menu.Items.Add (new Separator ());