本文整理汇总了C#中TreeWalk.AddTree方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.AddTree方法的具体用法?C# TreeWalk.AddTree怎么用?C# TreeWalk.AddTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.AddTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNoDF_NoGap
public virtual void TestNoDF_NoGap()
{
DirCache tree0 = db.ReadDirCache();
DirCache tree1 = db.ReadDirCache();
{
DirCacheBuilder b0 = tree0.Builder();
DirCacheBuilder b1 = tree1.Builder();
b0.Add(MakeEntry("a", REGULAR_FILE));
b0.Add(MakeEntry("a.b", EXECUTABLE_FILE));
b1.Add(MakeEntry("a/b", REGULAR_FILE));
b0.Add(MakeEntry("a0b", SYMLINK));
b0.Finish();
b1.Finish();
NUnit.Framework.Assert.AreEqual(3, tree0.GetEntryCount());
NUnit.Framework.Assert.AreEqual(1, tree1.GetEntryCount());
}
TreeWalk tw = new TreeWalk(db);
tw.AddTree(new DirCacheIterator(tree0));
tw.AddTree(new DirCacheIterator(tree1));
AssertModes("a", REGULAR_FILE, MISSING, tw);
AssertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
AssertModes("a", MISSING, TREE, tw);
tw.EnterSubtree();
AssertModes("a/b", MISSING, REGULAR_FILE, tw);
AssertModes("a0b", SYMLINK, MISSING, tw);
}
示例2: TestNonRecursiveFiltering
public virtual void TestNonRecursiveFiltering()
{
ObjectInserter odi = db.NewObjectInserter();
ObjectId aSth = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
"a.sth"));
ObjectId aTxt = odi.Insert(Constants.OBJ_BLOB, Sharpen.Runtime.GetBytesForString(
"a.txt"));
DirCache dc = db.ReadDirCache();
DirCacheBuilder builder = dc.Builder();
DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
aSthEntry.FileMode = FileMode.REGULAR_FILE;
aSthEntry.SetObjectId(aSth);
DirCacheEntry aTxtEntry = new DirCacheEntry("a.txt");
aTxtEntry.FileMode = FileMode.REGULAR_FILE;
aTxtEntry.SetObjectId(aTxt);
builder.Add(aSthEntry);
builder.Add(aTxtEntry);
builder.Finish();
ObjectId treeId = dc.WriteTree(odi);
odi.Flush();
TreeWalk tw = new TreeWalk(db);
tw.Filter = PathSuffixFilter.Create(".txt");
tw.AddTree(treeId);
IList<string> paths = new List<string>();
while (tw.Next())
{
paths.AddItem(tw.PathString);
}
IList<string> expected = new List<string>();
expected.AddItem("a.txt");
NUnit.Framework.Assert.AreEqual(expected, paths);
}
示例3: TestEmptyTree_WithTreeWalk
public virtual void TestEmptyTree_WithTreeWalk()
{
DirCache dc = DirCache.NewInCore();
NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
TreeWalk tw = new TreeWalk(db);
tw.AddTree(new DirCacheIterator(dc));
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例4: GetFileDiffs
public IEnumerable<FileDiff> GetFileDiffs(string newHash, string oldHash)
{
NGit.Repository repo = this.git.GetRepository();
ObjectId newCommit = repo.Resolve(newHash + "^{tree}");
ObjectId oldCommit = repo.Resolve(oldHash + "^{tree}");
var walk = new TreeWalk(repo) { Recursive = true };
walk.AddTree(oldCommit);
walk.AddTree(newCommit);
IEnumerable<DiffEntry> entries = DiffEntry.Scan(walk);
var diffs = entries.Where(diff => diff.GetNewId().Name != diff.GetOldId().Name);
return from diffEntry in diffs
let diffType = ToDiffType(diffEntry.GetChangeType())
let path = diffType == DiffType.Delete ? diffEntry.GetOldPath() : diffEntry.GetNewPath()
select new FileDiff(path, diffType);
}
示例5: ShouldListAddedFileInInitialCommit
public virtual void ShouldListAddedFileInInitialCommit()
{
// given
WriteTrashFile("a.txt", "content");
Git git = new Git(db);
git.Add().AddFilepattern("a.txt").Call();
RevCommit c = git.Commit().SetMessage("initial commit").Call();
// when
TreeWalk walk = new TreeWalk(db);
walk.AddTree(new EmptyTreeIterator());
walk.AddTree(c.Tree);
IList<DiffEntry> result = DiffEntry.Scan(walk);
// then
Assert.IsNotNull (result);
Assert.AreEqual(1, result.Count);
DiffEntry entry = result[0];
Assert.AreEqual(entry.GetChangeType(), DiffEntry.ChangeType.ADD);
Assert.AreEqual(entry.GetNewPath(), "a.txt");
Assert.AreEqual(entry.GetOldPath(), DiffEntry.DEV_NULL);
}
示例6: GetConflictedFiles
public static List<string> GetConflictedFiles (NGit.Repository repo)
{
List<string> list = new List<string> ();
TreeWalk treeWalk = new TreeWalk (repo);
treeWalk.Reset ();
treeWalk.Recursive = true;
DirCache dc = repo.ReadDirCache ();
treeWalk.AddTree (new DirCacheIterator (dc));
while (treeWalk.Next()) {
DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(0);
var ce = dirCacheIterator.GetDirCacheEntry ();
if (ce != null && ce.Stage == 1)
list.Add (ce.PathString);
}
return list;
}
示例7: TestPathFilterGroup_DoesNotSkipTail
public virtual void TestPathFilterGroup_DoesNotSkipTail()
{
DirCache dc = db.ReadDirCache();
FileMode mode = FileMode.REGULAR_FILE;
string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" };
DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].FileMode = mode;
}
{
DirCacheBuilder b = dc.Builder();
for (int i_1 = 0; i_1 < ents.Length; i_1++)
{
b.Add(ents[i_1]);
}
b.Finish();
}
int expIdx = 2;
DirCacheBuilder b_1 = dc.Builder();
TreeWalk tw = new TreeWalk(db);
tw.AddTree(new DirCacheBuildIterator(b_1));
tw.Recursive = true;
tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[expIdx]
));
NUnit.Framework.Assert.IsTrue(tw.Next(), "found " + paths[expIdx]);
DirCacheIterator c = tw.GetTree<DirCacheIterator>(0);
NUnit.Framework.Assert.IsNotNull(c);
NUnit.Framework.Assert.AreEqual(expIdx, c.ptr);
NUnit.Framework.Assert.AreSame(ents[expIdx], c.GetDirCacheEntry());
NUnit.Framework.Assert.AreEqual(paths[expIdx], tw.PathString);
NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
b_1.Add(c.GetDirCacheEntry());
NUnit.Framework.Assert.IsFalse(tw.Next(), "no more entries");
b_1.Finish();
NUnit.Framework.Assert.AreEqual(ents.Length, dc.GetEntryCount());
for (int i_2 = 0; i_2 < ents.Length; i_2++)
{
NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(i_2));
}
}
示例8: GetFileContent
public static string GetFileContent(this RevCommit commit, string path, Repository repository)
{
var treeWalk = new TreeWalk(repository) {Recursive = true, Filter = PathFilter.Create(path)};
treeWalk.AddTree(commit.Tree);
if (!treeWalk.Next())
{
return string.Empty;
}
var objectId = treeWalk.GetObjectId(0);
var loader = repository.Open(objectId);
using (var stream = loader.OpenStream())
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
示例9: AssertWorkDir
/// <exception cref="NGit.Errors.CorruptObjectException"></exception>
/// <exception cref="System.IO.IOException"></exception>
public virtual void AssertWorkDir(Dictionary<string, string> i)
{
TreeWalk walk = new TreeWalk(db);
walk.Recursive = true;
walk.AddTree(new FileTreeIterator(db));
string expectedValue;
string path;
int nrFiles = 0;
FileTreeIterator ft;
while (walk.Next())
{
ft = walk.GetTree<FileTreeIterator>(0);
path = ft.EntryPathString;
expectedValue = i.Get(path);
NUnit.Framework.Assert.IsNotNull(expectedValue, "found unexpected file for path "
+ path + " in workdir");
FilePath file = new FilePath(db.WorkTree, path);
NUnit.Framework.Assert.IsTrue(file.Exists());
if (file.IsFile())
{
FileInputStream @is = new FileInputStream(file);
byte[] buffer = new byte[(int)file.Length()];
int offset = 0;
int numRead = 0;
while (offset < buffer.Length && (numRead = @is.Read(buffer, offset, buffer.Length
- offset)) >= 0)
{
offset += numRead;
}
@is.Close();
CollectionAssert.AreEqual (buffer, Sharpen.Runtime.GetBytesForString(i.Get(path)),
"unexpected content for path " + path + " in workDir. ");
nrFiles++;
}
}
NUnit.Framework.Assert.AreEqual(i.Count, nrFiles, "WorkDir has not the right size."
);
}
示例10: files
public static API_NGit files(this API_NGit nGit,string commitId, Action<TreeWalk> onTreeWalk)
{
try
{
var headCommit = nGit.Repository.Resolve(commitId);
if (commitId.notNull())
{
var revWalk = new RevWalk(nGit.Repository);
var commit = revWalk.ParseCommit(headCommit);
var treeWalk = new TreeWalk(nGit.Repository);
var tree = commit.Tree;
treeWalk.AddTree(tree);
treeWalk.Recursive = true;
while (treeWalk.Next())
onTreeWalk(treeWalk);
}
}
catch (Exception ex)
{
ex.log("[API_NGit][getRepoFiles]");
}
return nGit ;
}
示例11: SubmoduleWithNoHead
public virtual void SubmoduleWithNoHead()
{
Git git = new Git(db);
WriteTrashFile("file.txt", "content");
git.Add().AddFilepattern("file.txt").Call();
RevCommit id = git.Commit().SetMessage("create file").Call();
string path = "sub";
DirCache cache = db.LockDirCache();
DirCacheEditor editor = cache.Editor();
editor.Add(new _PathEdit_345(id, path));
editor.Commit();
NUnit.Framework.Assert.IsNotNull(Git.Init().SetDirectory(new FilePath(db.WorkTree
, path)).Call().GetRepository());
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.AddTree(indexIter);
walk.AddTree(workTreeIter);
walk.Filter = PathFilter.Create(path);
NUnit.Framework.Assert.IsTrue(walk.Next());
NUnit.Framework.Assert.IsFalse(indexIter.IdEqual(workTreeIter));
NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, workTreeIter.EntryObjectId);
}
示例12: SubmoduleNestedWithHeadMatchingIndex
public virtual void SubmoduleNestedWithHeadMatchingIndex()
{
Git git = new Git(db);
WriteTrashFile("file.txt", "content");
git.Add().AddFilepattern("file.txt").Call();
RevCommit id = git.Commit().SetMessage("create file").Call();
string path = "sub/dir1/dir2";
DirCache cache = db.LockDirCache();
DirCacheEditor editor = cache.Editor();
editor.Add(new _PathEdit_412(id, path));
editor.Commit();
Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()).SetDirectory(new FilePath
(db.WorkTree, path)).Call().GetRepository().Close();
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.AddTree(indexIter);
walk.AddTree(workTreeIter);
walk.Filter = PathFilter.Create(path);
NUnit.Framework.Assert.IsTrue(walk.Next());
NUnit.Framework.Assert.IsTrue(indexIter.IdEqual(workTreeIter));
}
示例13: TestRemovedSubtree
public virtual void TestRemovedSubtree()
{
FilePath path = JGitTestUtil.GetTestResourceFile("dircache.testRemovedSubtree");
DirCache dc = DirCache.Read(path, FS.DETECTED);
NUnit.Framework.Assert.AreEqual(2, dc.GetEntryCount());
TreeWalk tw = new TreeWalk(db);
tw.Recursive = true;
tw.AddTree(new DirCacheIterator(dc));
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("a/a", tw.PathString);
NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, tw.GetFileMode(0));
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("q", tw.PathString);
NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, tw.GetFileMode(0));
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例14: TestTwoLevelSubtree_FilterPath
public virtual void TestTwoLevelSubtree_FilterPath()
{
DirCache dc = DirCache.NewInCore();
FileMode mode = FileMode.REGULAR_FILE;
string[] paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].FileMode = mode;
}
DirCacheBuilder b = dc.Builder();
for (int i_1 = 0; i_1 < ents.Length; i_1++)
{
b.Add(ents[i_1]);
}
b.Finish();
TreeWalk tw = new TreeWalk(db);
for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
{
tw.Reset();
tw.AddTree(new DirCacheIterator(dc));
tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[victimIdx
]));
tw.Recursive = tw.Filter.ShouldBeRecursive();
NUnit.Framework.Assert.IsTrue(tw.Next());
DirCacheIterator c = tw.GetTree<DirCacheIterator>(0);
NUnit.Framework.Assert.IsNotNull(c);
NUnit.Framework.Assert.AreEqual(victimIdx, c.ptr);
NUnit.Framework.Assert.AreSame(ents[victimIdx], c.GetDirCacheEntry());
NUnit.Framework.Assert.AreEqual(paths[victimIdx], tw.PathString);
NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
NUnit.Framework.Assert.IsFalse(tw.Next());
}
}
示例15: TestTwoLevelSubtree_Recursive
public virtual void TestTwoLevelSubtree_Recursive()
{
DirCache dc = DirCache.NewInCore();
FileMode mode = FileMode.REGULAR_FILE;
string[] paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].FileMode = mode;
}
DirCacheBuilder b = dc.Builder();
for (int i_1 = 0; i_1 < ents.Length; i_1++)
{
b.Add(ents[i_1]);
}
b.Finish();
TreeWalk tw = new TreeWalk(db);
tw.AddTree(new DirCacheIterator(dc));
tw.Recursive = true;
int pathIdx = 0;
while (tw.Next())
{
DirCacheIterator c = tw.GetTree<DirCacheIterator>(0);
NUnit.Framework.Assert.IsNotNull(c);
NUnit.Framework.Assert.AreEqual(pathIdx, c.ptr);
NUnit.Framework.Assert.AreSame(ents[pathIdx], c.GetDirCacheEntry());
NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString);
NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
pathIdx++;
}
NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx);
}