From de98e29f70ec47d9145edcf014f2f7c119d4b42c Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 21 Jun 2011 20:15:40 +0100 Subject: [PATCH] Add each note to its own namespace to avoid conflicts --- SparkleLib/Git/SparkleRepoGit.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 9968f3de..1ae4593e 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -19,6 +19,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Security.Cryptography; +using System.Text; using System.Text.RegularExpressions; namespace SparkleLib { @@ -540,17 +542,21 @@ namespace SparkleLib { public override void AddNote (string revision, string note) { + int timestamp = (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds; + // Create the note in one line for easier merging note = "" + " " + " " + SparkleConfig.DefaultConfig.UserName + "" + " " + SparkleConfig.DefaultConfig.UserEmail + "" + " " + - " " + (int) (DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds + "" + + " " + timestamp + "" + " " + note + "" + ""; - SparkleGit git_notes = new SparkleGit (LocalPath, "notes append -m \"" + note + "\" " + revision); + string note_namespace = SHA1 (timestamp.ToString () + note); + SparkleGit git_notes = new SparkleGit (LocalPath, + "notes --ref=" + note_namespace + " append -m \"" + note + "\" " + revision); git_notes.Start (); git_notes.WaitForExit (); @@ -571,5 +577,15 @@ namespace SparkleLib { return !File.Exists (file_path); } } + + + // Creates a SHA-1 hash of input + private string SHA1 (string s) + { + SHA1 sha1 = new SHA1CryptoServiceProvider (); + Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); + Byte[] encoded_bytes = sha1.ComputeHash (bytes); + return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); + } } }