lib: code cleanup
This commit is contained in:
parent
6271216e1b
commit
e8af571c2b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -48,6 +48,7 @@ SparkleLib/Defines.cs
|
||||||
SparkleLib/windows/Defines.cs
|
SparkleLib/windows/Defines.cs
|
||||||
SparkleLib/windows/GlobalAssemblyInfo.cs
|
SparkleLib/windows/GlobalAssemblyInfo.cs
|
||||||
SparkleShare/Linux/sparkleshare
|
SparkleShare/Linux/sparkleshare
|
||||||
|
SparkleShare/Mac/git
|
||||||
po/sparkleshare.pot
|
po/sparkleshare.pot
|
||||||
SparkleShare/Linux/Nautilus/sparkleshare-nautilus-extension.py
|
SparkleShare/Linux/Nautilus/sparkleshare-nautilus-extension.py
|
||||||
SparkleShare/Linux/Nautilus/sparkleshare-nautilus3-extension.py
|
SparkleShare/Linux/Nautilus/sparkleshare-nautilus3-extension.py
|
||||||
|
|
|
@ -54,10 +54,11 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
public override double Size {
|
public override double Size {
|
||||||
get {
|
get {
|
||||||
string file_path = new string [] {LocalPath, ".git", "repo_size"}.Combine ();
|
string file_path = new string [] { LocalPath, ".git", "repo_size" }.Combine ();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return double.Parse (File.ReadAllText (file_path));
|
string size = File.ReadAllText (file_path);
|
||||||
|
return double.Parse (size);
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -68,10 +69,11 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
public override double HistorySize {
|
public override double HistorySize {
|
||||||
get {
|
get {
|
||||||
string file_path = new string [] {LocalPath, ".git", "repo_history_size"}.Combine ();
|
string file_path = new string [] { LocalPath, ".git", "repo_history_size" }.Combine ();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return double.Parse (File.ReadAllText (file_path));
|
string size = File.ReadAllText (file_path);
|
||||||
|
return double.Parse (size);
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -85,8 +87,8 @@ namespace SparkleLib.Git {
|
||||||
double size = CalculateSizes (new DirectoryInfo (LocalPath));
|
double size = CalculateSizes (new DirectoryInfo (LocalPath));
|
||||||
double history_size = CalculateSizes (new DirectoryInfo (Path.Combine (LocalPath, ".git")));
|
double history_size = CalculateSizes (new DirectoryInfo (Path.Combine (LocalPath, ".git")));
|
||||||
|
|
||||||
string size_file_path = new string [] {LocalPath, ".git", "repo_size"}.Combine ();
|
string size_file_path = new string [] { LocalPath, ".git", "repo_size" }.Combine ();
|
||||||
string history_size_file_path = new string [] {LocalPath, ".git", "repo_history_size"}.Combine ();
|
string history_size_file_path = new string [] { LocalPath, ".git", "repo_history_size" }.Combine ();
|
||||||
|
|
||||||
File.WriteAllText (size_file_path, size.ToString ());
|
File.WriteAllText (size_file_path, size.ToString ());
|
||||||
File.WriteAllText (history_size_file_path, history_size.ToString ());
|
File.WriteAllText (history_size_file_path, history_size.ToString ());
|
||||||
|
@ -113,6 +115,7 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
string path = line.Substring (3);
|
string path = line.Substring (3);
|
||||||
path = path.Trim ("\"".ToCharArray ());
|
path = path.Trim ("\"".ToCharArray ());
|
||||||
|
|
||||||
file_paths.Add (path);
|
file_paths.Add (path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,16 +167,13 @@ namespace SparkleLib.Git {
|
||||||
string remote_revision = output.Substring (0, 40);
|
string remote_revision = output.Substring (0, 40);
|
||||||
|
|
||||||
if (!remote_revision.StartsWith (current_revision)) {
|
if (!remote_revision.StartsWith (current_revision)) {
|
||||||
SparkleHelpers.DebugInfo ("Git",
|
SparkleHelpers.DebugInfo ("Git", Name + " | Remote changes found, local: " +
|
||||||
Name + " | Remote changes detected (local: " +
|
current_revision + ", remote: " + remote_revision);
|
||||||
current_revision + ", remote: " + remote_revision + ")");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SparkleHelpers.DebugInfo ("Git",
|
SparkleHelpers.DebugInfo ("Git", Name + " | No remote changes, local+remote: " + current_revision);
|
||||||
Name + " | No remote changes detected (local+remote: " + current_revision + ")");
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
this.remote_url_is_set = true;
|
this.remote_url_is_set = true;
|
||||||
}
|
}
|
||||||
Console.WriteLine (this.use_git_bin);
|
|
||||||
SparkleGitBin git_bin = new SparkleGitBin (LocalPath, "push");
|
SparkleGitBin git_bin = new SparkleGitBin (LocalPath, "push");
|
||||||
git_bin.Start ();
|
git_bin.Start ();
|
||||||
git_bin.WaitForExit ();
|
git_bin.WaitForExit ();
|
||||||
|
@ -334,10 +334,8 @@ namespace SparkleLib.Git {
|
||||||
if (git.ExitCode == 0) {
|
if (git.ExitCode == 0) {
|
||||||
Rebase ();
|
Rebase ();
|
||||||
|
|
||||||
File.SetAttributes (
|
string identifier_file_path = Path.Combine (LocalPath, ".sparkleshare");
|
||||||
Path.Combine (LocalPath, ".sparkleshare"),
|
File.SetAttributes (identifier_file_path, FileAttributes.Hidden);
|
||||||
FileAttributes.Hidden
|
|
||||||
);
|
|
||||||
|
|
||||||
ChangeSets = GetChangeSets ();
|
ChangeSets = GetChangeSets ();
|
||||||
ClearCache ();
|
ClearCache ();
|
||||||
|
@ -368,23 +366,17 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
public override bool HasUnsyncedChanges {
|
public override bool HasUnsyncedChanges {
|
||||||
get {
|
get {
|
||||||
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath,
|
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath, ".git", "has_unsynced_changes");
|
||||||
".git", "has_unsynced_changes");
|
|
||||||
|
|
||||||
return File.Exists (unsynced_file_path);
|
return File.Exists (unsynced_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath,
|
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath, ".git", "has_unsynced_changes");
|
||||||
".git", "has_unsynced_changes");
|
|
||||||
|
|
||||||
if (value) {
|
if (value)
|
||||||
if (!File.Exists (unsynced_file_path))
|
File.WriteAllText (unsynced_file_path, "");
|
||||||
File.Create (unsynced_file_path).Close ();
|
else
|
||||||
|
|
||||||
} else {
|
|
||||||
File.Delete (unsynced_file_path);
|
File.Delete (unsynced_file_path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,24 +654,19 @@ namespace SparkleLib.Git {
|
||||||
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
|
change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
|
||||||
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
|
change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);
|
||||||
|
|
||||||
|
|
||||||
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
||||||
|
|
||||||
foreach (string entry_line in entry_lines) {
|
foreach (string entry_line in entry_lines) {
|
||||||
if (entry_line.StartsWith (":")) {
|
if (entry_line.StartsWith (":")) {
|
||||||
|
|
||||||
string change_type = entry_line [37].ToString ();
|
string change_type = entry_line [37].ToString ();
|
||||||
string file_path = entry_line.Substring (39);
|
string file_path = entry_line.Substring (39);
|
||||||
|
|
||||||
// Handle filepath with special characters
|
// Handle filepath with special characters
|
||||||
file_path = EnsureSpecialCharacters (file_path);
|
file_path = EnsureSpecialCharacters (file_path);
|
||||||
|
|
||||||
|
|
||||||
string to_file_path;
|
string to_file_path;
|
||||||
|
|
||||||
if (file_path.EndsWith (".empty"))
|
if (file_path.EndsWith (".empty"))
|
||||||
file_path = file_path.Substring (0,
|
file_path = file_path.Substring (0, file_path.Length - ".empty".Length);
|
||||||
file_path.Length - ".empty".Length);
|
|
||||||
|
|
||||||
if (file_path.Equals (".sparkleshare"))
|
if (file_path.Equals (".sparkleshare"))
|
||||||
continue;
|
continue;
|
||||||
|
@ -863,6 +850,7 @@ namespace SparkleLib.Git {
|
||||||
try {
|
try {
|
||||||
File.WriteAllText (Path.Combine (path, ".empty"), "I'm a folder!");
|
File.WriteAllText (Path.Combine (path, ".empty"), "I'm a folder!");
|
||||||
File.SetAttributes (Path.Combine (path, ".empty"), FileAttributes.Hidden);
|
File.SetAttributes (Path.Combine (path, ".empty"), FileAttributes.Hidden);
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
SparkleHelpers.DebugInfo ("Git", Name + " | Failed adding empty folder " + path);
|
SparkleHelpers.DebugInfo ("Git", Name + " | Failed adding empty folder " + path);
|
||||||
}
|
}
|
||||||
|
@ -878,7 +866,7 @@ namespace SparkleLib.Git {
|
||||||
// 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 ()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
string message = "";
|
string message = "";
|
||||||
|
|
||||||
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
|
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
|
||||||
|
@ -894,8 +882,8 @@ namespace SparkleLib.Git {
|
||||||
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
|
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
|
||||||
string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).Trim ("\"".ToCharArray ());
|
string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).Trim ("\"".ToCharArray ());
|
||||||
|
|
||||||
message += "- ‘" + EnsureSpecialCharacters (path) + "’\n";
|
message += "< ‘" + EnsureSpecialCharacters (path) + "’\n";
|
||||||
message += "+ ‘" + EnsureSpecialCharacters (moved_to_path) + "’\n";
|
message += "> ‘" + EnsureSpecialCharacters (moved_to_path) + "’\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (line.StartsWith ("M")) {
|
if (line.StartsWith ("M")) {
|
||||||
|
@ -927,10 +915,7 @@ namespace SparkleLib.Git {
|
||||||
// Recursively gets a folder's size in bytes
|
// Recursively gets a folder's size in bytes
|
||||||
private double CalculateSizes (DirectoryInfo parent)
|
private double CalculateSizes (DirectoryInfo parent)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists (parent.FullName))
|
if (!Directory.Exists (parent.FullName) || parent.Name.Equals ("rebase-apply"))
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (parent.Name.Equals ("rebase-apply"))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
double size = 0;
|
double size = 0;
|
||||||
|
|
Loading…
Reference in a new issue