本文整理汇总了C#中NGit.Tree.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddFile方法的具体用法?C# Tree.AddFile怎么用?C# Tree.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Tree
的用法示例。
在下文中一共展示了Tree.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBoth
public virtual void TestBoth()
{
GitIndex index = new GitIndex(db);
Tree tree = new Tree(db);
index.Add(trash, WriteTrashFile("a", "a"));
tree.AddFile("b/b");
index.Add(trash, WriteTrashFile("c", "c"));
tree.AddFile("c");
new IndexTreeWalker(index, tree, trash, new IndexTreeWalkerTest.TestIndexTreeVisitor
(this)).Walk();
NUnit.Framework.Assert.IsTrue(indexOnlyEntriesVisited.Contains("a"));
NUnit.Framework.Assert.IsTrue(treeOnlyEntriesVisited.Contains("b/b"));
NUnit.Framework.Assert.IsTrue(bothVisited.Contains("c"));
}
示例2: TestSimpleF1
public virtual void TestSimpleF1()
{
Tree tree = new Tree(db);
tree.AddFile("x");
TreeIterator i = MakeIterator(tree);
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("x", i.Next().GetName());
}
示例3: Test012_SubtreeExternalSorting
public virtual void Test012_SubtreeExternalSorting()
{
ObjectId emptyBlob = InsertEmptyBlob();
Tree t = new Tree(db);
FileTreeEntry e0 = t.AddFile("a-");
FileTreeEntry e1 = t.AddFile("a-b");
FileTreeEntry e2 = t.AddFile("a/b");
FileTreeEntry e3 = t.AddFile("a=");
FileTreeEntry e4 = t.AddFile("a=b");
e0.SetId(emptyBlob);
e1.SetId(emptyBlob);
e2.SetId(emptyBlob);
e3.SetId(emptyBlob);
e4.SetId(emptyBlob);
Tree a = (Tree)t.FindTreeMember("a");
a.SetId(InsertTree(a));
NUnit.Framework.Assert.AreEqual(ObjectId.FromString("b47a8f0a4190f7572e11212769090523e23eb1ea"
), InsertTree(t));
}
示例4: TestTricky
public virtual void TestTricky()
{
Tree tree = new Tree(db);
tree.AddFile("a.b");
tree.AddFile("a.c");
tree.AddFile("a/b.b/b");
tree.AddFile("a/b");
tree.AddFile("a/c");
tree.AddFile("a=c");
tree.AddFile("a=d");
TreeIterator i = MakeIterator(tree);
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a.b", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a.c", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a/b", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a/b.b/b", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a/c", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a=c", i.Next().GetFullName());
NUnit.Framework.Assert.IsTrue(i.HasNext());
NUnit.Framework.Assert.AreEqual("a=d", i.Next().GetFullName());
NUnit.Framework.Assert.IsFalse(i.HasNext());
}
示例5: AddFile
/// <summary>Adds a new or existing file with the specified name to this tree.</summary>
/// <remarks>
/// Adds a new or existing file with the specified name to this tree.
/// Trees are added if necessary as the name may contain '/':s.
/// </remarks>
/// <param name="s">an array containing the name</param>
/// <param name="offset">when the name starts in the tree.</param>
/// <returns>
/// a
/// <see cref="FileTreeEntry">FileTreeEntry</see>
/// for the added file.
/// </returns>
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
public virtual FileTreeEntry AddFile(byte[] s, int offset)
{
int slash;
int p;
for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
{
}
// search for path component terminator
EnsureLoaded();
byte xlast = slash < s.Length ? unchecked((byte)(byte)('/')) : (byte)0;
p = BinarySearch(contents, s, xlast, offset, slash);
if (p >= 0 && slash < s.Length && contents[p] is NGit.Tree)
{
return ((NGit.Tree)contents[p]).AddFile(s, slash + 1);
}
byte[] newName = Substring(s, offset, slash);
if (p >= 0)
{
throw new EntryExistsException(RawParseUtils.Decode(newName));
}
else
{
if (slash < s.Length)
{
NGit.Tree t = new NGit.Tree(this, newName);
InsertEntry(p, t);
return t.AddFile(s, slash + 1);
}
else
{
FileTreeEntry f = new FileTreeEntry(this, null, newName, false);
InsertEntry(p, f);
return f;
}
}
}
示例6: TestEmptyTreeCorruption
public virtual void TestEmptyTreeCorruption()
{
ObjectId bId = ObjectId.FromString("abbbfafe3129f85747aba7bfac992af77134c607");
RevTree tree_root;
RevTree tree_A;
RevTree tree_AB;
RevCommit b;
{
Tree root = new Tree(db);
Tree A = root.AddTree("A");
FileTreeEntry B = root.AddFile("B");
B.SetId(bId);
Tree A_A = A.AddTree("A");
Tree A_B = A.AddTree("B");
ObjectInserter inserter = db.NewObjectInserter();
try
{
A_A.SetId(inserter.Insert(Constants.OBJ_TREE, A_A.Format()));
A_B.SetId(inserter.Insert(Constants.OBJ_TREE, A_B.Format()));
A.SetId(inserter.Insert(Constants.OBJ_TREE, A.Format()));
root.SetId(inserter.Insert(Constants.OBJ_TREE, root.Format()));
inserter.Flush();
}
finally
{
inserter.Release();
}
tree_root = rw.ParseTree(root.GetId());
tree_A = rw.ParseTree(A.GetId());
tree_AB = rw.ParseTree(A_A.GetId());
NUnit.Framework.Assert.AreSame(tree_AB, rw.ParseTree(A_B.GetId()));
b = Commit(rw.ParseTree(root.GetId()));
}
MarkStart(b);
AssertCommit(b, objw.Next());
NUnit.Framework.Assert.IsNull(objw.Next());
NUnit.Framework.Assert.AreSame(tree_root, objw.NextObject());
NUnit.Framework.Assert.AreSame(tree_A, objw.NextObject());
NUnit.Framework.Assert.AreSame(tree_AB, objw.NextObject());
NUnit.Framework.Assert.AreSame(rw.LookupBlob(bId), objw.NextObject());
NUnit.Framework.Assert.IsNull(objw.NextObject());
}
示例7: Test008_SubtreeInternalSorting
public virtual void Test008_SubtreeInternalSorting()
{
Tree 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();
NUnit.Framework.Assert.AreSame(e1, ents[0]);
NUnit.Framework.Assert.AreSame(e0, ents[1]);
NUnit.Framework.Assert.AreSame(e3, ents[2]);
NUnit.Framework.Assert.AreSame(e4, ents[3]);
NUnit.Framework.Assert.AreSame(e2, ents[4]);
}
示例8: TestModified
public virtual void TestModified()
{
GitIndex index = new GitIndex(db);
index.Add(trash, WriteTrashFile("file2", "file2"));
index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
index.Write();
WriteTrashFile("dir/file3", "changed");
Tree tree = new Tree(db);
tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
));
tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
));
NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
Tree tree2 = (Tree)tree.FindTreeMember("dir");
tree2.SetId(InsertTree(tree2));
tree.SetId(InsertTree(tree));
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
diff.Diff();
NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
}
示例9: Test005_addRecursiveFile
public virtual void Test005_addRecursiveFile()
{
Tree t = new Tree(db);
FileTreeEntry f = t.AddFile("a/b/c");
NUnit.Framework.Assert.IsNotNull(f, "created f");
NUnit.Framework.Assert.AreEqual("c", f.GetName());
NUnit.Framework.Assert.AreEqual("b", f.GetParent().GetName());
NUnit.Framework.Assert.AreEqual("a", f.GetParent().GetParent().GetName());
NUnit.Framework.Assert.IsTrue(t == f.GetParent().GetParent().GetParent(), "t is great-grandparent"
);
}
示例10: Test002_addFile
public virtual void Test002_addFile()
{
Tree t = new Tree(db);
t.SetId(SOME_FAKE_ID);
NUnit.Framework.Assert.IsTrue(t.GetId() != null, "has id");
NUnit.Framework.Assert.IsFalse(t.IsModified(), "not modified");
string n = "bob";
FileTreeEntry f = t.AddFile(n);
NUnit.Framework.Assert.IsNotNull(f, "have file");
NUnit.Framework.Assert.AreEqual(n, f.GetName(), "name matches");
NUnit.Framework.Assert.AreEqual(f.GetName(), Sharpen.Runtime.GetStringForBytes(f.
GetNameUTF8(), "UTF-8"), "name matches");
NUnit.Framework.Assert.AreEqual(n, f.GetFullName(), "full name matches");
NUnit.Framework.Assert.IsTrue(f.GetId() == null, "no id");
NUnit.Framework.Assert.IsTrue(t.IsModified(), "is modified");
NUnit.Framework.Assert.IsTrue(t.GetId() == null, "has no id");
NUnit.Framework.Assert.IsTrue(t.FindBlobMember(f.GetName()) == f, "found bob");
TreeEntry[] i = t.Members();
NUnit.Framework.Assert.IsNotNull(i, "members array not null");
NUnit.Framework.Assert.IsTrue(i != null && i.Length > 0, "iterator is not empty");
NUnit.Framework.Assert.IsTrue(i != null && i[0] == f, "iterator returns file");
NUnit.Framework.Assert.IsTrue(i != null && i.Length == 1, "iterator is empty");
}
示例11: TestUnchangedSimple
public virtual void TestUnchangedSimple()
{
WriteTrashFile("a.b", "a.b");
WriteTrashFile("a.c", "a.c");
WriteTrashFile("a=c", "a=c");
WriteTrashFile("a=d", "a=d");
Git git = new Git(db);
git.Add().AddFilepattern("a.b").Call();
git.Add().AddFilepattern("a.c").Call();
git.Add().AddFilepattern("a=c").Call();
git.Add().AddFilepattern("a=d").Call();
Tree tree = new Tree(db);
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
));
tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
));
tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
));
tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
));
tree.SetId(InsertTree(tree));
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
diff.Diff();
NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
);
}
示例12: TestUnchangedComplex
public virtual void TestUnchangedComplex()
{
Git git = new Git(db);
WriteTrashFile("a.b", "a.b");
WriteTrashFile("a.c", "a.c");
WriteTrashFile("a/b.b/b", "a/b.b/b");
WriteTrashFile("a/b", "a/b");
WriteTrashFile("a/c", "a/c");
WriteTrashFile("a=c", "a=c");
WriteTrashFile("a=d", "a=d");
git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
Tree tree = new Tree(db);
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
));
tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
));
tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
));
tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
));
tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
));
tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
));
tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
));
Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");
tree3.SetId(InsertTree(tree3));
Tree tree2 = (Tree)tree.FindTreeMember("a");
tree2.SetId(InsertTree(tree2));
tree.SetId(InsertTree(tree));
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
diff.Diff();
NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
);
}
示例13: TestRemoved
public virtual void TestRemoved()
{
WriteTrashFile("file2", "file2");
WriteTrashFile("dir/file3", "dir/file3");
Tree tree = new Tree(db);
tree.AddFile("file2");
tree.AddFile("dir/file3");
NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
));
Tree tree2 = (Tree)tree.FindTreeMember("dir");
tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
));
tree2.SetId(InsertTree(tree2));
tree.SetId(InsertTree(tree));
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
diff.Diff();
NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
);
}
示例14: TestModified
public virtual void TestModified()
{
WriteTrashFile("file2", "file2");
WriteTrashFile("dir/file3", "dir/file3");
Git git = new Git(db);
git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
WriteTrashFile("dir/file3", "changed");
Tree tree = new Tree(db);
tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
));
tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
));
NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
Tree tree2 = (Tree)tree.FindTreeMember("dir");
tree2.SetId(InsertTree(tree2));
tree.SetId(InsertTree(tree));
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
diff.Diff();
NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
);
}
示例15: TestTreeOnlyOneLevel
public virtual void TestTreeOnlyOneLevel()
{
GitIndex index = new GitIndex(db);
Tree tree = new Tree(db);
tree.AddFile("foo");
tree.AddFile("bar");
new IndexTreeWalker(index, tree, trash, new IndexTreeWalkerTest.TestIndexTreeVisitor
(this)).Walk();
NUnit.Framework.Assert.IsTrue(treeOnlyEntriesVisited[0].Equals("bar"));
NUnit.Framework.Assert.IsTrue(treeOnlyEntriesVisited[1].Equals("foo"));
}