Code cleanup
This commit is contained in:
parent
b22d192a0a
commit
95649fedf8
|
@ -42,7 +42,6 @@ namespace SparkleShare {
|
||||||
public string LocalPath;
|
public string LocalPath;
|
||||||
public string RemoteOriginUrl;
|
public string RemoteOriginUrl;
|
||||||
public string CurrentHash;
|
public string CurrentHash;
|
||||||
|
|
||||||
public string UserEmail;
|
public string UserEmail;
|
||||||
public string UserName;
|
public string UserName;
|
||||||
|
|
||||||
|
@ -51,181 +50,314 @@ namespace SparkleShare {
|
||||||
return Catalog.GetString (s);
|
return Catalog.GetString (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SparkleRepo (string RepoPath)
|
public SparkleRepo (string path)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
LocalPath = path;
|
||||||
|
Name = Path.GetFileName (LocalPath);
|
||||||
|
|
||||||
Process = new Process ();
|
Process = new Process ();
|
||||||
Process.EnableRaisingEvents = true;
|
Process.EnableRaisingEvents = true;
|
||||||
Process.StartInfo.RedirectStandardOutput = true;
|
Process.StartInfo.RedirectStandardOutput = true;
|
||||||
Process.StartInfo.UseShellExecute = false;
|
Process.StartInfo.UseShellExecute = false;
|
||||||
|
Process.StartInfo.FileName = "git";
|
||||||
// Get the repository's path, example: "/home/user/SparkleShare/repo"
|
|
||||||
LocalPath = RepoPath;
|
|
||||||
Process.StartInfo.WorkingDirectory = LocalPath;
|
Process.StartInfo.WorkingDirectory = LocalPath;
|
||||||
|
|
||||||
// Get user.name, example: "User Name"
|
UserName = GetUserName ();
|
||||||
UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName);
|
UserEmail = GetUserEmail ();
|
||||||
if (UnixUserInfo.RealName.Equals (""))
|
RemoteOriginUrl = GetRemoteOriginUrl ();
|
||||||
UserName = "Anonymous";
|
CurrentHash = GetCurrentHash ();
|
||||||
else
|
Domain = GetDomain (RemoteOriginUrl);
|
||||||
UserName = UnixUserInfo.RealName;
|
|
||||||
|
|
||||||
// Get user.email, example: "user@github.com"
|
|
||||||
UserEmail = "not.set@git-scm.com";
|
|
||||||
Process.StartInfo.FileName = "git";
|
|
||||||
Process.StartInfo.Arguments = "config --get user.email";
|
|
||||||
Process.Start ();
|
|
||||||
UserEmail = Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
// Get remote.origin.url, example: "ssh://git@github.com/user/repo"
|
|
||||||
Process.StartInfo.FileName = "git";
|
|
||||||
Process.StartInfo.Arguments = "config --get remote.origin.url";
|
|
||||||
Process.Start ();
|
|
||||||
RemoteOriginUrl = Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
// Get the repository name, example: "Project"
|
|
||||||
Name = Path.GetFileName (LocalPath);
|
|
||||||
|
|
||||||
// Get the domain, example: "github.com"
|
|
||||||
Domain = RemoteOriginUrl;
|
|
||||||
Domain = Domain.Substring (Domain.IndexOf ("@") + 1);
|
|
||||||
if (Domain.IndexOf (":") > -1)
|
|
||||||
Domain = Domain.Substring (0, Domain.IndexOf (":"));
|
|
||||||
else
|
|
||||||
Domain = Domain.Substring (0, Domain.IndexOf ("/"));
|
|
||||||
|
|
||||||
// Get hash of the current commit
|
|
||||||
Process.StartInfo.FileName = "git";
|
|
||||||
Process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
|
||||||
Process.Start ();
|
|
||||||
CurrentHash = Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
// Watch the repository's folder
|
// Watch the repository's folder
|
||||||
Watcher = new FileSystemWatcher (LocalPath);
|
Watcher = new FileSystemWatcher (LocalPath) {
|
||||||
Watcher.IncludeSubdirectories = true;
|
IncludeSubdirectories = true,
|
||||||
Watcher.EnableRaisingEvents = true;
|
EnableRaisingEvents = true,
|
||||||
Watcher.Filter = "*";
|
Filter = "*"
|
||||||
|
};
|
||||||
|
|
||||||
Watcher.Changed += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Changed += new FileSystemEventHandler (OnFileActivity);
|
||||||
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
||||||
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
||||||
|
|
||||||
// Fetch remote changes every 20 seconds
|
// Fetch remote changes every 20 seconds
|
||||||
FetchTimer = new Timer ();
|
FetchTimer = new Timer () {
|
||||||
FetchTimer.Interval = 20000;
|
Interval = 20000
|
||||||
|
};
|
||||||
|
|
||||||
FetchTimer.Elapsed += delegate {
|
FetchTimer.Elapsed += delegate {
|
||||||
Fetch ();
|
Fetch ();
|
||||||
};
|
};
|
||||||
|
|
||||||
FetchTimer.Start ();
|
// Keep a buffer that checks if there are changes and
|
||||||
|
// whether they have settled
|
||||||
BufferTimer = new Timer ();
|
BufferTimer = new Timer () {
|
||||||
BufferTimer.Interval = 4000;
|
Interval = 4000
|
||||||
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
|
||||||
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes.");
|
|
||||||
|
|
||||||
lock(ChangeLock) {
|
|
||||||
if (HasChanged) {
|
|
||||||
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
|
|
||||||
DateTime now = DateTime.UtcNow;
|
|
||||||
TimeSpan changed = new TimeSpan (now.Ticks - LastChange.Ticks);
|
|
||||||
if (changed.TotalMilliseconds > 5000) {
|
|
||||||
HasChanged = false;
|
|
||||||
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes have settled, adding.");
|
|
||||||
AddCommitAndPush ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BufferTimer.Elapsed += delegate (object o, ElapsedEventArgs args) {
|
||||||
|
CheckForChanges ();
|
||||||
|
};
|
||||||
|
|
||||||
|
FetchTimer.Start ();
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
|
||||||
// Add everything that changed
|
// Add everything that changed
|
||||||
// since SparkleShare was stopped
|
// since SparkleShare was stopped
|
||||||
|
|
||||||
AddCommitAndPush ();
|
AddCommitAndPush ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Nothing going on...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetDomain (string url)
|
||||||
|
{
|
||||||
|
|
||||||
|
string domain;
|
||||||
|
|
||||||
|
domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
|
||||||
|
if (domain.IndexOf (":") > -1)
|
||||||
|
domain = domain.Substring (0, domain.IndexOf (":"));
|
||||||
|
else
|
||||||
|
domain = domain.Substring (0, domain.IndexOf ("/"));
|
||||||
|
|
||||||
|
return domain;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets hash of the current commit
|
||||||
|
public string GetCurrentHash ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string current_hash;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
current_hash = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return current_hash;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the user's name, example: "User Name"
|
||||||
|
public string GetUserName ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string user_name;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get user.name";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
user_name = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
if (user_name.Equals ("")) {
|
||||||
|
|
||||||
|
UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName);
|
||||||
|
|
||||||
|
if (unix_user_info.RealName.Equals (""))
|
||||||
|
user_name = "???";
|
||||||
|
else
|
||||||
|
user_name = unix_user_info.RealName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return user_name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the user's email, example: "person@gnome.org"
|
||||||
|
public string GetUserEmail ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string user_email;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get user.email";
|
||||||
|
process.Start ();
|
||||||
|
user_email = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return user_email;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project"
|
||||||
|
public string GetRemoteOriginUrl ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string remote_origin_url;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get remote.origin.url";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
remote_origin_url = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return remote_origin_url;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CheckForChanges ()
|
||||||
|
{
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Checking for changes.");
|
||||||
|
|
||||||
|
lock (ChangeLock) {
|
||||||
|
|
||||||
|
if (HasChanged) {
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes found, checking if settled.");
|
||||||
|
|
||||||
|
DateTime now = DateTime.UtcNow;
|
||||||
|
TimeSpan changed = new TimeSpan (now.Ticks - LastChange.Ticks);
|
||||||
|
|
||||||
|
if (changed.TotalMilliseconds > 5000) {
|
||||||
|
HasChanged = false;
|
||||||
|
SparkleHelpers.DebugInfo ("Buffer", "[" + Name + "] Changes have settled, adding files...");
|
||||||
|
AddCommitAndPush ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Starts a time buffer when something changes
|
// Starts a time buffer when something changes
|
||||||
private void OnFileActivity (object o, FileSystemEventArgs args)
|
private 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 + "] " + wct.ToString () + " '" + args.Name + "'");
|
SparkleHelpers.DebugInfo ("Event", "[" + Name + "] " + wct.ToString () + " '" + args.Name + "'");
|
||||||
|
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
lock(ChangeLock) {
|
|
||||||
|
lock (ChangeLock) {
|
||||||
LastChange = DateTime.UtcNow;
|
LastChange = DateTime.UtcNow;
|
||||||
HasChanged = true;
|
HasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// When there are changes we generally want to Add, Commit and Push
|
// When there are changes we generally want to Add, Commit and Push
|
||||||
// so this method does them all with appropriate timers, etc switched off
|
// so this method does them all with appropriate timers, etc. switched off
|
||||||
public void AddCommitAndPush ()
|
public void AddCommitAndPush ()
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
BufferTimer.Stop ();
|
BufferTimer.Stop ();
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
|
|
||||||
Add ();
|
Add ();
|
||||||
string Message = FormatCommitMessage ();
|
string message = FormatCommitMessage ();
|
||||||
if (!Message.Equals ("")) {
|
|
||||||
Commit (Message);
|
if (!message.Equals ("")) {
|
||||||
|
Commit (message);
|
||||||
Fetch ();
|
Fetch ();
|
||||||
Push ();
|
Push ();
|
||||||
// SparkleHelpers.CheckForUnicorns (Message);
|
CheckForUnicorns (message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally {
|
} finally {
|
||||||
|
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Stages the made changes
|
// Stages the made changes
|
||||||
private void Add ()
|
private void Add ()
|
||||||
{
|
{
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Staging changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "add --all";
|
Process.StartInfo.Arguments = "add --all";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");
|
||||||
|
|
||||||
// SparkleUI.NotificationIcon.SetSyncingState ();
|
// SparkleUI.NotificationIcon.SetSyncingState ();
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 ()
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
FetchTimer.Stop ();
|
FetchTimer.Stop ();
|
||||||
|
|
||||||
// SparkleUI.NotificationIcon.SetSyncingState ();
|
// SparkleUI.NotificationIcon.SetSyncingState ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "fetch -v";
|
Process.StartInfo.Arguments = "fetch -v";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string Output = Process.StandardOutput.ReadToEnd ().Trim (); // TODO: This doesn't work :(
|
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
|
string Output = Process.StandardOutput.ReadToEnd ().Trim (); // TODO: This doesn't work :(
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
||||||
|
|
||||||
if (!Output.Contains ("up to date"))
|
if (!Output.Contains ("up to date"))
|
||||||
Rebase ();
|
Rebase ();
|
||||||
|
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
}
|
|
||||||
finally {
|
} finally {
|
||||||
|
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
|
@ -235,47 +367,50 @@ namespace SparkleShare {
|
||||||
Watcher.EnableRaisingEvents = false;
|
Watcher.EnableRaisingEvents = false;
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "rebase origin";
|
Process.StartInfo.Arguments = "rebase origin";
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes rebased.");
|
||||||
string Output = Process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
string output = Process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
// Show notification if there are updates
|
// Show notification if there are updates
|
||||||
if (!Output.Contains ("up to date")) {
|
if (!output.Contains ("up to date")) {
|
||||||
|
|
||||||
if (Output.Contains ("Failed to merge")) {
|
if (output.Contains ("Failed to merge")) {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Resolving conflict...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Resolving conflict...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "status";
|
Process.StartInfo.Arguments = "status";
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Output = Process.StandardOutput.ReadToEnd ().Trim ();
|
output = Process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
string [] lines = Regex.Split (output, "\n");
|
||||||
|
|
||||||
foreach (string Line in Regex.Split (Output, "\n")) {
|
foreach (string line in lines) {
|
||||||
|
|
||||||
if (Line.Contains ("needs merge")) {
|
if (line.Contains ("needs merge")) {
|
||||||
|
|
||||||
string ProblemFileName = Line.Substring (Line.IndexOf (": needs merge"));
|
string problem_file_name = line.Substring (line.IndexOf (": needs merge"));
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "checkout --ours " + ProblemFileName;
|
Process.StartInfo.Arguments = "checkout --ours " + problem_file_name;
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
DateTime DateTime = new DateTime ();
|
|
||||||
string TimeStamp = DateTime.Now.ToString ("H:mm d MMM yyyy");
|
string TimeStamp = DateTime.Now.ToString ("H:mm d MMM yyyy");
|
||||||
|
|
||||||
File.Move (ProblemFileName,
|
File.Move (problem_file_name,
|
||||||
ProblemFileName + " (" + UserName + ", " + TimeStamp + ")");
|
problem_file_name + " (" + UserName + ", " + TimeStamp + ")");
|
||||||
|
|
||||||
Process.StartInfo.Arguments
|
Process.StartInfo.Arguments
|
||||||
= "checkout --theirs " + ProblemFileName;
|
= "checkout --theirs " + problem_file_name;
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
string ConflictTitle = "A mid-air collision happened!\n";
|
string conflict_title = "A mid-air collision happened!\n";
|
||||||
string ConflictSubtext = "Don't worry, SparkleShare made\na copy of the conflicting files.";
|
string conflict_subtext = "Don't worry, SparkleShare made\na copy of the conflicting files.";
|
||||||
|
|
||||||
// SparkleBubble ConflictBubble =
|
// SparkleBubble ConflictBubble =
|
||||||
// new SparkleBubble(_(ConflictTitle), _(ConflictSubtext));
|
// new SparkleBubble(_(ConflictTitle), _(ConflictSubtext));
|
||||||
|
@ -291,7 +426,9 @@ namespace SparkleShare {
|
||||||
Process.StartInfo.Arguments = "rebase --continue";
|
Process.StartInfo.Arguments = "rebase --continue";
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved.");
|
||||||
|
|
||||||
Push ();
|
Push ();
|
||||||
Fetch ();
|
Fetch ();
|
||||||
|
|
||||||
|
@ -345,34 +482,52 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
Watcher.EnableRaisingEvents = true;
|
Watcher.EnableRaisingEvents = true;
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Nothing going on...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
||||||
|
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignores Repos, dotfiles, swap files and the like.
|
|
||||||
private bool ShouldIgnore (string FileName) {
|
// Ignores repos, dotfiles, swap files and the like.
|
||||||
if (FileName.Substring (0, 1).Equals (".") ||
|
private bool ShouldIgnore (string file_name) {
|
||||||
FileName.Contains (".lock") ||
|
|
||||||
FileName.Contains (".git") ||
|
if (file_name.Substring (0, 1).Equals (".") ||
|
||||||
FileName.Contains ("/.") ||
|
file_name.Contains (".lock") ||
|
||||||
Directory.Exists (LocalPath + FileName))
|
file_name.Contains (".git") ||
|
||||||
|
file_name.Contains ("/.") ||
|
||||||
|
Directory.Exists (LocalPath + file_name)) {
|
||||||
|
|
||||||
return true; // Yes, ignore it.
|
return true; // Yes, ignore it.
|
||||||
else if (FileName.Length > 3 && FileName.Substring (FileName.Length - 4).Equals (".swp"))
|
|
||||||
return true;
|
} else if (file_name.Length > 3 &&
|
||||||
else return false;
|
file_name.Substring (file_name.Length - 4).Equals (".swp")) {
|
||||||
|
|
||||||
|
return true; // Yes, ignore it.
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Creates a pretty commit message based on what has changed
|
// Creates a pretty commit message based on what has changed
|
||||||
private string FormatCommitMessage ()
|
private string FormatCommitMessage ()
|
||||||
{
|
{
|
||||||
|
@ -390,70 +545,70 @@ namespace SparkleShare {
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string Output = Process.StandardOutput.ReadToEnd ();
|
string Output = Process.StandardOutput.ReadToEnd ();
|
||||||
|
|
||||||
foreach (string Line in Regex.Split (Output, "\n")) {
|
foreach (string line in Regex.Split (Output, "\n")) {
|
||||||
if (Line.IndexOf ("new file:") > -1)
|
if (line.IndexOf ("new file:") > -1)
|
||||||
FilesAdded++;
|
FilesAdded++;
|
||||||
if (Line.IndexOf ("modified:") > -1)
|
if (line.IndexOf ("modified:") > -1)
|
||||||
FilesEdited++;
|
FilesEdited++;
|
||||||
if (Line.IndexOf ("renamed:") > -1)
|
if (line.IndexOf ("renamed:") > -1)
|
||||||
FilesRenamed++;
|
FilesRenamed++;
|
||||||
if (Line.IndexOf ("deleted:") > -1)
|
if (line.IndexOf ("deleted:") > -1)
|
||||||
FilesDeleted++;
|
FilesDeleted++;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string Line in Regex.Split (Output, "\n")) {
|
foreach (string line in Regex.Split (Output, "\n")) {
|
||||||
|
|
||||||
// Format message for when files are added,
|
// Format message for when files are added,
|
||||||
// example: "added 'file' and 3 more."
|
// example: "added 'file' and 3 more."
|
||||||
if (Line.IndexOf ("new file:") > -1 && !DoneAddCommit) {
|
if (line.IndexOf ("new file:") > -1 && !DoneAddCommit) {
|
||||||
DoneAddCommit = true;
|
DoneAddCommit = true;
|
||||||
if (FilesAdded > 1)
|
if (FilesAdded > 1)
|
||||||
return "added ‘" +
|
return "added ‘" +
|
||||||
Line.Replace ("#\tnew file:", "").Trim () +
|
line.Replace ("#\tnew file:", "").Trim () +
|
||||||
"’\nand " + (FilesAdded - 1) + " more.";
|
"’\nand " + (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,
|
||||||
// example: "edited 'file'."
|
// example: "edited 'file'."
|
||||||
if (Line.IndexOf ("modified:") > -1 && !DoneEditCommit) {
|
if (line.IndexOf ("modified:") > -1 && !DoneEditCommit) {
|
||||||
DoneEditCommit = true;
|
DoneEditCommit = true;
|
||||||
if (FilesEdited > 1)
|
if (FilesEdited > 1)
|
||||||
return "edited ‘" +
|
return "edited ‘" +
|
||||||
Line.Replace ("#\tmodified:", "").Trim () +
|
line.Replace ("#\tmodified:", "").Trim () +
|
||||||
"’\nand " + (FilesEdited - 1) + " more.";
|
"’\nand " + (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,
|
||||||
// example: "deleted 'file'."
|
// example: "deleted 'file'."
|
||||||
if (Line.IndexOf ("deleted:") > -1 && !DoneDeleteCommit) {
|
if (line.IndexOf ("deleted:") > -1 && !DoneDeleteCommit) {
|
||||||
DoneDeleteCommit = true;
|
DoneDeleteCommit = true;
|
||||||
if (FilesDeleted > 1)
|
if (FilesDeleted > 1)
|
||||||
return "deleted ‘" +
|
return "deleted ‘" +
|
||||||
Line.Replace ("#\tdeleted:", "").Trim () +
|
line.Replace ("#\tdeleted:", "").Trim () +
|
||||||
"’\nand " + (FilesDeleted - 1) + " more.";
|
"’\nand " + (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,
|
||||||
// example: "renamed 'file' to 'new name'."
|
// example: "renamed 'file' to 'new name'."
|
||||||
if (Line.IndexOf ("renamed:") > -1 && !DoneRenameCommit) {
|
if (line.IndexOf ("renamed:") > -1 && !DoneRenameCommit) {
|
||||||
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 ‘") + "’.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
|
|
||||||
SparkleRepo = sparkle_repo;
|
SparkleRepo = sparkle_repo;
|
||||||
SetSizeRequest (640, 480);
|
SetSizeRequest (550, 720);
|
||||||
SetPosition (WindowPosition.Center);
|
SetPosition (WindowPosition.Center);
|
||||||
BorderWidth = 12;
|
BorderWidth = 12;
|
||||||
|
|
||||||
|
@ -54,9 +54,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
LayoutVertical.PackStart (CreateEventLog (), true, true, 0);
|
LayoutVertical.PackStart (CreateEventLog (), true, true, 0);
|
||||||
|
|
||||||
HButtonBox dialog_buttons = new HButtonBox ();
|
HButtonBox dialog_buttons = new HButtonBox {
|
||||||
dialog_buttons.Layout = ButtonBoxStyle.Edge;
|
Layout = ButtonBoxStyle.Edge,
|
||||||
dialog_buttons.BorderWidth = 0;
|
BorderWidth = 0
|
||||||
|
};
|
||||||
|
|
||||||
Button open_folder_button = new Button (_("Open Folder"));
|
Button open_folder_button = new Button (_("Open Folder"));
|
||||||
open_folder_button.Clicked += delegate (object o, EventArgs args) {
|
open_folder_button.Clicked += delegate (object o, EventArgs args) {
|
||||||
|
@ -79,7 +80,7 @@ namespace SparkleShare {
|
||||||
LayoutVertical.PackStart (dialog_buttons, false, false, 0);
|
LayoutVertical.PackStart (dialog_buttons, false, false, 0);
|
||||||
|
|
||||||
Add (LayoutVertical);
|
Add (LayoutVertical);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ namespace SparkleShare {
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath;
|
process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath;
|
||||||
process.StartInfo.FileName = "git";
|
process.StartInfo.FileName = "git";
|
||||||
process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -25";
|
process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -50";
|
||||||
|
|
||||||
string output = "";
|
string output = "";
|
||||||
|
|
||||||
|
@ -185,7 +186,12 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label date_label = new Label ();
|
Label date_label = new Label ("") {
|
||||||
|
UseMarkup = true,
|
||||||
|
Xalign = 0,
|
||||||
|
Xpad = 9,
|
||||||
|
Ypad = 9
|
||||||
|
};
|
||||||
|
|
||||||
DateTime today = DateTime.Now;
|
DateTime today = DateTime.Now;
|
||||||
DateTime yesterday = DateTime.Now.AddDays (-1);
|
DateTime yesterday = DateTime.Now.AddDays (-1);
|
||||||
|
@ -194,39 +200,32 @@ namespace SparkleShare {
|
||||||
today.Month == activity_day.DateTime.Month &&
|
today.Month == activity_day.DateTime.Month &&
|
||||||
today.Year == activity_day.DateTime.Year) {
|
today.Year == activity_day.DateTime.Year) {
|
||||||
|
|
||||||
date_label.Text = "<b>Today</b>";
|
date_label.Markup = "<b>Today</b>";
|
||||||
|
|
||||||
} else if (yesterday.Day == activity_day.DateTime.Day &&
|
} else if (yesterday.Day == activity_day.DateTime.Day &&
|
||||||
yesterday.Month == activity_day.DateTime.Month &&
|
yesterday.Month == activity_day.DateTime.Month &&
|
||||||
yesterday.Year == activity_day.DateTime.Year) {
|
yesterday.Year == activity_day.DateTime.Year) {
|
||||||
|
|
||||||
date_label.Text = "<b>Yesterday</b>";
|
date_label.Markup = "<b>Yesterday</b>";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
date_label.Text = "<b>" + activity_day.DateTime.ToString ("ddd MMM d, yyyy") + "</b>";
|
date_label.Markup = "<b>" + activity_day.DateTime.ToString ("ddd MMM d, yyyy") + "</b>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
date_label.UseMarkup = true;
|
|
||||||
date_label.Xalign = 0;
|
|
||||||
date_label.Xpad = 9;
|
|
||||||
date_label.Ypad = 9;
|
|
||||||
|
|
||||||
layout_vertical.PackStart (date_label, true, true, 0);
|
layout_vertical.PackStart (date_label, true, true, 0);
|
||||||
|
|
||||||
IconView icon_view = new IconView (list_store);
|
IconView icon_view = new IconView (list_store) {
|
||||||
|
ItemWidth = 480,
|
||||||
icon_view.PixbufColumn = 0;
|
MarkupColumn = 1,
|
||||||
icon_view.MarkupColumn = 1;
|
Orientation = Orientation.Horizontal,
|
||||||
|
PixbufColumn = 0,
|
||||||
icon_view.Orientation = Orientation.Horizontal;
|
Spacing = 9
|
||||||
icon_view.ItemWidth = 550;
|
};
|
||||||
icon_view.Spacing = 9;
|
|
||||||
|
|
||||||
layout_vertical.PackStart (icon_view);
|
layout_vertical.PackStart (icon_view);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
ScrolledWindow = new ScrolledWindow ();
|
||||||
|
|
Loading…
Reference in a new issue