public Errorable <Tag> Retrieve(SqlCommand cmd, SqlDataReader dr, int expectedCapacity = 10) { if (!dr.Read()) { return(this._idOrName.Collapse <ConsistencyError>(l => new TagIDRecordDoesNotExistError(l), r => new TagNameDoesNotExistError(r))); } TagID id = (TagID)dr.GetSqlBinary(0).Value; Tag.Builder tb = new Tag.Builder( pName: (TagName)dr.GetSqlString(1).Value, pCommitID: (CommitID)dr.GetSqlBinary(2).Value, pTagger: dr.GetSqlString(3).Value, pDateTagged: dr.GetDateTimeOffset(4), pMessage: dr.GetSqlString(5).Value ); Tag tg = tb; if (tg.ID != id) { return(new ComputedTagIDMismatchError(tg.ID, id)); } return(tg); }
internal async Task DeleteTagByNameTest() { TreeNode tr = new TreeNode.Builder(new List <TreeTreeReference>(0), new List <TreeBlobReference>(0)); await trrepo.PersistTree(tr.ID, new IVO.Definition.Containers.ImmutableContainer <TreeID, TreeNode>(trx => trx.ID, tr)); Commit cm = new Commit.Builder(new List <CommitID>(0), tr.ID, "James S. Dunne", DateTimeOffset.Now, "Initial commit."); await cmrepo.PersistCommit(cm); Tag tg = new Tag.Builder((TagName)"v1.0", cm.ID, "James S. Dunne", DateTimeOffset.Now, "Testing tags"); await tgrepo.PersistTag(tg); var retgPre = await tgrepo.GetTag(tg.ID); Assert.IsFalse(retgPre.HasErrors); Tag rtgPre = retgPre.Value; Assert.IsNotNull(rtgPre); Assert.AreEqual(tg.ID, rtgPre.ID); Assert.AreEqual(tg.Name.ToString(), rtgPre.Name.ToString()); Assert.AreEqual(tg.CommitID, rtgPre.CommitID); Assert.AreEqual(tg.Tagger, rtgPre.Tagger); Assert.AreEqual(tg.DateTagged.ToString(), rtgPre.DateTagged.ToString()); await tgrepo.DeleteTagByName((TagName)"v1.0"); var retgPost = await tgrepo.GetTag(tg.ID); Assert.IsTrue(retgPost.HasErrors); Assert.AreEqual(1, retgPost.Errors.Count); }
async Task TestCreateTag(CommitID cmid) { var db = getDataContext(); ICommitRepository cmrepo = new CommitRepository(db); ITagRepository tgrepo = new TagRepository(db); Console.WriteLine("Get commit by tag 'v1.0'"); var cm = await cmrepo.GetCommitByTagName("v1.0"); if (cm != null) { Console.WriteLine("v1.0 was {0}", cm.Item2.ID); #if false Console.WriteLine("Deleting Tag by ID {0}", cm.Item1.ID); await tgrepo.DeleteTag(cm.Item1.ID).Wait(); #else Console.WriteLine("Deleting Tag by name 'v1.0'"); await tgrepo.DeleteTagByName("v1.0"); #endif } Tag tg = new Tag.Builder("v1.0", cmid, "James Dunne <*****@*****.**>", DateTimeOffset.Now, "Tagged for version 1.0"); await tgrepo.PersistTag(tg); var tgByName = await cmrepo.GetCommitByTagName("v1.0"); Debug.Assert(tgByName.Item2.ID == cmid); Console.WriteLine("Completed."); }
internal static Errorable <Tuple <Tag, Commit> > retrieve(ConsistencyError errorIfNotExist, SqlCommand cmd, SqlDataReader dr) { // If no result, return null: if (!dr.Read()) { return(errorIfNotExist); } TagID tgid = (TagID)dr.GetSqlBinary(0).Value; Tag.Builder tgb = new Tag.Builder( pName: (TagName)dr.GetSqlString(1).Value, pCommitID: (CommitID)dr.GetSqlBinary(2).Value, pTagger: dr.GetSqlString(3).Value, pDateTagged: dr.GetDateTimeOffset(4), pMessage: dr.GetSqlString(5).Value ); Tag tg = tgb; if (tg.ID != tgid) { return(new ComputedTagIDMismatchError(tg.ID, tgid)); } const int offs = 6; CommitID id = (CommitID)dr.GetSqlBinary(0 + offs).Value; Commit.Builder cmb = new Commit.Builder( pParents: new System.Collections.Generic.List <CommitID>(2), pTreeID: (TreeID)dr.GetSqlBinary(1 + offs).Value, pCommitter: dr.GetSqlString(2 + offs).Value, pDateCommitted: dr.GetDateTimeOffset(3 + offs), pMessage: dr.GetSqlString(4 + offs).Value ); // Read the parent commit ids from the second result: if (dr.NextResult()) { while (dr.Read()) { cmb.Parents.Add((CommitID)dr.GetSqlBinary(0).Value); } cmb.Parents.Sort(new CommitID.Comparer()); } Commit cm = cmb; if (cm.ID != id) { return(new ComputedCommitIDMismatchError(cm.ID, id)); } return(new Tuple <Tag, Commit>(tg, cm)); }
internal async Task PersistTagTest() { TreeNode tr = new TreeNode.Builder(new List <TreeTreeReference>(0), new List <TreeBlobReference>(0)); await trrepo.PersistTree(tr.ID, new IVO.Definition.Containers.ImmutableContainer <TreeID, TreeNode>(trx => trx.ID, tr)); Commit cm = new Commit.Builder(new List <CommitID>(0), tr.ID, "James S. Dunne", DateTimeOffset.Now, "Initial commit."); await cmrepo.PersistCommit(cm); Tag tg = new Tag.Builder((TagName)"v1.0", cm.ID, "James S. Dunne", DateTimeOffset.Now, "Testing tags"); await tgrepo.PersistTag(tg); }
internal async Task GetCommitByTagNameTest() { await createCommits(); Tag tg = new Tag.Builder((TagName)"v1.0", cmRoot.ID, "James S. Dunne", DateTimeOffset.Now, "Tagged!"); await tgrepo.PersistTag(tg); var etgcm = await cmrepo.GetCommitByTagName(tg.Name); Assert.IsFalse(etgcm.HasErrors); var tgcm = etgcm.Value; Assert.IsNotNull(tgcm); Assert.IsNotNull(tgcm.Item1); Assert.IsNotNull(tgcm.Item2); Assert.AreEqual(cmRoot.ID, tgcm.Item2.ID); Assert.AreEqual(cmRoot.DateCommitted.ToString(), tgcm.Item2.DateCommitted.ToString()); Assert.AreEqual(cmRoot.Committer, tgcm.Item2.Committer); Assert.AreEqual(cmRoot.Message, tgcm.Item2.Message); }
private async Task <Errorable <Tag> > getTag(TagID id) { FileInfo fi = system.getPathByID(id); if (!fi.Exists) { return(new TagIDRecordDoesNotExistError(id)); } byte[] buf; int nr = 0; using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 16384, true)) { // TODO: implement an async buffered Stream: buf = new byte[16384]; nr = await fs.ReadAsync(buf, 0, 16384).ConfigureAwait(continueOnCapturedContext: false); if (nr >= 16384) { // My, what a large tag you have! throw new NotSupportedException(); } } Tag.Builder tb = new Tag.Builder(); // Parse the Tag: using (var ms = new MemoryStream(buf, 0, nr, false)) using (var sr = new StreamReader(ms, Encoding.UTF8)) { string line = sr.ReadLine(); // Set CommitID: if (line == null || !line.StartsWith("commit ")) { return(new TagParseExpectedCommitError()); } var ecid = CommitID.TryParse(line.Substring("commit ".Length)); if (ecid.HasErrors) { return(ecid.Errors); } tb.CommitID = ecid.Value; // Set Name: line = sr.ReadLine(); if (line == null || !line.StartsWith("name ")) { return(new TagParseExpectedNameError()); } tb.Name = (TagName)line.Substring("name ".Length); // Set Tagger: line = sr.ReadLine(); if (line == null || !line.StartsWith("tagger ")) { return(new TagParseExpectedTaggerError()); } tb.Tagger = line.Substring("tagger ".Length); // Set DateTagged: line = sr.ReadLine(); if (line == null || !line.StartsWith("date ")) { return(new TagParseExpectedDateError()); } // NOTE: date parsing will result in an inexact DateTimeOffset from what was created with, but it // is close enough because the SHA-1 hash is calculated using the DateTimeOffset.ToString(), so // only the ToString() representations of the DateTimeOffsets need to match. DateTimeOffset tmpDate; if (!DateTimeOffset.TryParse(line.Substring("date ".Length), out tmpDate)) { return(new TagParseBadDateFormatError()); } tb.DateTagged = tmpDate; // Skip empty line: line = sr.ReadLine(); if (line == null || line.Length != 0) { return(new TagParseExpectedBlankLineError()); } // Set Message: tb.Message = sr.ReadToEnd(); } // Create the immutable Tag from the Builder: Tag tg = tb; // Validate the computed TagID: if (tg.ID != id) { return(new ComputedTagIDMismatchError(tg.ID, id)); } return(tg); }