public AddTree ( byte s, int offset ) : |
||
s | byte | an array containing the name |
offset | int | when the name starts in the tree. |
Résultat |
/// <summary> /// Adds a new or existing Tree with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </summary> /// <param name="s"> an array containing the name </param> /// <param name="offset"> when the name starts in the tree.</param> /// <returns>A <seealso cref="FileTreeEntry"/> for the added tree.</returns> /// <exception cref="IOException"></exception> public Tree AddTree(byte[] s, int offset) { int slash; for (slash = offset; slash < s.Length && s[slash] != '/'; slash++) { // search for path component terminator } EnsureLoaded(); int p = BinarySearch(_contents, s, (byte)'/', offset, slash); if (p >= 0 && slash < s.Length && _contents[p] is Tree) { return(((Tree)_contents[p]).AddTree(s, slash + 1)); } byte[] newName = SubString(s, offset, slash); if (p >= 0) { throw new EntryExistsException(RawParseUtils.decode(newName)); } Tree t = new Tree(this, newName); InsertEntry(p, t); return(slash == s.Length ? t : t.AddTree(s, slash + 1)); }
private void FillTree(DirectoryInfo dir, Core.Tree tree) { foreach (var subdir in dir.GetDirectories()) { if (subdir.Name == Constants.DOT_GIT || IgnoreHandler.IsIgnored(tree.FullName + "/" + subdir.Name)) { continue; } var t = tree.AddTree(subdir.Name); FillTree(subdir, t); } foreach (var file in dir.GetFiles()) { if (IgnoreHandler.IsIgnored(tree.FullName + "/" + file.Name)) { continue; } tree.AddFile((file.Name)); } }
void WriteTree(ObjectWriter writer, Core.Tree headTree, GitIndex index, Core.Tree tree, DirectoryInfo dir) { foreach (var fsi in dir.GetFileSystemInfos()) { if (fsi is FileInfo) { // Exclude untracked files string gname = _repo.ToGitPath(fsi.FullName); bool inIndex = index.GetEntry(gname) != null; bool inHead = headTree.FindBlobMember(gname) != null; if (inIndex || inHead) { var entry = tree.AddFile(fsi.Name); entry.Id = writer.WriteBlob((FileInfo)fsi); } } else if (fsi.Name != Constants.DOT_GIT) { var child = tree.AddTree(fsi.Name); WriteTree(writer, headTree, index, child, (DirectoryInfo)fsi); child.Id = writer.WriteTree(child); } } }
/// <summary> /// Adds a new or existing Tree with the specified name to this tree. /// Trees are added if necessary as the name may contain '/':s. /// </summary> /// <param name="s"> an array containing the name </param> /// <param name="offset"> when the name starts in the tree.</param> /// <returns>A <seealso cref="FileTreeEntry"/> for the added tree.</returns> /// <exception cref="IOException"></exception> public Tree AddTree(byte[] s, int offset) { int slash; for (slash = offset; slash < s.Length && s[slash] != '/'; slash++) { // search for path component terminator } EnsureLoaded(); int p = BinarySearch(_contents, s, (byte)'/', offset, slash); if (p >= 0 && slash < s.Length && _contents[p] is Tree) { return ((Tree)_contents[p]).AddTree(s, slash + 1); } byte[] newName = SubString(s, offset, slash); if (p >= 0) { throw new EntryExistsException(RawParseUtils.decode(newName)); } Tree t = new Tree(this, newName); InsertEntry(p, t); return slash == s.Length ? t : t.AddTree(s, slash + 1); }
public void testTwoSuccessiveCommitsLinkedToHead() { var repo = createNewEmptyRepo(); var workingDirectory = repo.WorkingDirectory; repo.Create(); var objectWriter = new ObjectWriter(repo); FileInfo project1_a_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/A.txt"), "A.txt - first version\n"); FileInfo project1_b_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - first version\n"); var tree = new Tree(repo); Tree projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); var commit = new Commit(repo) { Author = new PersonIdent(jauthor, (0L), 60), Committer = new PersonIdent(jcommitter, (0L), 60), Message = "Foo\n\nMessage", TreeEntry = tree }; commit.Save(); var commitId = commit.CommitId; FileInfo project1_b_v2_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - second version\n"); tree = new Tree(repo); projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_v2_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); commit = new Commit(repo) { Author = new PersonIdent(jauthor, (0L), 60), Committer = new PersonIdent(jcommitter, (0L), 60), Message = "Modified", ParentIds = new[] { commitId }, TreeEntry = tree }; commit.Save(); commitId = commit.CommitId; RefUpdate lck = repo.UpdateRef("refs/heads/master"); Assert.IsNotNull(lck, "obtained lock"); lck.NewObjectId = commitId; Assert.AreEqual(RefUpdate.RefUpdateResult.New, lck.ForceUpdate()); }
public void test008_SubtreeInternalSorting() { var t = new Tree(db); FileTreeEntry e0 = t.AddFile("a-b"); FileTreeEntry e1 = t.AddFile("a-"); FileTreeEntry e2 = t.AddFile("a=b"); Tree e3 = t.AddTree("a"); FileTreeEntry e4 = t.AddFile("a="); TreeEntry[] ents = t.Members; Assert.AreSame(e1, ents[0]); Assert.AreSame(e0, ents[1]); Assert.AreSame(e3, ents[2]); Assert.AreSame(e4, ents[3]); Assert.AreSame(e2, ents[4]); }
public void test006_addDeepTree() { var t = new Tree(db); Tree e = t.AddTree("e"); Assert.IsNotNull(e); Assert.IsTrue(e.Parent == t); Tree f = t.AddTree("f"); Assert.IsNotNull(f); Assert.IsTrue(f.Parent == t); Tree g = f.AddTree("g"); Assert.IsNotNull(g); Assert.IsTrue(g.Parent == f); Tree h = g.AddTree("h"); Assert.IsNotNull(h); Assert.IsTrue(h.Parent == g); h.Id = SomeFakeId; Assert.IsTrue(!h.IsModified); g.Id = SomeFakeId; Assert.IsTrue(!g.IsModified); f.Id = SomeFakeId; Assert.IsTrue(!f.IsModified); e.Id = SomeFakeId; Assert.IsTrue(!e.IsModified); t.Id = SomeFakeId; Assert.IsTrue(!t.IsModified); Assert.AreEqual("f/g/h", h.FullName); Assert.IsTrue(t.findTreeMember(h.FullName) == h); Assert.IsTrue(t.FindBlobMember("f/z") == null); Assert.IsTrue(t.FindBlobMember("y/z") == null); FileTreeEntry i = h.AddFile("i"); Assert.IsNotNull(i); Assert.AreEqual("f/g/h/i", i.FullName); Assert.IsTrue(t.FindBlobMember(i.FullName) == i); Assert.IsTrue(h.IsModified); Assert.IsTrue(g.IsModified); Assert.IsTrue(f.IsModified); Assert.IsTrue(!e.IsModified); Assert.IsTrue(t.IsModified); Assert.IsTrue(h.Id == null); Assert.IsTrue(g.Id == null); Assert.IsTrue(f.Id == null); Assert.IsTrue(e.Id != null); Assert.IsTrue(t.Id == null); }
public void test005_addRecursiveTree() { var t = new Tree(db); Tree f = t.AddTree("a/b/c"); Assert.IsNotNull(f); Assert.AreEqual(f.Name, "c"); Assert.AreEqual(f.Parent.Name, "b"); Assert.AreEqual(f.Parent.Parent.Name, "a"); Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent"); }
public void test004_addTree() { var t = new Tree(db) {Id = SomeFakeId}; Assert.IsTrue(t.Id != null); Assert.IsFalse(t.IsModified); const string n = "bob"; Tree f = t.AddTree(n); Assert.IsNotNull(f); Assert.AreEqual(n, f.Name); Assert.AreEqual(f.Name, Constants.CHARSET.GetString(f.NameUTF8)); Assert.AreEqual(n, f.FullName); Assert.IsTrue(f.Id == null); Assert.IsTrue(f.Parent == t); Assert.IsTrue(f.Repository == db); Assert.IsTrue(f.IsLoaded); Assert.IsFalse(f.Members.Length > 0); Assert.IsFalse(f.IsRoot); Assert.IsTrue(f.TreeEntry == f); Assert.IsTrue(t.IsModified); Assert.IsTrue(t.Id == null); Assert.IsTrue(t.findTreeMember(f.Name) == f); TreeEntry[] i = t.Members; Assert.IsTrue(i.Length > 0); Assert.IsTrue(i[0] == f); Assert.IsTrue(i.Length == 1); }
public void testSimpleT() { Tree tree = new Tree(db); tree.AddTree("a"); TreeIterator i = MakeIterator(tree); Assert.IsFalse(i.hasNext()); }
public void testSimpleT() { Tree tree = new Tree(db); tree.AddTree("a"); TreeIterator i = makeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsFalse(i.hasNext()); }
public void testMissingSubtree_DetectFileAdded_FileModified() { var ow = new ObjectWriter(db); ObjectId aFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("a")); ObjectId bFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("b")); ObjectId cFileId1 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-1")); ObjectId cFileId2 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-2")); // Create sub-a/empty, sub-c/empty = hello. Func<ObjectId> oldTree = () => { var root = new Tree(db); Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").Id = aFileId; subA.Id = ow.WriteTree(subA); Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").Id = cFileId1; subC.Id = ow.WriteTree(subC); return ow.WriteTree(root); }; // Create sub-a/empty, sub-b/empty, sub-c/empty. Func<ObjectId> newTree = () => { var root = new Tree(db); Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").Id = aFileId; subA.Id = ow.WriteTree(subA); Tree subB = root.AddTree("sub-b"); subB.AddFile("empty").Id = bFileId; subB.Id = ow.WriteTree(subB); Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").Id = cFileId2; subC.Id = ow.WriteTree(subC); return ow.WriteTree(root); }; var tw = new GitSharp.Core.TreeWalk.TreeWalk(db); tw.reset(new[] { oldTree.Invoke(), newTree.Invoke() }); tw.Recursive = true; tw.setFilter(TreeFilter.ANY_DIFF); Assert.IsTrue(tw.next()); Assert.AreEqual("sub-b/empty", tw.getPathString()); Assert.AreEqual(FileMode.Missing, tw.getFileMode(0)); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1)); Assert.AreEqual(ObjectId.ZeroId, tw.getObjectId(0)); Assert.AreEqual(bFileId, tw.getObjectId(1)); Assert.IsTrue(tw.next()); Assert.AreEqual("sub-c/empty", tw.getPathString()); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(0)); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1)); Assert.AreEqual(cFileId1, tw.getObjectId(0)); Assert.AreEqual(cFileId2, tw.getObjectId(1)); Assert.IsFalse(tw.next()); }