diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 219ac29c..7c562096 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -30,32 +30,23 @@ namespace SparkleLib.Git { } - private string identifier = null; + 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 (); - public override string Identifier { - get { - if (string.IsNullOrEmpty (this.identifier)) { + // 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 (); - // 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 (); + if (output.Length < 40) + return null; - // 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; - - this.identifier = output.Substring (0, 40); - } - - return this.identifier; - } + return output.Substring (0, 40); } @@ -312,7 +303,13 @@ namespace SparkleLib.Git { if (git.ExitCode == 0) { Rebase (); - return true; + + File.SetAttributes ( + Path.Combine (LocalPath, ".sparkleshare"), + FileAttributes.Hidden + ); + + return true; } else { return false; @@ -659,7 +656,9 @@ namespace SparkleLib.Git { file_path = file_path.Substring (0, file_path.Length - ".empty".Length); - if (change_type.Equals ("A")) { + if (change_type.Equals ("A") && + !file_path.Equals (".sparkleshare")) { + change_set.Added.Add (file_path); } else if (change_type.Equals ("M")) { diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 6ca60b5d..5e75b1f2 100755 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -35,7 +35,8 @@ namespace SparkleLib { public abstract class SparkleRepoBase { - + + private string identifier; private TimeSpan short_interval = new TimeSpan (0, 0, 3, 0); private TimeSpan long_interval = new TimeSpan (0, 0, 10, 0); private TimeSpan poll_interval; @@ -75,7 +76,7 @@ namespace SparkleLib { public readonly string Name; public readonly Uri Url; - public abstract string Identifier { get; } + public abstract string ComputeIdentifier (); public abstract string CurrentRevision { get; } public abstract double Size { get; } public abstract double HistorySize { get; } @@ -131,6 +132,25 @@ namespace SparkleLib { return this.is_buffering; } } + + public string Identifier { + get { + if (this.identifier == null) { + string id_path = Path.Combine (LocalPath, ".sparkleshare"); + + if (File.Exists (id_path)) { + this.identifier = File.ReadAllText (id_path).Trim (); + + } else { + this.identifier = ComputeIdentifier (); + File.WriteAllText (id_path, this.identifier); + File.SetAttributes (id_path, FileAttributes.Hidden); + } + } + + return this.identifier; + } + } public SparkleRepoBase (string path) @@ -147,6 +167,9 @@ namespace SparkleLib { if (CurrentRevision == null) CreateInitialChangeSet (); + + this.identifier = Identifier; + CreateWatcher (); CreateListener (); @@ -171,8 +194,6 @@ namespace SparkleLib { if (HasUnsyncedChanges && !IsSyncing && this.server_online) SyncUpBase (); }; - - } @@ -328,7 +349,10 @@ namespace SparkleLib { if (!pre_sync_revision.Equals (CurrentRevision)) { List change_sets = GetChangeSets (1); - if (change_sets != null && change_sets.Count > 0) { + if (change_sets != null && + change_sets.Count > 0 && + !change_sets [0].Added.Contains (".sparkleshare")) { + if (NewChangeSet != null) NewChangeSet (change_sets [0]); } @@ -517,7 +541,6 @@ namespace SparkleLib { writer.WriteLine (""); writer.WriteLine ("Any files you add or change in this folder will be automatically synced to "); writer.WriteLine (Url + " and everyone connected to it."); - writer.WriteLine (""); writer.WriteLine ("SparkleShare is a Free and Open Source software program that helps people "); writer.WriteLine ("collaborate and share files. If you like what we do, please consider a small ");