SparkleRepo: update coding style
This commit is contained in:
parent
c377ee725d
commit
973d0346e1
|
@ -26,11 +26,8 @@ using System.Timers;
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
// SparkleRepo class holds repository information and timers
|
// SparkleRepo class holds repository information and timers
|
||||||
public class SparkleRepo {
|
public class SparkleRepo
|
||||||
|
{
|
||||||
public static string _ (string s) {
|
|
||||||
return Catalog.GetString (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Process Process;
|
private Process Process;
|
||||||
private Timer FetchTimer;
|
private Timer FetchTimer;
|
||||||
|
@ -46,7 +43,13 @@ namespace SparkleShare {
|
||||||
public string UserEmail;
|
public string UserEmail;
|
||||||
public string UserName;
|
public string UserName;
|
||||||
|
|
||||||
public SparkleRepo (string RepoPath) {
|
public static string _ (string s)
|
||||||
|
{
|
||||||
|
return Catalog.GetString (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkleRepo (string RepoPath)
|
||||||
|
{
|
||||||
|
|
||||||
Process = new Process ();
|
Process = new Process ();
|
||||||
Process.EnableRaisingEvents = true;
|
Process.EnableRaisingEvents = true;
|
||||||
|
@ -58,10 +61,12 @@ namespace SparkleShare {
|
||||||
Process.StartInfo.WorkingDirectory = LocalPath;
|
Process.StartInfo.WorkingDirectory = LocalPath;
|
||||||
|
|
||||||
// Get user.name, example: "User Name"
|
// Get user.name, example: "User Name"
|
||||||
UserName = "Anonymous";
|
UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName);
|
||||||
UnixUserInfo UnixUserInfo =
|
if (UserName.Equals (""))
|
||||||
new UnixUserInfo (UnixEnvironment.UserName);
|
UserName = "Anonymous";
|
||||||
UserName = UnixUserInfo.RealName;
|
else
|
||||||
|
UserName = UnixUserInfo.RealName;
|
||||||
|
|
||||||
Process.StartInfo.FileName = "git";
|
Process.StartInfo.FileName = "git";
|
||||||
Process.StartInfo.Arguments = "config user.name " + UserName;
|
Process.StartInfo.Arguments = "config user.name " + UserName;
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
@ -126,7 +131,6 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Add everything that changed
|
// Add everything that changed
|
||||||
// since SparkleShare was stopped
|
// since SparkleShare was stopped
|
||||||
Add ();
|
Add ();
|
||||||
|
@ -136,19 +140,19 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts a time buffer when something changes
|
// Starts a time buffer when something changes
|
||||||
public void OnFileActivity (object o, FileSystemEventArgs args) {
|
public void OnFileActivity (object o, FileSystemEventArgs args)
|
||||||
|
{
|
||||||
WatcherChangeTypes wct = args.ChangeType;
|
WatcherChangeTypes wct = args.ChangeType;
|
||||||
if (!ShouldIgnore (args.Name)) {
|
if (!ShouldIgnore (args.Name)) {
|
||||||
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] "
|
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'");
|
||||||
+ wct.ToString () +
|
|
||||||
" '" + args.Name + "'");
|
|
||||||
StartBufferTimer ();
|
StartBufferTimer ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A buffer that will fetch changes after
|
// A buffer that will fetch changes after
|
||||||
// file activity has settles down
|
// file activity has settles down
|
||||||
public void StartBufferTimer () {
|
public void StartBufferTimer ()
|
||||||
|
{
|
||||||
|
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
int Interval = 4000;
|
int Interval = 4000;
|
||||||
|
@ -157,15 +161,11 @@ namespace SparkleShare {
|
||||||
// Delay for a few seconds to see if more files change
|
// Delay for a few seconds to see if more files change
|
||||||
BufferTimer.Interval = Interval;
|
BufferTimer.Interval = Interval;
|
||||||
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
||||||
SparkleHelpers.DebugInfo ("Buffer",
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Done waiting.");
|
||||||
"[" + Name + "] Done waiting.");
|
|
||||||
Add ();
|
Add ();
|
||||||
};
|
};
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Buffer",
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] " + "Waiting for more changes...");
|
||||||
"[" + Name + "] " +
|
|
||||||
"Waiting for more changes...");
|
|
||||||
|
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,27 +178,27 @@ namespace SparkleShare {
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
|
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
SparkleHelpers.DebugInfo ("Buffer",
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] " + "Waiting for more changes...");
|
||||||
"[" + Name + "] " +
|
|
||||||
"Waiting for more changes...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clones a remote repo
|
// Clones a remote repo
|
||||||
public void Clone () {
|
public void Clone ()
|
||||||
|
{
|
||||||
Process.StartInfo.Arguments = "clone " + RemoteOriginUrl;
|
Process.StartInfo.Arguments = "clone " + RemoteOriginUrl;
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
// Add a gitignore file
|
// Add a gitignore file
|
||||||
TextWriter Writer = new StreamWriter (LocalPath + ".gitignore");
|
TextWriter Writer = new StreamWriter (LocalPath + ".gitignore");
|
||||||
Writer.WriteLine ("*~"); // Ignore gedit swap files
|
Writer.WriteLine ("*~"); // Ignore gedit swap files
|
||||||
Writer.WriteLine (".*.sw?"); // Ignore vi swap files
|
Writer.WriteLine (".*.sw?"); // Ignore vi swap files
|
||||||
Writer.Close ();
|
Writer.Close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stages the made changes
|
// Stages the made changes
|
||||||
public void Add () {
|
public void Add ()
|
||||||
|
{
|
||||||
BufferTimer.Stop ();
|
BufferTimer.Stop ();
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");
|
||||||
|
@ -212,16 +212,17 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commits the made changes
|
// Commits the made changes
|
||||||
public void Commit (string Message) {
|
public void Commit (string Message)
|
||||||
SparkleHelpers.DebugInfo ("Commit",
|
{
|
||||||
"[" + Name + "] " + Message);
|
SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + Message);
|
||||||
Process.StartInfo.Arguments = "commit -m \"" + Message + "\"";
|
Process.StartInfo.Arguments = "commit -m \"" + Message + "\"";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetches changes from the remote repo
|
// Fetches changes from the remote repo
|
||||||
public void Fetch () {
|
public void Fetch ()
|
||||||
|
{
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
// SparkleUI.NotificationIcon.SetSyncingState ();
|
// SparkleUI.NotificationIcon.SetSyncingState ();
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
||||||
|
@ -237,7 +238,8 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
public void Rebase () {
|
public void Rebase ()
|
||||||
|
{
|
||||||
|
|
||||||
Watcher.EnableRaisingEvents = false;
|
Watcher.EnableRaisingEvents = false;
|
||||||
|
|
||||||
|
@ -253,8 +255,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
if (Output.Contains ("Failed to merge")) {
|
if (Output.Contains ("Failed to merge")) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git",
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Resolving conflict...");
|
||||||
"[" + Name + "] Resolving conflict...");
|
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "status";
|
Process.StartInfo.Arguments = "status";
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
@ -265,21 +266,17 @@ namespace SparkleShare {
|
||||||
|
|
||||||
if (Line.Contains ("needs merge")) {
|
if (Line.Contains ("needs merge")) {
|
||||||
|
|
||||||
string ProblemFileName =
|
string ProblemFileName = Line.Substring (Line.IndexOf (": needs merge"));
|
||||||
Line.Substring (Line.IndexOf (": needs merge"));
|
|
||||||
|
|
||||||
Process.StartInfo.Arguments
|
Process.StartInfo.Arguments = "checkout --ours " + ProblemFileName;
|
||||||
= "checkout --ours " + ProblemFileName;
|
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
DateTime DateTime = new DateTime ();
|
DateTime DateTime = new DateTime ();
|
||||||
string TimeStamp =
|
string TimeStamp = DateTime.Now.ToString ("H:mm, d MMM yyyy");
|
||||||
DateTime.Now.ToString ("H:mm, d MMM yyyy");
|
|
||||||
|
|
||||||
File.Move (ProblemFileName,
|
File.Move (ProblemFileName,
|
||||||
ProblemFileName + " (" + UserName + " - " +
|
ProblemFileName + " (" + UserName + " - " + TimeStamp + ")");
|
||||||
TimeStamp + ")");
|
|
||||||
|
|
||||||
Process.StartInfo.Arguments
|
Process.StartInfo.Arguments
|
||||||
= "checkout --theirs " + ProblemFileName;
|
= "checkout --theirs " + ProblemFileName;
|
||||||
|
@ -287,9 +284,7 @@ namespace SparkleShare {
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
string ConflictTitle = "A mid-air collision happened!\n";
|
string ConflictTitle = "A mid-air collision happened!\n";
|
||||||
string ConflictSubtext =
|
string ConflictSubtext = "Don't worry, SparkleShare made\na copy of the conflicting files.";
|
||||||
@"Don't worry, SparkleShare made\n
|
|
||||||
a copies of the conflicting files.";
|
|
||||||
|
|
||||||
SparkleBubble ConflictBubble =
|
SparkleBubble ConflictBubble =
|
||||||
new SparkleBubble(_(ConflictTitle), _(ConflictSubtext));
|
new SparkleBubble(_(ConflictTitle), _(ConflictSubtext));
|
||||||
|
@ -305,8 +300,7 @@ namespace SparkleShare {
|
||||||
Process.StartInfo.Arguments = "rebase --continue";
|
Process.StartInfo.Arguments = "rebase --continue";
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
SparkleHelpers.DebugInfo ("Git",
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");
|
||||||
"[" + Name + "] Conflict resolved.");
|
|
||||||
Push ();
|
Push ();
|
||||||
Fetch ();
|
Fetch ();
|
||||||
|
|
||||||
|
@ -315,31 +309,25 @@ namespace SparkleShare {
|
||||||
// Get the last committer e-mail
|
// Get the last committer e-mail
|
||||||
Process.StartInfo.Arguments = "log --format=\"%ae\" -1";
|
Process.StartInfo.Arguments = "log --format=\"%ae\" -1";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string LastCommitEmail =
|
string LastCommitEmail = Process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
// Get the last commit message
|
// Get the last commit message
|
||||||
Process.StartInfo.Arguments = "log --format=\"%s\" -1";
|
Process.StartInfo.Arguments = "log --format=\"%s\" -1";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string LastCommitMessage =
|
string LastCommitMessage = Process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
// Get the last commiter
|
// Get the last commiter
|
||||||
Process.StartInfo.Arguments = "log --format=\"%an\" -1";
|
Process.StartInfo.Arguments = "log --format=\"%an\" -1";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string LastCommitUserName =
|
string LastCommitUserName = Process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
string NotifySettingFile =
|
string NotifySettingFile = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
|
||||||
SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
|
"sparkleshare.notify");
|
||||||
"sparkleshare.notify");
|
|
||||||
|
|
||||||
if (File.Exists (NotifySettingFile)) {
|
if (File.Exists (NotifySettingFile)) {
|
||||||
SparkleHelpers.DebugInfo ("Notification",
|
SparkleHelpers.DebugInfo ("Notification", "[" + Name + "] Showing message...");
|
||||||
"[" + Name + "] Showing message...");
|
|
||||||
ShowEventBubble (LastCommitUserName + " " + LastCommitMessage,
|
ShowEventBubble (LastCommitUserName + " " + LastCommitMessage,
|
||||||
SparkleHelpers.GetAvatar (LastCommitEmail, 48),
|
SparkleHelpers.GetAvatar (LastCommitEmail, 48), true);
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -350,7 +338,8 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pushes the changes to the remote repo
|
// Pushes the changes to the remote repo
|
||||||
public void Push () {
|
public void Push ()
|
||||||
|
{
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
||||||
Process.StartInfo.Arguments = "push";
|
Process.StartInfo.Arguments = "push";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
@ -367,14 +356,14 @@ namespace SparkleShare {
|
||||||
FileName.Contains ("/.") ||
|
FileName.Contains ("/.") ||
|
||||||
Directory.Exists (LocalPath + FileName))
|
Directory.Exists (LocalPath + FileName))
|
||||||
return true; // Yes, ignore it.
|
return true; // Yes, ignore it.
|
||||||
else if (FileName.Length > 3 &&
|
else if (FileName.Length > 3 && FileName.Substring (FileName.Length - 4).Equals (".swp"))
|
||||||
FileName.Substring (FileName.Length - 4).Equals (".swp"))
|
|
||||||
return true;
|
return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a pretty commit message based on what has changed
|
// Creates a pretty commit message based on what has changed
|
||||||
public string FormatCommitMessage () {
|
public string FormatCommitMessage ()
|
||||||
|
{
|
||||||
|
|
||||||
bool DoneAddCommit = false;
|
bool DoneAddCommit = false;
|
||||||
bool DoneEditCommit = false;
|
bool DoneEditCommit = false;
|
||||||
|
@ -408,11 +397,11 @@ namespace SparkleShare {
|
||||||
DoneAddCommit = true;
|
DoneAddCommit = true;
|
||||||
if (FilesAdded > 1)
|
if (FilesAdded > 1)
|
||||||
return "added ‘" +
|
return "added ‘" +
|
||||||
Line.Replace ("#\tnew file:", "").Trim () +
|
Line.Replace ("#\tnew file:", "").Trim () +
|
||||||
"’ and " + (FilesAdded - 1) + " more.";
|
"’ and " + (FilesAdded - 1) + " more.";
|
||||||
else
|
else
|
||||||
return "added ‘" +
|
return "added ‘" +
|
||||||
Line.Replace ("#\tnew file:", "").Trim () + "’.";
|
Line.Replace ("#\tnew file:", "").Trim () + "’.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are edited,
|
// Format message for when files are edited,
|
||||||
|
@ -421,11 +410,11 @@ namespace SparkleShare {
|
||||||
DoneEditCommit = true;
|
DoneEditCommit = true;
|
||||||
if (FilesEdited > 1)
|
if (FilesEdited > 1)
|
||||||
return "edited ‘" +
|
return "edited ‘" +
|
||||||
Line.Replace ("#\tmodified:", "").Trim () +
|
Line.Replace ("#\tmodified:", "").Trim () +
|
||||||
"’ and " + (FilesEdited - 1) + " more.";
|
"’ and " + (FilesEdited - 1) + " more.";
|
||||||
else
|
else
|
||||||
return "edited ‘" +
|
return "edited ‘" +
|
||||||
Line.Replace ("#\tmodified:", "").Trim () + "’.";
|
Line.Replace ("#\tmodified:", "").Trim () + "’.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are edited,
|
// Format message for when files are edited,
|
||||||
|
@ -434,11 +423,11 @@ namespace SparkleShare {
|
||||||
DoneDeleteCommit = true;
|
DoneDeleteCommit = true;
|
||||||
if (FilesDeleted > 1)
|
if (FilesDeleted > 1)
|
||||||
return "deleted ‘" +
|
return "deleted ‘" +
|
||||||
Line.Replace ("#\tdeleted:", "").Trim () +
|
Line.Replace ("#\tdeleted:", "").Trim () +
|
||||||
"’ and " + (FilesDeleted - 1) + " more.";
|
"’ and " + (FilesDeleted - 1) + " more.";
|
||||||
else
|
else
|
||||||
return "deleted ‘" +
|
return "deleted ‘" +
|
||||||
Line.Replace ("#\tdeleted:", "").Trim () + "’.";
|
Line.Replace ("#\tdeleted:", "").Trim () + "’.";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are renamed,
|
// Format message for when files are renamed,
|
||||||
|
@ -447,13 +436,13 @@ namespace SparkleShare {
|
||||||
DoneDeleteCommit = true;
|
DoneDeleteCommit = true;
|
||||||
if (FilesRenamed > 1)
|
if (FilesRenamed > 1)
|
||||||
return "renamed ‘" +
|
return "renamed ‘" +
|
||||||
Line.Replace ("#\trenamed:", "").Trim ().Replace
|
Line.Replace ("#\trenamed:", "").Trim ().Replace
|
||||||
(" -> ", "’ to ‘") + "’ and " + (FilesDeleted - 1) +
|
(" -> ", "’ to ‘") + "’ and " + (FilesDeleted - 1) +
|
||||||
" more.";
|
" more.";
|
||||||
else
|
else
|
||||||
return "renamed ‘" +
|
return "renamed ‘" +
|
||||||
Line.Replace ("#\trenamed:", "").Trim ().Replace
|
Line.Replace ("#\trenamed:", "").Trim ().Replace
|
||||||
(" -> ", "’ to ‘") + "’.";
|
(" -> ", "’ to ‘") + "’.";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -465,29 +454,28 @@ namespace SparkleShare {
|
||||||
|
|
||||||
// Shows a notification with text and image
|
// Shows a notification with text and image
|
||||||
public void ShowEventBubble (string Title,
|
public void ShowEventBubble (string Title,
|
||||||
Gdk.Pixbuf Avatar,
|
Gdk.Pixbuf Avatar,
|
||||||
bool ShowButtons) {
|
bool ShowButtons) {
|
||||||
|
|
||||||
SparkleBubble StuffChangedBubble = new SparkleBubble (Title, "");
|
SparkleBubble StuffChangedBubble = new SparkleBubble (Title, "");
|
||||||
StuffChangedBubble.Icon = Avatar;
|
StuffChangedBubble.Icon = Avatar;
|
||||||
|
|
||||||
// Add a button to open the folder where the changed file is
|
// Add a button to open the folder where the changed file is
|
||||||
if (ShowButtons)
|
if (ShowButtons)
|
||||||
StuffChangedBubble.AddAction
|
StuffChangedBubble.AddAction ("", _("Open Folder"),
|
||||||
("", _("Open Folder"),
|
delegate {
|
||||||
delegate {
|
switch (SparklePlatform.Name) {
|
||||||
switch (SparklePlatform.Name) {
|
|
||||||
case "GNOME":
|
case "GNOME":
|
||||||
Process.StartInfo.FileName = "xdg-open";
|
Process.StartInfo.FileName = "xdg-open";
|
||||||
break;
|
break;
|
||||||
case "OSX":
|
case "OSX":
|
||||||
Process.StartInfo.FileName = "open";
|
Process.StartInfo.FileName = "open";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Process.StartInfo.Arguments = LocalPath;
|
Process.StartInfo.Arguments = LocalPath;
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.StartInfo.FileName = "git";
|
Process.StartInfo.FileName = "git";
|
||||||
} );
|
} );
|
||||||
|
|
||||||
StuffChangedBubble.Show ();
|
StuffChangedBubble.Show ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue