2011-06-01 23:08:05 +00:00
|
|
|
// SparkleShare, a collaboration and sharing tool.
|
2011-05-16 20:19:58 +00:00
|
|
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
2013-10-11 15:13:46 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
2011-05-16 20:19:58 +00:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2013-10-11 15:13:46 +00:00
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Threading;
|
2012-02-28 13:34:15 +00:00
|
|
|
using SparkleLib;
|
2011-05-16 20:19:58 +00:00
|
|
|
|
2012-03-01 17:02:52 +00:00
|
|
|
namespace SparkleLib.Git {
|
2011-05-16 20:19:58 +00:00
|
|
|
|
2013-03-24 22:52:05 +00:00
|
|
|
public class SparkleFetcher : SparkleFetcherSSH {
|
2011-05-16 20:19:58 +00:00
|
|
|
|
2011-08-26 20:47:46 +00:00
|
|
|
private SparkleGit git;
|
2012-06-29 15:44:02 +00:00
|
|
|
private bool use_git_bin;
|
2012-09-29 21:57:35 +00:00
|
|
|
private string cached_salt;
|
|
|
|
|
2013-08-25 16:46:06 +00:00
|
|
|
private Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
|
|
|
private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
2012-09-29 21:57:35 +00:00
|
|
|
private string crypto_salt {
|
|
|
|
get {
|
|
|
|
if (!string.IsNullOrEmpty (this.cached_salt))
|
|
|
|
return this.cached_salt;
|
|
|
|
|
|
|
|
// Check if the repo's salt is stored in a branch...
|
2012-11-27 21:57:05 +00:00
|
|
|
SparkleGit git = new SparkleGit (TargetFolder, "ls-remote --heads");
|
|
|
|
string branches = git.StartAndReadStandardOutput ();
|
|
|
|
Regex salt_regex = new Regex ("refs/heads/salt-([0-9a-f]+)");
|
|
|
|
Match salt_match = salt_regex.Match (branches);
|
2012-10-20 22:22:41 +00:00
|
|
|
|
2012-11-28 20:17:39 +00:00
|
|
|
if (salt_match.Success)
|
2012-11-27 21:57:05 +00:00
|
|
|
this.cached_salt = salt_match.Groups [1].Value;
|
2012-09-29 21:57:35 +00:00
|
|
|
|
|
|
|
// ...if not, create a new salt for the repo
|
|
|
|
if (string.IsNullOrEmpty (this.cached_salt)) {
|
|
|
|
this.cached_salt = GenerateCryptoSalt ();
|
|
|
|
string salt_file_path = new string [] { TargetFolder, ".git", "salt" }.Combine ();
|
|
|
|
|
2012-10-20 22:22:41 +00:00
|
|
|
// Temporarily store the salt in a file, so the Repo object can
|
2012-09-29 21:57:35 +00:00
|
|
|
// push it to a branch on the host later
|
|
|
|
File.WriteAllText (salt_file_path, this.cached_salt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.cached_salt;
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 20:47:46 +00:00
|
|
|
|
|
|
|
|
2013-01-27 19:24:36 +00:00
|
|
|
public SparkleFetcher (SparkleFetcherInfo info) : base (info)
|
2011-05-31 01:26:57 +00:00
|
|
|
{
|
2012-12-21 21:02:35 +00:00
|
|
|
if (RemoteUrl.ToString ().StartsWith ("ssh+"))
|
|
|
|
RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://")));
|
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
Uri uri = RemoteUrl;
|
2011-05-31 01:26:57 +00:00
|
|
|
|
2012-07-22 20:54:59 +00:00
|
|
|
if (!uri.Scheme.Equals ("ssh") && !uri.Scheme.Equals ("https") &&
|
|
|
|
!uri.Scheme.Equals ("http") && !uri.Scheme.Equals ("git")) {
|
2012-04-11 21:10:02 +00:00
|
|
|
|
2012-06-14 12:54:59 +00:00
|
|
|
uri = new Uri ("ssh://" + uri);
|
2012-01-13 23:47:19 +00:00
|
|
|
}
|
2011-05-31 01:26:57 +00:00
|
|
|
|
2012-10-05 19:55:57 +00:00
|
|
|
if (uri.Host.Equals ("gitorious.org") && !uri.Scheme.StartsWith ("http")) {
|
2013-01-06 18:33:55 +00:00
|
|
|
if (!uri.AbsolutePath.Equals ("/") &&
|
|
|
|
!uri.AbsolutePath.EndsWith (".git")) {
|
2011-08-26 22:49:08 +00:00
|
|
|
|
2013-01-06 18:33:55 +00:00
|
|
|
uri = new Uri ("ssh://git@gitorious.org" + uri.AbsolutePath + ".git");
|
2012-01-13 23:47:19 +00:00
|
|
|
|
|
|
|
} else {
|
2013-01-06 18:33:55 +00:00
|
|
|
uri = new Uri ("ssh://git@gitorious.org" + uri.AbsolutePath);
|
2011-09-11 20:15:08 +00:00
|
|
|
}
|
2011-05-31 01:26:57 +00:00
|
|
|
|
2012-10-05 19:55:57 +00:00
|
|
|
} else if (uri.Host.Equals ("github.com") && !uri.Scheme.StartsWith ("http")) {
|
2013-01-06 18:33:55 +00:00
|
|
|
uri = new Uri ("ssh://git@github.com" + uri.AbsolutePath);
|
2012-01-13 23:47:19 +00:00
|
|
|
|
2012-10-05 19:55:57 +00:00
|
|
|
} else if (uri.Host.Equals ("bitbucket.org") && !uri.Scheme.StartsWith ("http")) {
|
2012-06-29 15:44:02 +00:00
|
|
|
// Nothing really
|
|
|
|
|
2012-01-13 23:47:19 +00:00
|
|
|
} else {
|
2012-10-05 19:55:57 +00:00
|
|
|
if (string.IsNullOrEmpty (uri.UserInfo) && !uri.Scheme.StartsWith ("http")) {
|
2012-06-14 12:54:59 +00:00
|
|
|
if (uri.Port == -1)
|
2013-01-06 18:33:55 +00:00
|
|
|
uri = new Uri (uri.Scheme + "://storage@" + uri.Host + uri.AbsolutePath);
|
2012-06-14 12:54:59 +00:00
|
|
|
else
|
2013-01-06 18:33:55 +00:00
|
|
|
uri = new Uri (uri.Scheme + "://storage@" + uri.Host + ":" + uri.Port + uri.AbsolutePath);
|
2012-01-23 23:50:54 +00:00
|
|
|
}
|
2012-06-29 15:44:02 +00:00
|
|
|
|
2012-07-22 18:59:51 +00:00
|
|
|
this.use_git_bin = false; // TODO
|
2011-05-31 01:26:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 19:24:36 +00:00
|
|
|
RemoteUrl = uri;
|
2011-05-31 01:26:57 +00:00
|
|
|
}
|
2011-05-16 20:19:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
public override bool Fetch ()
|
|
|
|
{
|
2013-04-27 12:02:54 +00:00
|
|
|
if (!base.Fetch ())
|
|
|
|
return false;
|
|
|
|
|
2012-04-12 22:44:31 +00:00
|
|
|
if (FetchPriorHistory) {
|
2012-03-29 00:44:26 +00:00
|
|
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
2012-07-22 20:54:59 +00:00
|
|
|
"clone --progress --no-checkout \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
2012-03-29 00:44:26 +00:00
|
|
|
|
|
|
|
} else {
|
2012-07-14 15:18:29 +00:00
|
|
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
2012-07-22 20:54:59 +00:00
|
|
|
"clone --progress --no-checkout --depth=1 \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
2012-03-29 00:44:26 +00:00
|
|
|
}
|
2012-04-11 18:07:34 +00:00
|
|
|
|
2011-08-27 15:53:17 +00:00
|
|
|
this.git.StartInfo.RedirectStandardError = true;
|
2011-08-26 20:47:46 +00:00
|
|
|
this.git.Start ();
|
2011-12-18 16:10:06 +00:00
|
|
|
|
2011-08-27 15:53:17 +00:00
|
|
|
double percentage = 1.0;
|
2011-12-30 00:44:35 +00:00
|
|
|
|
|
|
|
DateTime last_change = DateTime.Now;
|
|
|
|
TimeSpan change_interval = new TimeSpan (0, 0, 0, 1);
|
|
|
|
|
2013-06-20 20:01:03 +00:00
|
|
|
try {
|
|
|
|
while (!this.git.StandardError.EndOfStream) {
|
|
|
|
string line = this.git.StandardError.ReadLine ();
|
2013-08-25 16:46:06 +00:00
|
|
|
Match match = this.progress_regex.Match (line);
|
2011-08-27 15:53:17 +00:00
|
|
|
|
2013-06-20 20:01:03 +00:00
|
|
|
double number = 0.0;
|
2013-08-25 16:46:06 +00:00
|
|
|
double speed = 0.0;
|
2013-06-20 20:01:03 +00:00
|
|
|
if (match.Success) {
|
2013-08-25 16:46:06 +00:00
|
|
|
try {
|
|
|
|
number = double.Parse (match.Groups [1].Value, new CultureInfo ("en-US"));
|
|
|
|
|
|
|
|
} catch (FormatException) {
|
|
|
|
SparkleLogger.LogInfo ("Git", "Error parsing progress: \"" + match.Groups [1] + "\"");
|
|
|
|
}
|
2013-06-20 20:01:03 +00:00
|
|
|
|
2013-08-25 16:46:06 +00:00
|
|
|
// The pushing progress consists of two stages: the "Compressing
|
|
|
|
// objects" stage which we count as 20% of the total progress, and
|
|
|
|
// the "Writing objects" stage which we count as the last 80%
|
|
|
|
if (line.Contains ("Compressing")) {
|
|
|
|
// "Compressing objects" stage
|
|
|
|
number = (number / 100 * 20);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// "Writing objects" stage
|
|
|
|
number = (number / 100 * 80 + 20);
|
|
|
|
Match speed_match = this.speed_regex.Match (line);
|
|
|
|
|
|
|
|
if (speed_match.Success) {
|
|
|
|
try {
|
|
|
|
speed = double.Parse (speed_match.Groups [1].Value, new CultureInfo ("en-US")) * 1024;
|
|
|
|
|
|
|
|
} catch (FormatException) {
|
|
|
|
SparkleLogger.LogInfo ("Git", "Error parsing speed: \"" + speed_match.Groups [1] + "\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (speed_match.Groups [2].Value.Equals ("M"))
|
|
|
|
speed = speed * 1024;
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 20:01:03 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
SparkleLogger.LogInfo ("Fetcher", line);
|
|
|
|
line = line.Trim (new char [] {' ', '@'});
|
|
|
|
|
|
|
|
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
|
|
|
line.StartsWith ("error:", StringComparison.InvariantCultureIgnoreCase)) {
|
|
|
|
|
|
|
|
base.errors.Add (line);
|
|
|
|
|
|
|
|
} else if (line.StartsWith ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!")) {
|
|
|
|
base.errors.Add ("warning: Remote host identification has changed!");
|
|
|
|
|
|
|
|
} else if (line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) {
|
|
|
|
base.errors.Add ("warning: Possible DNS spoofing detected!");
|
|
|
|
}
|
2012-06-17 21:57:15 +00:00
|
|
|
}
|
2012-04-17 09:05:47 +00:00
|
|
|
|
2013-06-20 20:01:03 +00:00
|
|
|
if (number >= percentage) {
|
|
|
|
percentage = number;
|
2011-12-30 00:44:35 +00:00
|
|
|
|
2013-06-20 20:01:03 +00:00
|
|
|
if (DateTime.Compare (last_change, DateTime.Now.Subtract (change_interval)) < 0) {
|
2013-08-25 16:46:06 +00:00
|
|
|
base.OnProgressChanged (percentage, speed);
|
2013-06-20 20:01:03 +00:00
|
|
|
last_change = DateTime.Now;
|
|
|
|
}
|
2011-12-30 00:44:35 +00:00
|
|
|
}
|
2011-08-27 15:53:17 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 09:11:03 +00:00
|
|
|
} catch (Exception) {
|
2013-06-20 20:01:03 +00:00
|
|
|
IsActive = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:47:46 +00:00
|
|
|
this.git.WaitForExit ();
|
2012-06-17 20:56:27 +00:00
|
|
|
|
2012-02-26 15:58:09 +00:00
|
|
|
if (this.git.ExitCode == 0) {
|
|
|
|
while (percentage < 100) {
|
|
|
|
percentage += 25;
|
2012-06-17 20:56:27 +00:00
|
|
|
|
2012-02-26 15:58:09 +00:00
|
|
|
if (percentage >= 100)
|
|
|
|
break;
|
2012-04-22 12:32:55 +00:00
|
|
|
|
2012-03-01 23:56:44 +00:00
|
|
|
Thread.Sleep (500);
|
2013-08-25 16:46:06 +00:00
|
|
|
base.OnProgressChanged (percentage, 0);
|
2012-02-26 15:58:09 +00:00
|
|
|
}
|
2012-06-17 20:56:27 +00:00
|
|
|
|
2013-08-25 16:46:06 +00:00
|
|
|
base.OnProgressChanged (100, 0);
|
2011-12-30 00:44:35 +00:00
|
|
|
|
2011-05-16 20:19:58 +00:00
|
|
|
InstallConfiguration ();
|
|
|
|
InstallExcludeRules ();
|
2012-06-29 13:00:25 +00:00
|
|
|
InstallAttributeRules ();
|
2012-06-17 20:56:27 +00:00
|
|
|
|
2011-05-16 20:19:58 +00:00
|
|
|
return true;
|
2012-02-26 15:58:09 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-05-16 20:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
public override bool IsFetchedRepoEmpty {
|
|
|
|
get {
|
2012-06-10 22:56:39 +00:00
|
|
|
SparkleGit git = new SparkleGit (TargetFolder, "rev-parse HEAD");
|
2012-11-22 09:45:52 +00:00
|
|
|
git.StartAndWaitForExit ();
|
2012-04-22 12:32:55 +00:00
|
|
|
|
2012-06-10 22:56:39 +00:00
|
|
|
return (git.ExitCode != 0);
|
2012-04-22 12:32:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void EnableFetchedRepoCrypto (string password)
|
2012-02-09 01:46:25 +00:00
|
|
|
{
|
2012-04-22 12:32:55 +00:00
|
|
|
// Define the crypto filter in the config
|
2012-07-28 13:58:09 +00:00
|
|
|
string repo_config_file_path = new string [] { TargetFolder, ".git", "config" }.Combine ();
|
2012-04-22 12:32:55 +00:00
|
|
|
string config = File.ReadAllText (repo_config_file_path);
|
2011-11-28 13:40:34 +00:00
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
string n = Environment.NewLine;
|
|
|
|
|
2012-10-20 22:22:41 +00:00
|
|
|
string salt = this.crypto_salt;
|
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
config += "[filter \"crypto\"]" + n +
|
2012-10-20 22:22:41 +00:00
|
|
|
"\tsmudge = openssl enc -d -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n +
|
|
|
|
"\tclean = openssl enc -e -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n;
|
2012-04-22 12:32:55 +00:00
|
|
|
|
|
|
|
File.WriteAllText (repo_config_file_path, config);
|
|
|
|
|
|
|
|
// Pass all files through the crypto filter
|
2012-07-28 13:58:09 +00:00
|
|
|
string git_attributes_file_path = new string [] { TargetFolder, ".git", "info", "attributes" }.Combine ();
|
2012-06-28 23:12:37 +00:00
|
|
|
File.AppendAllText (git_attributes_file_path, "\n* filter=crypto");
|
2012-04-22 12:32:55 +00:00
|
|
|
|
|
|
|
// Store the password
|
2012-07-28 13:58:09 +00:00
|
|
|
string password_file_path = new string [] { TargetFolder, ".git", "password" }.Combine ();
|
2012-04-22 12:32:55 +00:00
|
|
|
File.WriteAllText (password_file_path, password.Trim ());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool IsFetchedRepoPasswordCorrect (string password)
|
|
|
|
{
|
|
|
|
string password_check_file_path = Path.Combine (TargetFolder, ".sparkleshare");
|
|
|
|
|
|
|
|
if (!File.Exists (password_check_file_path)) {
|
|
|
|
SparkleGit git = new SparkleGit (TargetFolder, "show HEAD:.sparkleshare");
|
2012-11-22 09:45:52 +00:00
|
|
|
string output = git.StartAndReadStandardOutput ();
|
2012-04-22 12:32:55 +00:00
|
|
|
|
2012-11-22 09:45:52 +00:00
|
|
|
if (git.ExitCode == 0)
|
2012-04-22 12:32:55 +00:00
|
|
|
File.WriteAllText (password_check_file_path, output);
|
2012-11-22 09:45:52 +00:00
|
|
|
else
|
|
|
|
return false;
|
2012-04-22 12:32:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 14:48:35 +00:00
|
|
|
Process process = new Process ();
|
|
|
|
process.EnableRaisingEvents = true;
|
2012-04-22 12:32:55 +00:00
|
|
|
process.StartInfo.WorkingDirectory = TargetFolder;
|
|
|
|
process.StartInfo.UseShellExecute = false;
|
|
|
|
process.StartInfo.RedirectStandardOutput = true;
|
2013-12-06 23:38:12 +00:00
|
|
|
process.StartInfo.RedirectStandardInput = true;
|
2012-04-22 12:32:55 +00:00
|
|
|
process.StartInfo.CreateNoWindow = true;
|
|
|
|
|
|
|
|
process.StartInfo.FileName = "openssl";
|
2013-12-06 23:38:12 +00:00
|
|
|
process.StartInfo.Arguments = "enc -d -aes-256-cbc -base64 -pass stdin" +
|
|
|
|
"-in \"" + password_check_file_path + "\"";
|
2012-04-22 12:32:55 +00:00
|
|
|
|
2013-06-30 14:48:35 +00:00
|
|
|
SparkleLogger.LogInfo ("Cmd | " + System.IO.Path.GetFileName (process.StartInfo.WorkingDirectory),
|
|
|
|
System.IO.Path.GetFileName (process.StartInfo.FileName) + " " + process.StartInfo.Arguments);
|
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
process.Start ();
|
2013-12-06 23:38:12 +00:00
|
|
|
process.StandardInput.WriteLine (password);
|
2012-04-22 12:32:55 +00:00
|
|
|
process.WaitForExit ();
|
2011-11-28 13:40:34 +00:00
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
if (process.ExitCode == 0) {
|
|
|
|
File.Delete (password_check_file_path);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-28 13:40:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 01:46:25 +00:00
|
|
|
|
2011-08-26 20:47:46 +00:00
|
|
|
public override void Stop ()
|
|
|
|
{
|
2012-04-11 10:51:53 +00:00
|
|
|
try {
|
2013-06-20 20:01:03 +00:00
|
|
|
if (this.git != null && !this.git.HasExited) {
|
2012-10-05 19:55:57 +00:00
|
|
|
this.git.Kill ();
|
|
|
|
this.git.Dispose ();
|
|
|
|
}
|
2012-04-11 10:51:53 +00:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
2012-11-22 12:31:48 +00:00
|
|
|
SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly", e);
|
2011-08-26 20:47:46 +00:00
|
|
|
}
|
2013-06-30 14:48:35 +00:00
|
|
|
|
|
|
|
if (Directory.Exists (TargetFolder)) {
|
|
|
|
try {
|
|
|
|
Directory.Delete (TargetFolder, true /* Recursive */ );
|
|
|
|
SparkleLogger.LogInfo ("Fetcher", "Deleted '" + TargetFolder + "'");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
SparkleLogger.LogInfo ("Fetcher", "Failed to delete '" + TargetFolder + "'", e);
|
|
|
|
}
|
|
|
|
}
|
2012-04-18 09:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-22 12:32:55 +00:00
|
|
|
public override void Complete ()
|
2012-04-18 09:52:45 +00:00
|
|
|
{
|
2012-07-05 11:33:32 +00:00
|
|
|
if (!IsFetchedRepoEmpty) {
|
|
|
|
SparkleGit git = new SparkleGit (TargetFolder, "checkout --quiet HEAD");
|
2012-07-26 10:12:14 +00:00
|
|
|
git.StartAndWaitForExit ();
|
2012-07-05 11:33:32 +00:00
|
|
|
}
|
2012-06-10 22:56:39 +00:00
|
|
|
|
2012-07-05 11:33:32 +00:00
|
|
|
base.Complete ();
|
2011-08-26 20:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 20:19:58 +00:00
|
|
|
private void InstallConfiguration ()
|
|
|
|
{
|
2012-06-29 12:17:59 +00:00
|
|
|
string [] settings = new string [] {
|
|
|
|
"core.quotepath false", // Don't quote "unusual" characters in path names
|
|
|
|
"core.ignorecase false", // Be case sensitive explicitly to work on Mac
|
|
|
|
"core.filemode false", // Ignore permission changes
|
|
|
|
"core.autocrlf false", // Don't change file line endings
|
2012-11-08 16:02:55 +00:00
|
|
|
"core.precomposeunicode true", // Use the same Unicode form on all filesystems
|
2012-06-29 12:17:59 +00:00
|
|
|
"core.safecrlf false",
|
2013-07-06 18:05:12 +00:00
|
|
|
"core.excludesfile \"\"",
|
2012-06-29 12:17:59 +00:00
|
|
|
"core.packedGitLimit 128m", // Some memory limiting options
|
|
|
|
"core.packedGitWindowSize 128m",
|
|
|
|
"pack.deltaCacheSize 128m",
|
|
|
|
"pack.packSizeLimit 128m",
|
2012-10-26 12:43:54 +00:00
|
|
|
"pack.windowMemory 128m",
|
|
|
|
"push.default matching"
|
2012-06-29 11:53:13 +00:00
|
|
|
};
|
2012-06-28 23:12:37 +00:00
|
|
|
|
2012-06-29 12:17:59 +00:00
|
|
|
foreach (string setting in settings) {
|
|
|
|
SparkleGit git_config = new SparkleGit (TargetFolder, "config " + setting);
|
2012-07-26 10:12:14 +00:00
|
|
|
git_config.StartAndWaitForExit ();
|
2012-06-29 11:53:13 +00:00
|
|
|
}
|
2012-06-28 23:12:37 +00:00
|
|
|
|
2012-06-29 11:53:13 +00:00
|
|
|
if (this.use_git_bin)
|
|
|
|
InstallGitBinConfiguration ();
|
|
|
|
}
|
2012-06-28 23:12:37 +00:00
|
|
|
|
|
|
|
|
2012-06-29 11:53:13 +00:00
|
|
|
public void InstallGitBinConfiguration ()
|
|
|
|
{
|
2012-06-29 12:17:59 +00:00
|
|
|
string [] settings = new string [] {
|
2012-12-14 18:13:30 +00:00
|
|
|
"core.bigFileThreshold 1024g",
|
2012-06-29 20:43:49 +00:00
|
|
|
"filter.bin.clean \"git bin clean %f\"",
|
2012-12-20 17:40:55 +00:00
|
|
|
"filter.bin.smudge \"git bin smudge\""
|
2012-06-29 11:53:13 +00:00
|
|
|
};
|
2012-06-28 23:12:37 +00:00
|
|
|
|
2012-06-29 12:17:59 +00:00
|
|
|
foreach (string setting in settings) {
|
|
|
|
SparkleGit git_config = new SparkleGit (TargetFolder, "config " + setting);
|
2012-07-26 10:12:14 +00:00
|
|
|
git_config.StartAndWaitForExit ();
|
2012-06-28 23:12:37 +00:00
|
|
|
}
|
2011-05-16 20:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add a .gitignore file to the repo
|
|
|
|
private void InstallExcludeRules ()
|
|
|
|
{
|
2012-08-27 12:54:22 +00:00
|
|
|
string git_info_path = new string [] { TargetFolder, ".git", "info" }.Combine ();
|
|
|
|
|
|
|
|
if (!Directory.Exists (git_info_path))
|
|
|
|
Directory.CreateDirectory (git_info_path);
|
|
|
|
|
2012-07-22 20:54:59 +00:00
|
|
|
string exclude_rules = string.Join (Environment.NewLine, ExcludeRules);
|
2012-08-27 12:54:22 +00:00
|
|
|
string exclude_rules_file_path = new string [] { git_info_path, "exclude" }.Combine ();
|
2012-01-16 19:57:11 +00:00
|
|
|
|
2012-07-22 20:54:59 +00:00
|
|
|
File.WriteAllText (exclude_rules_file_path, exclude_rules);
|
2012-06-29 13:00:25 +00:00
|
|
|
}
|
2012-01-11 22:15:13 +00:00
|
|
|
|
|
|
|
|
2012-06-29 13:00:25 +00:00
|
|
|
private void InstallAttributeRules ()
|
|
|
|
{
|
2012-07-28 13:58:09 +00:00
|
|
|
string attribute_rules_file_path = new string [] { TargetFolder, ".git", "info", "attributes" }.Combine ();
|
2012-07-22 20:54:59 +00:00
|
|
|
TextWriter writer = new StreamWriter (attribute_rules_file_path);
|
2012-01-11 22:15:13 +00:00
|
|
|
|
2012-06-29 11:53:13 +00:00
|
|
|
if (this.use_git_bin) {
|
2012-06-28 23:12:37 +00:00
|
|
|
writer.WriteLine ("* filter=bin binary");
|
|
|
|
|
|
|
|
} else {
|
2012-06-29 13:00:25 +00:00
|
|
|
// Compile a list of files we don't want Git to compress.
|
2012-06-29 12:17:59 +00:00
|
|
|
// Not compressing already compressed files decreases memory usage and increases speed
|
|
|
|
string [] extensions = new string [] {
|
|
|
|
"jpg", "jpeg", "png", "tiff", "gif", // Images
|
|
|
|
"flac", "mp3", "ogg", "oga", // Audio
|
|
|
|
"avi", "mov", "mpg", "mpeg", "mkv", "ogv", "ogx", "webm", // Video
|
2013-02-14 11:04:31 +00:00
|
|
|
"zip", "gz", "bz", "bz2", "rpm", "deb", "tgz", "rar", "ace", "7z", "pak", "tc", "iso", ".dmg" // Archives
|
2012-06-29 12:17:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
foreach (string extension in extensions) {
|
|
|
|
writer.WriteLine ("*." + extension + " -delta");
|
|
|
|
writer.WriteLine ("*." + extension.ToUpper () + " -delta");
|
|
|
|
}
|
2012-11-10 10:43:30 +00:00
|
|
|
|
|
|
|
writer.WriteLine ("*.txt text");
|
|
|
|
writer.WriteLine ("*.TXT text");
|
2012-06-28 23:12:37 +00:00
|
|
|
}
|
2012-01-11 22:15:13 +00:00
|
|
|
|
|
|
|
writer.Close ();
|
2011-05-16 20:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|