lib: Add separate SparkleGit and SparkleGitBin objects derived from SparkleProcess
This commit is contained in:
parent
a0b3c101d9
commit
799314ceee
|
@ -31,6 +31,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
private SparkleGit git;
|
||||
private string crypto_salt = "e0d592768d7cf99a"; // TODO: Make unique per repo
|
||||
private bool use_mass_storage = false; // TODO
|
||||
|
||||
|
||||
public SparkleFetcher (string server, string required_fingerprint, string remote_path,
|
||||
|
@ -210,7 +211,7 @@ namespace SparkleLib.Git {
|
|||
string git_attributes_file_path = SparkleHelpers.CombineMore (
|
||||
TargetFolder, ".git", "info", "attributes");
|
||||
|
||||
File.WriteAllText (git_attributes_file_path, "* filter=crypto");
|
||||
File.AppendAllText (git_attributes_file_path, "\n* filter=crypto");
|
||||
|
||||
|
||||
// Store the password
|
||||
|
@ -303,6 +304,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
string n = Environment.NewLine;
|
||||
|
||||
// TODO: Use commands to configure
|
||||
config = config.Replace ("[core]" + n,
|
||||
"[core]" + n +
|
||||
"\tquotepath = false" + n + // Show special characters in the logs
|
||||
|
@ -326,6 +328,57 @@ namespace SparkleLib.Git {
|
|||
|
||||
// Write the config to the file
|
||||
File.WriteAllText (repo_config_file_path, config);
|
||||
|
||||
if (this.use_mass_storage) {
|
||||
SparkleGit git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config filter.bin.clean \"git bin clean %f\"");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config filter.bin.smudge \"git bin smudge\"");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config git-bin.s3bucket \"your bucket name\"");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config git-bin.s3key \"your key\"");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config git-bin.s3secretKey \"your secret key\"");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config git-bin.chunkSize 1m");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
|
||||
|
||||
git_config = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config core.bigFileThreshold 2g");
|
||||
|
||||
git_config.Start ();
|
||||
git_config.WaitForExit ();
|
||||
}
|
||||
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "Added configuration to '" + repo_config_file_path + "'");
|
||||
}
|
||||
|
||||
|
@ -349,9 +402,13 @@ namespace SparkleLib.Git {
|
|||
// File that lists the files we want don't want git to compress.
|
||||
// Not compressing the already compressed files saves us memory
|
||||
// usage and increases speed
|
||||
string no_compression_rules_file_path = Path.Combine (info.FullName, "attributes");
|
||||
writer = new StreamWriter (no_compression_rules_file_path);
|
||||
string git_attributes_file_path = Path.Combine (info.FullName, "attributes");
|
||||
writer = new StreamWriter (git_attributes_file_path);
|
||||
|
||||
if (this.use_mass_storage) {
|
||||
writer.WriteLine ("* filter=bin binary");
|
||||
|
||||
} else {
|
||||
// Images
|
||||
writer.WriteLine ("*.jpg -delta");
|
||||
writer.WriteLine ("*.jpeg -delta");
|
||||
|
@ -437,6 +494,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
writer.WriteLine ("*.tar -delta");
|
||||
writer.WriteLine ("*.TAR -delta");
|
||||
}
|
||||
|
||||
writer.Close ();
|
||||
}
|
||||
|
|
|
@ -22,18 +22,61 @@ using SparkleLib;
|
|||
|
||||
namespace SparkleLib.Git {
|
||||
|
||||
public class SparkleGit : Process {
|
||||
public abstract class SparkleProcess : Process {
|
||||
|
||||
public static string ExecPath = null;
|
||||
public static string Path = null;
|
||||
|
||||
|
||||
public SparkleGit (string path, string args) : base ()
|
||||
public SparkleProcess (string path, string args) : base ()
|
||||
{
|
||||
Path = LocateGit ();
|
||||
StartInfo.FileName = path;
|
||||
StartInfo.Arguments = args;
|
||||
}
|
||||
|
||||
|
||||
new public void Start ()
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Cmd | " + System.IO.Path.GetFileName (StartInfo.WorkingDirectory),
|
||||
System.IO.Path.GetFileName (StartInfo.FileName) + " " + StartInfo.Arguments);
|
||||
|
||||
try {
|
||||
base.Start ();
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Cmd", "Couldn't execute command: " + e.Message);
|
||||
Environment.Exit (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected string LocateCommand (string name)
|
||||
{
|
||||
string [] possible_command_paths = new string [] {
|
||||
"/usr/bin/" + name,
|
||||
"/usr/local/bin/" + name,
|
||||
"/opt/local/bin/" + name
|
||||
};
|
||||
|
||||
foreach (string path in possible_command_paths) {
|
||||
if (File.Exists (path))
|
||||
return path;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SparkleGit : SparkleProcess {
|
||||
|
||||
public static string ExecPath;
|
||||
public static string GitPath;
|
||||
|
||||
|
||||
public SparkleGit (string path, string args) : base (path, args)
|
||||
{
|
||||
if (string.IsNullOrEmpty (GitPath))
|
||||
GitPath = LocateCommand ("git");
|
||||
|
||||
EnableRaisingEvents = true;
|
||||
StartInfo.FileName = Path;
|
||||
StartInfo.FileName = GitPath;
|
||||
StartInfo.RedirectStandardOutput = true;
|
||||
StartInfo.UseShellExecute = false;
|
||||
StartInfo.WorkingDirectory = path;
|
||||
|
@ -44,40 +87,26 @@ namespace SparkleLib.Git {
|
|||
else
|
||||
StartInfo.Arguments = "--exec-path=\"" + ExecPath + "\" " + args;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
new public void Start ()
|
||||
public class SparkleGitBin : SparkleProcess {
|
||||
|
||||
public static string GitBinPath;
|
||||
|
||||
|
||||
public SparkleGitBin (string path, string args) : base (path, args)
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Cmd | " + System.IO.Path.GetFileName (StartInfo.WorkingDirectory),
|
||||
"git " + StartInfo.Arguments);
|
||||
if (string.IsNullOrEmpty (GitBinPath))
|
||||
GitBinPath = LocateCommand ("git-bin");
|
||||
|
||||
try {
|
||||
base.Start ();
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Cmd", "There's a problem running Git: " + e.Message);
|
||||
Environment.Exit (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string LocateGit ()
|
||||
{
|
||||
if (!string.IsNullOrEmpty (Path))
|
||||
return Path;
|
||||
|
||||
string [] possible_git_paths = new string [] {
|
||||
"/usr/bin/git",
|
||||
"/usr/local/bin/git",
|
||||
"/opt/local/bin/git",
|
||||
"/usr/local/git/bin/git"
|
||||
};
|
||||
|
||||
foreach (string path in possible_git_paths)
|
||||
if (File.Exists (path))
|
||||
return path;
|
||||
|
||||
return "git";
|
||||
EnableRaisingEvents = true;
|
||||
StartInfo.FileName = GitBinPath;
|
||||
StartInfo.RedirectStandardOutput = true;
|
||||
StartInfo.UseShellExecute = false;
|
||||
StartInfo.WorkingDirectory = path;
|
||||
StartInfo.CreateNoWindow = true;
|
||||
StartInfo.Arguments = args;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,15 @@ namespace SparkleLib.Git {
|
|||
|
||||
public class SparkleRepo : SparkleRepoBase {
|
||||
|
||||
private bool author_set = false;
|
||||
private bool author_set;
|
||||
private bool use_mass_storage;
|
||||
|
||||
|
||||
public SparkleRepo (string path) : base (path)
|
||||
{
|
||||
//this.use_mass_storage =
|
||||
//SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (Name, "use_mass_storage")
|
||||
// .Equals (bool.TrueString);
|
||||
}
|
||||
|
||||
|
||||
|
@ -189,6 +193,17 @@ namespace SparkleLib.Git {
|
|||
Commit (message);
|
||||
}
|
||||
|
||||
// TODO: set remote_url from config
|
||||
|
||||
if (this.use_mass_storage) {
|
||||
/* SparkleGit git_bin = new SparkleGitBin (LocalPath, "push");
|
||||
|
||||
git_bin.Start ();
|
||||
git_bin.WaitForExit ();
|
||||
*/ // TODO: Progress
|
||||
}
|
||||
|
||||
|
||||
SparkleGit git = new SparkleGit (LocalPath,
|
||||
"push --progress " + // Redirects progress stats to standarderror
|
||||
"\"" + RemoteUrl + "\" master");
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace SparkleShare {
|
|||
|
||||
|
||||
// Let's use the bundled git first
|
||||
SparkleLib.Git.SparkleGit.Path =
|
||||
SparkleLib.Git.SparkleGit.GitPath =
|
||||
Path.Combine (NSBundle.MainBundle.ResourcePath,
|
||||
"git", "libexec", "git-core", "git");
|
||||
|
||||
|
|
Loading…
Reference in a new issue