本文整理汇总了C#中TreeWalk.Next方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.Next方法的具体用法?C# TreeWalk.Next怎么用?C# TreeWalk.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.Next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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());
}
示例3: 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;
}
示例4: 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));
}
}
示例5: 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();
}
}
}
示例6: 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 ;
}
示例7: 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);
}
示例8: AddTree
/// <summary>Recursively add an entire tree into this builder.</summary>
/// <remarks>
/// Recursively add an entire tree into this builder.
/// <p>
/// If pathPrefix is "a/b" and the tree contains file "c" then the resulting
/// DirCacheEntry will have the path "a/b/c".
/// <p>
/// All entries are inserted at stage 0, therefore assuming that the
/// application will not insert any other paths with the same pathPrefix.
/// </remarks>
/// <param name="pathPrefix">
/// UTF-8 encoded prefix to mount the tree's entries at. If the
/// path does not end with '/' one will be automatically inserted
/// as necessary.
/// </param>
/// <param name="stage">stage of the entries when adding them.</param>
/// <param name="reader">
/// reader the tree(s) will be read from during recursive
/// traversal. This must be the same repository that the resulting
/// DirCache would be written out to (or used in) otherwise the
/// caller is simply asking for deferred MissingObjectExceptions.
/// Caller is responsible for releasing this reader when done.
/// </param>
/// <param name="tree">
/// the tree to recursively add. This tree's contents will appear
/// under <code>pathPrefix</code>. The ObjectId must be that of a
/// tree; the caller is responsible for dereferencing a tag or
/// commit (if necessary).
/// </param>
/// <exception cref="System.IO.IOException">a tree cannot be read to iterate through its entries.
/// </exception>
public virtual void AddTree(byte[] pathPrefix, int stage, ObjectReader reader, AnyObjectId
tree)
{
TreeWalk tw = new TreeWalk(reader);
tw.AddTree(new CanonicalTreeParser(pathPrefix, reader, tree.ToObjectId()));
tw.Recursive = true;
if (tw.Next())
{
DirCacheEntry newEntry = ToEntry(stage, tw);
BeforeAdd(newEntry);
FastAdd(newEntry);
while (tw.Next())
{
FastAdd(ToEntry(stage, tw));
}
}
}
示例9: 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());
}
}
示例10: Scan
/// <summary>
/// Convert the TreeWalk into DiffEntry headers, depending on
/// <code>includeTrees</code>
/// it will add tree objects into result or not.
/// </summary>
/// <param name="walk">
/// the TreeWalk to walk through. Must have exactly two trees and
/// when
/// <code>includeTrees</code>
/// parameter is
/// <code>true</code>
/// it can't
/// be recursive.
/// </param>
/// <param name="includeTrees">include tree object's.</param>
/// <returns>headers describing the changed files.</returns>
/// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
/// <exception cref="System.ArgumentException">
/// when
/// <code>includeTrees</code>
/// is true and given TreeWalk is
/// recursive. Or when given TreeWalk doesn't have exactly two
/// trees
/// </exception>
public static IList<NGit.Diff.DiffEntry> Scan(TreeWalk walk, bool includeTrees)
{
if (walk.TreeCount != 2)
{
throw new ArgumentException(JGitText.Get().treeWalkMustHaveExactlyTwoTrees);
}
if (includeTrees && walk.Recursive)
{
throw new ArgumentException(JGitText.Get().cannotBeRecursiveWhenTreesAreIncluded);
}
IList<NGit.Diff.DiffEntry> r = new AList<NGit.Diff.DiffEntry>();
MutableObjectId idBuf = new MutableObjectId();
while (walk.Next())
{
NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
walk.GetObjectId(idBuf, 0);
entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
walk.GetObjectId(idBuf, 1);
entry.newId = AbbreviatedObjectId.FromObjectId(idBuf);
entry.oldMode = walk.GetFileMode(0);
entry.newMode = walk.GetFileMode(1);
entry.newPath = entry.oldPath = walk.PathString;
if (entry.oldMode == FileMode.MISSING)
{
entry.oldPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.ADD;
r.AddItem(entry);
}
else
{
if (entry.newMode == FileMode.MISSING)
{
entry.newPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.DELETE;
r.AddItem(entry);
}
else
{
if (!entry.oldId.Equals(entry.newId))
{
entry.changeType = DiffEntry.ChangeType.MODIFY;
if (RenameDetector.SameType(entry.oldMode, entry.newMode))
{
r.AddItem(entry);
}
else
{
Sharpen.Collections.AddAll(r, BreakModify(entry));
}
}
else
{
if (entry.oldMode != entry.newMode)
{
entry.changeType = DiffEntry.ChangeType.MODIFY;
r.AddItem(entry);
}
}
}
}
if (includeTrees && walk.IsSubtree)
{
walk.EnterSubtree();
}
}
return r;
}
示例11: TestPick
public virtual void TestPick()
{
// B---O
// \----P---T
//
// Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
// was created by "P", nor should it modify "a", which was done by "P".
//
DirCache treeB = db.ReadDirCache();
DirCache treeO = db.ReadDirCache();
DirCache treeP = db.ReadDirCache();
DirCache treeT = db.ReadDirCache();
{
DirCacheBuilder b = treeB.Builder();
DirCacheBuilder o = treeO.Builder();
DirCacheBuilder p = treeP.Builder();
DirCacheBuilder t = treeT.Builder();
b.Add(CreateEntry("a", FileMode.REGULAR_FILE));
o.Add(CreateEntry("a", FileMode.REGULAR_FILE));
o.Add(CreateEntry("o", FileMode.REGULAR_FILE));
p.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
p.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
t.Add(CreateEntry("a", FileMode.REGULAR_FILE));
t.Add(CreateEntry("t", FileMode.REGULAR_FILE));
b.Finish();
o.Finish();
p.Finish();
t.Finish();
}
ObjectInserter ow = db.NewObjectInserter();
ObjectId B = Commit(ow, treeB, new ObjectId[] { });
ObjectId O = Commit(ow, treeO, new ObjectId[] { B });
ObjectId P = Commit(ow, treeP, new ObjectId[] { B });
ObjectId T = Commit(ow, treeT, new ObjectId[] { P });
ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
(db));
twm.SetBase(P);
bool merge = twm.Merge(new ObjectId[] { O, T });
NUnit.Framework.Assert.IsTrue(merge);
TreeWalk tw = new TreeWalk(db);
tw.Recursive = true;
tw.Reset(twm.GetResultTreeId());
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("a", tw.PathString);
AssertCorrectId(treeO, tw);
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("o", tw.PathString);
AssertCorrectId(treeO, tw);
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("t", tw.PathString);
AssertCorrectId(treeT, tw);
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例12: TestRevert
public virtual void TestRevert()
{
// B---P---T
//
// Revert P, this should result in a tree with a
// from B and t from T as the change to a in P
// and addition of t in P is reverted.
//
// We use the standard merge, but change the order
// of the sources.
//
DirCache treeB = db.ReadDirCache();
DirCache treeP = db.ReadDirCache();
DirCache treeT = db.ReadDirCache();
{
DirCacheBuilder b = treeB.Builder();
DirCacheBuilder p = treeP.Builder();
DirCacheBuilder t = treeT.Builder();
b.Add(CreateEntry("a", FileMode.REGULAR_FILE));
p.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
p.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
t.Add(CreateEntry("a", FileMode.REGULAR_FILE, "q"));
t.Add(CreateEntry("p-fail", FileMode.REGULAR_FILE));
t.Add(CreateEntry("t", FileMode.REGULAR_FILE));
b.Finish();
p.Finish();
t.Finish();
}
ObjectInserter ow = db.NewObjectInserter();
ObjectId B = Commit(ow, treeB, new ObjectId[] { });
ObjectId P = Commit(ow, treeP, new ObjectId[] { B });
ObjectId T = Commit(ow, treeT, new ObjectId[] { P });
ThreeWayMerger twm = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger
(db));
twm.SetBase(P);
bool merge = twm.Merge(new ObjectId[] { B, T });
NUnit.Framework.Assert.IsTrue(merge);
TreeWalk tw = new TreeWalk(db);
tw.Recursive = true;
tw.Reset(twm.GetResultTreeId());
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("a", tw.PathString);
AssertCorrectId(treeB, tw);
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("t", tw.PathString);
AssertCorrectId(treeT, tw);
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例13: AssertEntry
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
/// <exception cref="NGit.Errors.CorruptObjectException"></exception>
/// <exception cref="System.IO.IOException"></exception>
private void AssertEntry(string sha1string, string path, TreeWalk tw)
{
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual(path, tw.PathString);
NUnit.Framework.Assert.AreEqual(sha1string, tw.GetObjectId(1).GetName());
}
示例14: IdOffset
public virtual void IdOffset()
{
Git git = new Git(db);
WriteTrashFile("fileAinfsonly", "A");
FilePath fileBinindex = WriteTrashFile("fileBinindex", "B");
FsTick(fileBinindex);
git.Add().AddFilepattern("fileBinindex").Call();
WriteTrashFile("fileCinfsonly", "C");
TreeWalk tw = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
tw.AddTree(indexIter);
tw.AddTree(workTreeIter);
workTreeIter.SetDirCacheIterator(tw, 0);
AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
AssertEntry("0000000000000000000000000000000000000000", "a", tw);
AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
// The reason for adding this test. Check that the id is correct for
// mixed
AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw);
AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw);
AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw);
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例15: 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));
}