Refactor adding of (empty) repos. Fixes #773
This commit is contained in:
parent
19b7250b61
commit
febd993f29
|
@ -46,7 +46,6 @@ namespace SparkleLib.Git {
|
||||||
uri = new Uri ("ssh://" + uri);
|
uri = new Uri ("ssh://" + uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (uri.Host.Equals ("gitorious.org")) {
|
if (uri.Host.Equals ("gitorious.org")) {
|
||||||
if (!uri.AbsolutePath.Equals ("/") &&
|
if (!uri.AbsolutePath.Equals ("/") &&
|
||||||
!uri.AbsolutePath.EndsWith (".git")) {
|
!uri.AbsolutePath.EndsWith (".git")) {
|
||||||
|
@ -77,7 +76,6 @@ namespace SparkleLib.Git {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TargetFolder = target_folder;
|
TargetFolder = target_folder;
|
||||||
RemoteUrl = uri;
|
RemoteUrl = uri;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +88,6 @@ namespace SparkleLib.Git {
|
||||||
"clone " +
|
"clone " +
|
||||||
"--progress " +
|
"--progress " +
|
||||||
"--no-checkout " +
|
"--no-checkout " +
|
||||||
"--depth=1 " +
|
|
||||||
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,6 +95,7 @@ namespace SparkleLib.Git {
|
||||||
"clone " +
|
"clone " +
|
||||||
"--progress " +
|
"--progress " +
|
||||||
"--no-checkout " +
|
"--no-checkout " +
|
||||||
|
"--depth=1 " +
|
||||||
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
"\"" + RemoteUrl + "\" \"" + TargetFolder + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,15 +171,15 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
public override bool IsFetchedRepoEmpty {
|
public override bool IsFetchedRepoEmpty {
|
||||||
get {
|
get {
|
||||||
SparkleGit git = new SparkleGit (TargetFolder, "rev-list --reverse HEAD");
|
SparkleGit git = new SparkleGit (TargetFolder, "rev-parse HEAD");
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
// Reading the standard output HAS to go before
|
||||||
// WaitForExit, or it will hang forever on output > 4096 bytes
|
// WaitForExit, or it will hang forever on output > 4096 bytes
|
||||||
string output = git.StandardOutput.ReadToEnd ();
|
git.StandardOutput.ReadToEnd ();
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
return (output.Length < 40);
|
return (git.ExitCode != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,6 +278,9 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
public override void Complete ()
|
public override void Complete ()
|
||||||
{
|
{
|
||||||
|
if (IsFetchedRepoEmpty)
|
||||||
|
return;
|
||||||
|
|
||||||
SparkleGit git = new SparkleGit (TargetFolder, "checkout HEAD");
|
SparkleGit git = new SparkleGit (TargetFolder, "checkout HEAD");
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
|
@ -440,7 +441,7 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
private void AddWarnings ()
|
private void AddWarnings ()
|
||||||
{
|
{
|
||||||
SparkleGit git = new SparkleGit (TargetFolder,
|
/*SparkleGit git = new SparkleGit (TargetFolder,
|
||||||
"config --global core.excludesfile");
|
"config --global core.excludesfile");
|
||||||
|
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
@ -454,6 +455,6 @@ namespace SparkleLib.Git {
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
this.warnings.Add ("You seem to have a system wide ‘gitignore’ file, this may affect SparkleShare files.");
|
this.warnings.Add ("You seem to have a system wide ‘gitignore’ file, this may affect SparkleShare files.");
|
||||||
}
|
*/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,26 +30,6 @@ namespace SparkleLib.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string ComputeIdentifier () {
|
|
||||||
// Because git computes a hash based on content,
|
|
||||||
// author, and timestamp; it is unique enough to
|
|
||||||
// use the hash of the first commit as an identifier
|
|
||||||
// for our folder
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "rev-list --reverse HEAD");
|
|
||||||
git.Start ();
|
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
|
||||||
// WaitForExit, or it will hang forever on output > 4096 bytes
|
|
||||||
string output = git.StandardOutput.ReadToEnd ();
|
|
||||||
git.WaitForExit ();
|
|
||||||
|
|
||||||
if (output.Length < 40)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return output.Substring (0, 40);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override List<string> ExcludePaths {
|
public override List<string> ExcludePaths {
|
||||||
get {
|
get {
|
||||||
List<string> rules = new List<string> ();
|
List<string> rules = new List<string> ();
|
||||||
|
@ -104,6 +84,13 @@ namespace SparkleLib.Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void CreateInitialChangeSet ()
|
||||||
|
{
|
||||||
|
base.CreateInitialChangeSet ();
|
||||||
|
SyncUp (); // FIXME: Weird freeze happens when base class handles this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string [] UnsyncedFilePaths {
|
public override string [] UnsyncedFilePaths {
|
||||||
get {
|
get {
|
||||||
List<string> file_paths = new List<string> ();
|
List<string> file_paths = new List<string> ();
|
||||||
|
@ -138,15 +125,17 @@ namespace SparkleLib.Git {
|
||||||
// Remove stale rebase-apply files because it
|
// Remove stale rebase-apply files because it
|
||||||
// makes the method return the wrong hashes.
|
// makes the method return the wrong hashes.
|
||||||
string rebase_apply_file = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply");
|
string rebase_apply_file = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply");
|
||||||
|
|
||||||
if (File.Exists (rebase_apply_file))
|
if (File.Exists (rebase_apply_file))
|
||||||
File.Delete (rebase_apply_file);
|
File.Delete (rebase_apply_file);
|
||||||
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "rev-parse HEAD");
|
SparkleGit git = new SparkleGit (LocalPath, "rev-parse HEAD");
|
||||||
git.Start ();
|
git.Start ();
|
||||||
|
|
||||||
|
string output = git.StandardOutput.ReadToEnd ();
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
if (git.ExitCode == 0) {
|
if (git.ExitCode == 0) {
|
||||||
string output = git.StandardOutput.ReadToEnd ();
|
|
||||||
return output.TrimEnd ();
|
return output.TrimEnd ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -161,7 +150,7 @@ namespace SparkleLib.Git {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Checking for remote changes...");
|
||||||
|
|
||||||
string current_revision = CurrentRevision;
|
string current_revision = CurrentRevision;
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "ls-remote \"" + RemoteUrl + "\" master");
|
SparkleGit git = new SparkleGit (LocalPath, "ls-remote --exit-code \"" + RemoteUrl + "\" master");
|
||||||
|
|
||||||
git.Start ();
|
git.Start ();
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
@ -198,7 +187,6 @@ namespace SparkleLib.Git {
|
||||||
Commit (message);
|
Commit (message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath,
|
SparkleGit git = new SparkleGit (LocalPath,
|
||||||
"push --progress " + // Redirects progress stats to standarderror
|
"push --progress " + // Redirects progress stats to standarderror
|
||||||
"\"" + RemoteUrl + "\" master");
|
"\"" + RemoteUrl + "\" master");
|
||||||
|
@ -248,7 +236,6 @@ namespace SparkleLib.Git {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] " + line);
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] " + line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (number >= percentage) {
|
if (number >= percentage) {
|
||||||
percentage = number;
|
percentage = number;
|
||||||
base.OnProgressChanged (percentage, speed);
|
base.OnProgressChanged (percentage, speed);
|
||||||
|
|
|
@ -140,7 +140,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
|
|
||||||
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto"); // TODO
|
// TODO: Find better way to determine if folder should have crypto setup
|
||||||
|
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("crypto");
|
||||||
|
|
||||||
if (Finished != null)
|
if (Finished != null)
|
||||||
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
|
Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings);
|
||||||
|
|
|
@ -17,12 +17,14 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
|
||||||
public static class SparkleHelpers {
|
public static class SparkleHelpers {
|
||||||
|
|
||||||
private static object debug_lock = new object ();
|
private static Object debug_lock = new Object ();
|
||||||
|
|
||||||
// Show debug info if needed
|
// Show debug info if needed
|
||||||
public static void DebugInfo (string type, string message)
|
public static void DebugInfo (string type, string message)
|
||||||
|
@ -101,6 +103,15 @@ namespace SparkleLib {
|
||||||
platform == PlatformID.Win32Windows);
|
platform == PlatformID.Win32Windows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string SHA1 (string s)
|
||||||
|
{
|
||||||
|
SHA1 sha1 = new SHA1CryptoServiceProvider ();
|
||||||
|
Byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||||
|
Byte [] enc_bytes = sha1.ComputeHash (bytes);
|
||||||
|
|
||||||
|
return BitConverter.ToString (enc_bytes).ToLower ().Replace ("-", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -35,15 +34,10 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class PollInterval {
|
|
||||||
public static TimeSpan Short { get { return new TimeSpan (0, 0, 5, 0); }}
|
|
||||||
public static TimeSpan Long { get { return new TimeSpan (0, 0, 15, 0); }}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class SparkleRepoBase {
|
public abstract class SparkleRepoBase {
|
||||||
|
|
||||||
public abstract string ComputeIdentifier ();
|
|
||||||
public abstract string CurrentRevision { get; }
|
public abstract string CurrentRevision { get; }
|
||||||
public abstract double Size { get; }
|
public abstract double Size { get; }
|
||||||
public abstract double HistorySize { get; }
|
public abstract double HistorySize { get; }
|
||||||
|
@ -95,10 +89,15 @@ namespace SparkleLib {
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.identifier = ComputeIdentifier ();
|
Random random = new Random ();
|
||||||
|
string number = "" + random.Next () + "" + random.Next () + "" + random.Next ();
|
||||||
|
this.identifier = SparkleHelpers.SHA1 (number);
|
||||||
|
|
||||||
File.WriteAllText (id_path, this.identifier);
|
File.WriteAllText (id_path, this.identifier);
|
||||||
File.SetAttributes (id_path, FileAttributes.Hidden);
|
File.SetAttributes (id_path, FileAttributes.Hidden);
|
||||||
|
|
||||||
|
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Assigned identifier: " + this.identifier);
|
||||||
|
|
||||||
return this.identifier;
|
return this.identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,6 +130,11 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class PollInterval {
|
||||||
|
public static TimeSpan Short { get { return new TimeSpan (0, 0, 5, 0); }}
|
||||||
|
public static TimeSpan Long { get { return new TimeSpan (0, 0, 15, 0); }}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public SparkleRepoBase (string path)
|
public SparkleRepoBase (string path)
|
||||||
{
|
{
|
||||||
|
@ -162,7 +166,7 @@ namespace SparkleLib {
|
||||||
bool time_to_poll = (DateTime.Compare (this.last_poll,
|
bool time_to_poll = (DateTime.Compare (this.last_poll,
|
||||||
DateTime.Now.Subtract (this.poll_interval)) < 0);
|
DateTime.Now.Subtract (this.poll_interval)) < 0);
|
||||||
|
|
||||||
if (time_to_poll) {
|
if (time_to_poll && !is_syncing) {
|
||||||
this.last_poll = DateTime.Now;
|
this.last_poll = DateTime.Now;
|
||||||
|
|
||||||
if (HasRemoteChanges)
|
if (HasRemoteChanges)
|
||||||
|
@ -182,13 +186,10 @@ namespace SparkleLib {
|
||||||
// Sync up everything that changed
|
// Sync up everything that changed
|
||||||
// since we've been offline
|
// since we've been offline
|
||||||
if (HasLocalChanges) {
|
if (HasLocalChanges) {
|
||||||
this.watcher.Disable ();
|
|
||||||
SyncUpBase ();
|
SyncUpBase ();
|
||||||
|
|
||||||
while (HasUnsyncedChanges)
|
while (HasUnsyncedChanges)
|
||||||
SyncUpBase ();
|
SyncUpBase ();
|
||||||
|
|
||||||
this.watcher.Enable ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remote_timer.Start ();
|
this.remote_timer.Start ();
|
||||||
|
@ -208,7 +209,7 @@ namespace SparkleLib {
|
||||||
"Any files you add or change in this folder will be automatically synced to " + n +
|
"Any files you add or change in this folder will be automatically synced to " + n +
|
||||||
RemoteUrl + " and everyone connected to it." + n +
|
RemoteUrl + " and everyone connected to it." + n +
|
||||||
"" + n +
|
"" + n +
|
||||||
"SparkleShare is a Free and Open Source software program that helps people " + n +
|
"SparkleShare is an Open Source software program that helps people " + n +
|
||||||
"collaborate and share files. If you like what we do, please consider a small " + n +
|
"collaborate and share files. If you like what we do, please consider a small " + n +
|
||||||
"donation to support the project: http://sparkleshare.org/support-us/" + n +
|
"donation to support the project: http://sparkleshare.org/support-us/" + n +
|
||||||
"" + n +
|
"" + n +
|
||||||
|
|
|
@ -137,7 +137,7 @@ namespace SparkleShare {
|
||||||
LineWrap = true,
|
LineWrap = true,
|
||||||
LineWrapMode = Pango.WrapMode.Word,
|
LineWrapMode = Pango.WrapMode.Word,
|
||||||
Markup = "<span font_size='small' fgcolor='white'>" +
|
Markup = "<span font_size='small' fgcolor='white'>" +
|
||||||
"SparkleShare is Free and Open Source Software. You are free to use, modify, " +
|
"SparkleShare Open Source software. You are free to use, modify, " +
|
||||||
"and redistribute it under the GNU General Public License version 3 or later." +
|
"and redistribute it under the GNU General Public License version 3 or later." +
|
||||||
"</span>",
|
"</span>",
|
||||||
WidthRequest = 330,
|
WidthRequest = 330,
|
||||||
|
|
|
@ -168,7 +168,7 @@ namespace SparkleShare {
|
||||||
StringValue = @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." +
|
StringValue = @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"SparkleShare is Free and Open Source Software. You are free to use, modify, and redistribute it " +
|
"SparkleShare is Open Source software. You are free to use, modify, and redistribute it " +
|
||||||
"under the GNU General Public License version 3 or later.",
|
"under the GNU General Public License version 3 or later.",
|
||||||
Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
|
Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
|
||||||
TextColor = NSColor.White,
|
TextColor = NSColor.White,
|
||||||
|
|
|
@ -1006,7 +1006,6 @@ namespace SparkleShare {
|
||||||
public void FinishFetcher ()
|
public void FinishFetcher ()
|
||||||
{
|
{
|
||||||
this.fetcher.Complete ();
|
this.fetcher.Complete ();
|
||||||
|
|
||||||
string canonical_name = Path.GetFileNameWithoutExtension (this.fetcher.RemoteUrl.AbsolutePath);
|
string canonical_name = Path.GetFileNameWithoutExtension (this.fetcher.RemoteUrl.AbsolutePath);
|
||||||
|
|
||||||
bool target_folder_exists = Directory.Exists (
|
bool target_folder_exists = Directory.Exists (
|
||||||
|
@ -1039,19 +1038,19 @@ namespace SparkleShare {
|
||||||
string backend = SparkleFetcherBase.GetBackend (this.fetcher.RemoteUrl.AbsolutePath);
|
string backend = SparkleFetcherBase.GetBackend (this.fetcher.RemoteUrl.AbsolutePath);
|
||||||
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl.ToString (), backend);
|
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl.ToString (), backend);
|
||||||
|
|
||||||
/* if (!string.IsNullOrEmpty (announcements_url)) {
|
if (FolderFetched != null)
|
||||||
|
FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
|
||||||
|
|
||||||
|
/* TODO
|
||||||
|
if (!string.IsNullOrEmpty (announcements_url)) {
|
||||||
SparkleConfig.DefaultConfig.SetFolderOptionalAttribute (
|
SparkleConfig.DefaultConfig.SetFolderOptionalAttribute (
|
||||||
target_folder_name, "announcements_url", announcements_url);
|
target_folder_name, "announcements_url", announcements_url);
|
||||||
} TODO
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
lock (this.repo_lock) {
|
lock (this.repo_lock) {
|
||||||
AddRepository (target_folder_path);
|
AddRepository (target_folder_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FolderFetched != null)
|
|
||||||
FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
|
|
||||||
|
|
||||||
if (FolderListChanged != null)
|
if (FolderListChanged != null)
|
||||||
FolderListChanged ();
|
FolderListChanged ();
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ namespace SparkleShare {
|
||||||
Foreground = new SolidColorBrush (Colors.White),
|
Foreground = new SolidColorBrush (Colors.White),
|
||||||
Text = "Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others.\n" +
|
Text = "Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others.\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"SparkleShare is Free and Open Source Software. You are free to use, modify, " +
|
"SparkleShare is Open Source software. You are free to use, modify, " +
|
||||||
"and redistribute it under the GNU General Public License version 3 or later.",
|
"and redistribute it under the GNU General Public License version 3 or later.",
|
||||||
TextWrapping = TextWrapping.Wrap,
|
TextWrapping = TextWrapping.Wrap,
|
||||||
Width = 318
|
Width = 318
|
||||||
|
|
Loading…
Reference in a new issue