fetcher: code cleanup
This commit is contained in:
parent
ce844af1ee
commit
0b500c3ef4
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
@ -40,10 +39,8 @@ namespace SparkleLib.Git {
|
||||||
{
|
{
|
||||||
Uri uri = RemoteUrl;
|
Uri uri = RemoteUrl;
|
||||||
|
|
||||||
if (!uri.Scheme.Equals ("ssh") &&
|
if (!uri.Scheme.Equals ("ssh") && !uri.Scheme.Equals ("https") &&
|
||||||
!uri.Scheme.Equals ("https") &&
|
!uri.Scheme.Equals ("http") && !uri.Scheme.Equals ("git")) {
|
||||||
!uri.Scheme.Equals ("http") &&
|
|
||||||
!uri.Scheme.Equals ("git")) {
|
|
||||||
|
|
||||||
uri = new Uri ("ssh://" + uri);
|
uri = new Uri ("ssh://" + uri);
|
||||||
}
|
}
|
||||||
|
@ -90,18 +87,11 @@ namespace SparkleLib.Git {
|
||||||
{
|
{
|
||||||
if (FetchPriorHistory) {
|
if (FetchPriorHistory) {
|
||||||
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||||
"clone " +
|
"clone --progress --no-checkout \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
||||||
"--progress " +
|
|
||||||
"--no-checkout " +
|
|
||||||
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||||
"clone " +
|
"clone --progress --no-checkout --depth=1 \"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
||||||
"--progress " +
|
|
||||||
"--no-checkout " +
|
|
||||||
"--depth=1 " +
|
|
||||||
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.git.StartInfo.RedirectStandardError = true;
|
this.git.StartInfo.RedirectStandardError = true;
|
||||||
|
@ -125,15 +115,12 @@ namespace SparkleLib.Git {
|
||||||
// objects" stage which we count as 20% of the total progress, and
|
// objects" stage which we count as 20% of the total progress, and
|
||||||
// the "Receiving objects" stage which we count as the last 80%
|
// the "Receiving objects" stage which we count as the last 80%
|
||||||
if (line.Contains ("|"))
|
if (line.Contains ("|"))
|
||||||
// "Receiving objects" stage
|
number = (number / 100 * 80 + 20); // "Receiving objects" stage
|
||||||
number = (number / 100 * 80 + 20);
|
|
||||||
else
|
else
|
||||||
// "Compressing objects" stage
|
number = (number / 100 * 20); // "Compressing objects" stage
|
||||||
number = (number / 100 * 20);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SparkleHelpers.DebugInfo ("Fetcher", line);
|
SparkleHelpers.DebugInfo ("Fetcher", line);
|
||||||
|
|
||||||
line = line.Trim (new char [] {' ', '@'});
|
line = line.Trim (new char [] {' ', '@'});
|
||||||
|
|
||||||
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
@ -219,14 +206,10 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
File.WriteAllText (repo_config_file_path, config);
|
File.WriteAllText (repo_config_file_path, config);
|
||||||
|
|
||||||
|
|
||||||
// Pass all files through the crypto filter
|
// Pass all files through the crypto filter
|
||||||
string git_attributes_file_path = SparkleHelpers.CombineMore (
|
string git_attributes_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "attributes");
|
||||||
TargetFolder, ".git", "info", "attributes");
|
|
||||||
|
|
||||||
File.AppendAllText (git_attributes_file_path, "\n* filter=crypto");
|
File.AppendAllText (git_attributes_file_path, "\n* filter=crypto");
|
||||||
|
|
||||||
|
|
||||||
// Store the password
|
// Store the password
|
||||||
string password_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "password");
|
string password_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "password");
|
||||||
File.WriteAllText (password_file_path, password.Trim ());
|
File.WriteAllText (password_file_path, password.Trim ());
|
||||||
|
@ -246,12 +229,10 @@ namespace SparkleLib.Git {
|
||||||
string output = git.StandardOutput.ReadToEnd ();
|
string output = git.StandardOutput.ReadToEnd ();
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
if (git.ExitCode != 0) {
|
if (git.ExitCode != 0)
|
||||||
return false;
|
return false;
|
||||||
|
else
|
||||||
} else {
|
|
||||||
File.WriteAllText (password_check_file_path, output);
|
File.WriteAllText (password_check_file_path, output);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Process process = new Process () {
|
Process process = new Process () {
|
||||||
|
@ -268,10 +249,6 @@ namespace SparkleLib.Git {
|
||||||
" -pass pass:\"" + password + "\" -in " + password_check_file_path;
|
" -pass pass:\"" + password + "\" -in " + password_check_file_path;
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
|
||||||
// WaitForExit, or it will hang forever on output > 4096 bytes
|
|
||||||
process.StandardOutput.ReadToEnd ();
|
|
||||||
process.WaitForExit ();
|
process.WaitForExit ();
|
||||||
|
|
||||||
if (process.ExitCode == 0) {
|
if (process.ExitCode == 0) {
|
||||||
|
@ -359,21 +336,17 @@ namespace SparkleLib.Git {
|
||||||
// Add a .gitignore file to the repo
|
// Add a .gitignore file to the repo
|
||||||
private void InstallExcludeRules ()
|
private void InstallExcludeRules ()
|
||||||
{
|
{
|
||||||
// Compile a list of files we want Git to ignore
|
string exclude_rules = string.Join (Environment.NewLine, ExcludeRules);
|
||||||
string exclude_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "exclude");
|
string exclude_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "exclude");
|
||||||
TextWriter writer = new StreamWriter (exclude_rules_file_path);
|
|
||||||
|
|
||||||
foreach (string exclude_rule in ExcludeRules)
|
File.WriteAllText (exclude_rules_file_path, exclude_rules);
|
||||||
writer.WriteLine (exclude_rule);
|
|
||||||
|
|
||||||
writer.Close ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void InstallAttributeRules ()
|
private void InstallAttributeRules ()
|
||||||
{
|
{
|
||||||
string attribute_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "attributes");
|
string attribute_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "attributes");
|
||||||
TextWriter writer = new StreamWriter (attribute_rules_file_path);
|
TextWriter writer = new StreamWriter (attribute_rules_file_path);
|
||||||
|
|
||||||
if (this.use_git_bin) {
|
if (this.use_git_bin) {
|
||||||
writer.WriteLine ("* filter=bin binary");
|
writer.WriteLine ("* filter=bin binary");
|
||||||
|
|
|
@ -354,7 +354,7 @@ namespace SparkleLib {
|
||||||
throw new FileNotFoundException (FullPath + " does not exist");
|
throw new FileNotFoundException (FullPath + " does not exist");
|
||||||
|
|
||||||
Save (FullPath);
|
Save (FullPath);
|
||||||
SparkleHelpers.DebugInfo ("Config", "Writen to '" + FullPath + "'");
|
SparkleHelpers.DebugInfo ("Config", "Wrote to '" + FullPath + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
@ -264,14 +261,13 @@ namespace SparkleLib {
|
||||||
EnableRaisingEvents = true
|
EnableRaisingEvents = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process.StartInfo.FileName = "ssh-keyscan";
|
||||||
|
process.StartInfo.Arguments = "-t rsa " + host;
|
||||||
process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath;
|
process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.CreateNoWindow = true;
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
process.StartInfo.FileName = "ssh-keyscan";
|
|
||||||
process.StartInfo.Arguments = "-t rsa " + host;
|
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
// Reading the standard output HAS to go before
|
||||||
|
@ -296,14 +292,13 @@ namespace SparkleLib {
|
||||||
EnableRaisingEvents = true
|
EnableRaisingEvents = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process.StartInfo.FileName = "ssh-keygen";
|
||||||
|
process.StartInfo.Arguments = "-lf \"" + tmp_file_path + "\"";
|
||||||
process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath;
|
process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.CreateNoWindow = true;
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
process.StartInfo.FileName = "ssh-keygen";
|
|
||||||
process.StartInfo.Arguments = "-lf \"" + tmp_file_path + "\"";
|
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
// Reading the standard output HAS to go before
|
||||||
|
|
Loading…
Reference in a new issue