本文整理汇总了C#中TreeWalk.next方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.next方法的具体用法?C# TreeWalk.next怎么用?C# TreeWalk.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.next方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testEmptyTree_WithTreeWalk
public void testEmptyTree_WithTreeWalk()
{
DirCache dc = DirCache.read(db);
Assert.AreEqual(0, dc.getEntryCount());
var tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(dc));
Assert.IsFalse(tw.next());
}
示例2: CompareCommits
/// <summary>
/// Compare reference commit against compared commit. You may pass in a null commit (i.e. for getting the changes of the first commit)
/// </summary>
/// <param name="reference"></param>
/// <param name="compared"></param>
/// <returns></returns>
public static IEnumerable<Change> CompareCommits(Commit reference, Commit compared)
{
var changes = new List<Change>();
if (reference == null && compared == null)
return changes;
var repo = (reference ?? compared).Repository;
if (compared.Repository.Directory != repo.Directory)
throw new InvalidOperationException("Can not compare commits from different repositories");
var ref_tree = (reference != null ? reference.Tree._id : ObjectId.ZeroId);
var compared_tree = (compared != null ? compared.Tree._id : ObjectId.ZeroId);
var db = repo._internal_repo;
var pathFilter = TreeFilter.ALL;
var walk = new TreeWalk(db);
//new GitSharp.Core.ObjectWriter(repo).WriteTree( new CoreTree(repo)); // <--- writing an empty tree object. very ugly hack that is necessary to get an empty tree into the treewalker.
if (reference == null || compared == null)
walk.reset((reference ?? compared).Tree._id);
else
walk.reset(new GitSharp.Core.AnyObjectId[] { ref_tree, compared_tree });
//if (ref_tree == ObjectId.ZeroId)
// walk.addTree(new EmptyTreeIterator());
//else
// walk.addTree(ref_tree);
//if (compared_tree == ObjectId.ZeroId)
// walk.addTree(new EmptyTreeIterator());
//else
// walk.addTree(compared_tree);
walk.Recursive = true;
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
while (walk.next())
{
if (walk.getTreeCount() == 2)
{
int m0 = walk.getRawMode(0);
int m1 = walk.getRawMode(1);
var change = new Change()
{
ReferenceCommit = reference,
ComparedCommit = compared,
ReferencePermissions = walk.getFileMode(0).Bits,
ComparedPermissions = walk.getFileMode(1).Bits,
Name = walk.getNameString(),
Path = walk.getPathString(),
};
changes.Add(change);
if (m0 == 0 && m1 != 0)
{
change.ChangeType = ChangeType.Added;
change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
}
else if (m0 != 0 && m1 == 0)
{
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
}
else if (m0 != m1 && walk.idEqual(0, 1))
{
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
}
else
{
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(1));
}
}
else
{
var change = new Change()
{
ReferenceCommit = reference,
ComparedCommit = compared,
Name = walk.getNameString(),
Path = walk.getPathString(),
};
changes.Add(change);
if (reference != null)
{
change.ReferencePermissions = walk.getFileMode(0).Bits;
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
}
else
{
change.ComparedPermissions = walk.getFileMode(0).Bits;
change.ChangeType = ChangeType.Added;
change.ComparedObject = AbstractObject.Wrap(repo, walk.getObjectId(0));
}
}
}
return changes;
}
示例3: CalculateCommitDiff
/// <summary>
/// compare the given commits and return the changes.
/// </summary>
/// <param name="repo"></param>
/// <param name="walk"></param>
/// <param name="commits">first commit in the array is the commit that is compared against the others which are his ancestors (i.e. from different branches)</param>
/// <returns></returns>
private static IEnumerable<Change> CalculateCommitDiff(Repository repo, TreeWalk walk, Commit[] commits)
{
while (walk.next())
{
int m0 = walk.getRawMode(0);
if (walk.getTreeCount() == 2)
{
int m1 = walk.getRawMode(1);
var change = new Change
{
ReferenceCommit = commits[0],
ComparedCommit = commits[1],
ReferencePermissions = walk.getFileMode(0).Bits,
ComparedPermissions = walk.getFileMode(1).Bits,
Name = walk.getNameString(),
Path = walk.getPathString(),
};
if (m0 != 0 && m1 == 0)
{
change.ChangeType = ChangeType.Added;
change.ComparedObject = Wrap(repo, walk.getObjectId(0));
}
else if (m0 == 0 && m1 != 0)
{
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
}
else if (m0 != m1 && walk.idEqual(0, 1))
{
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
change.ComparedObject = Wrap(repo, walk.getObjectId(1));
}
else
{
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
change.ComparedObject = Wrap(repo, walk.getObjectId(1));
}
yield return change;
}
else
{
var raw_modes = new int[walk.getTreeCount()-1];
for(int i = 0;i<walk.getTreeCount()-1; i++)
raw_modes[i] = walk.getRawMode(i+1);
var change = new Change
{
ReferenceCommit = commits[0],
//ComparedCommit = compared,
Name = walk.getNameString(),
Path = walk.getPathString(),
};
if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
{
change.ChangeType = ChangeType.Added;
change.ComparedObject = Wrap(repo, walk.getObjectId(0));
yield return change;
}
else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
{
change.ChangeType = ChangeType.Deleted;
yield return change;
}
else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).All(x => !walk.idEqual(0, x.Index))) // TODO: not sure if this condition suffices in some special cases.
{
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
yield return change;
}
else if (raw_modes.Select((m1, i) => new { Mode = m1, Index = i + 1 }).Any(x => m0 != x.Mode && walk.idEqual(0, x.Index)))
{
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = Wrap(repo, walk.getObjectId(0));
yield return change;
}
}
}
}
示例4: CompareAgainst
//public class Diff
//{
// public List<AbstractObject> Modified = new List<AbstractObject>();
// public List<AbstractObject> Added = new List<AbstractObject>();
// public List<AbstractObject> Deleted = new List<AbstractObject>();
// public List<AbstractObject> TypeChanged = new List<AbstractObject>();
//}
/// <summary>
/// Compares this commit against another one and returns all changes between the two.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public IEnumerable<Change> CompareAgainst(Commit other)
{
var changes = new List<Change>();
var db = _repo._internal_repo;
var pathFilter = TreeFilter.ALL;
var walk = new TreeWalk(db);
walk.reset(new GitSharp.Core.AnyObjectId[] { this.Tree._id, other.Tree._id });
walk.Recursive = true;
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
Debug.Assert(walk.getTreeCount() == 2);
while (walk.next())
{
//for (int i = 1; i < nTree; i++)
// out.print(':');
//for (int i = 0; i < nTree; i++) {
// var m = walk.getFileMode(i);
// String s = m.toString();
// for (int pad = 6 - s.length(); pad > 0; pad--)
// out.print('0');
// out.print(s);
// out.print(' ');
//}
//for (int i = 0; i < nTree; i++) {
// out.print(walk.getObjectId(i).name());
// out.print(' ');
//}
//char chg = 'M';
int m0 = walk.getRawMode(0);
int m1 = walk.getRawMode(1);
var change = new Change()
{
ReferenceCommit = this,
ComparedCommit = other,
ReferencePermissions = walk.getFileMode(0).Bits,
ComparedPermissions = walk.getFileMode(1).Bits,
Name = walk.getNameString(),
Path = walk.getPathString(),
};
changes.Add(change);
if (m0 == 0 && m1 != 0)
{
change.ChangeType = ChangeType.Added;
change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
}
else if (m0 != 0 && m1 == 0)
{
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
}
else if (m0 != m1 && walk.idEqual(0, 1))
{
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
}
else
{
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = AbstractObject.Wrap(_repo, walk.getObjectId(0));
change.ComparedObject = AbstractObject.Wrap(_repo, walk.getObjectId(1));
}
}
return changes;
}
示例5: testTreeWalk_LsFiles
public void testTreeWalk_LsFiles()
{
global::GitSharp.Core.Repository db = createBareRepository();
List<CGitIndexRecord> ls = ReadLsFiles();
var dc = new DirCache(_index);
Assert.AreEqual(0, dc.getEntryCount());
dc.read();
Assert.AreEqual(ls.Count, dc.getEntryCount());
var rItr = ls.GetEnumerator();
var tw = new TreeWalk(db);
tw.reset();
tw.Recursive = true;
tw.addTree(new DirCacheIterator(dc));
while (rItr.MoveNext())
{
Assert.IsTrue(tw.next());
var dcItr = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
Assert.IsNotNull(dcItr);
AssertAreEqual(rItr.Current, dcItr.getDirCacheEntry());
}
}
示例6: testTwoLevelSubtree_Recursive
public void testTwoLevelSubtree_Recursive()
{
DirCache dc = DirCache.read(db);
FileMode mode = FileMode.RegularFile;
string[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].setFileMode(mode);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
var tw = new TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheIterator(dc));
tw.Recursive = true;
int pathIdx = 0;
while (tw.next())
{
var c = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
Assert.IsNotNull(c);
Assert.AreEqual(pathIdx, c.Pointer);
Assert.AreSame(ents[pathIdx], c.getDirCacheEntry());
Assert.AreEqual(paths[pathIdx], tw.getPathString());
Assert.AreEqual(mode.Bits, tw.getRawMode(0));
Assert.AreSame(mode, tw.getFileMode(0));
pathIdx++;
}
Assert.AreEqual(paths.Length, pathIdx);
}
示例7: testTwoLevelSubtree_FilterPath
public void testTwoLevelSubtree_FilterPath()
{
DirCache dc = DirCache.read(db);
FileMode mode = FileMode.RegularFile;
string[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].setFileMode(mode);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
var tw = new TreeWalk(db);
for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
{
tw.reset();
tw.addTree(new DirCacheIterator(dc));
tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[victimIdx] }));
tw.Recursive = tw.getFilter().shouldBeRecursive();
Assert.IsTrue(tw.next());
var c = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
Assert.IsNotNull(c);
Assert.AreEqual(victimIdx, c.Pointer);
Assert.AreSame(ents[victimIdx], c.getDirCacheEntry());
Assert.AreEqual(paths[victimIdx], tw.getPathString());
Assert.AreEqual(mode.Bits, tw.getRawMode(0));
Assert.AreSame(mode, tw.getFileMode(0));
Assert.IsFalse(tw.next());
}
}
示例8: testSingleSubtree_NoRecursion
public void testSingleSubtree_NoRecursion()
{
DirCache dc = DirCache.read(db);
string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].setFileMode(FileMode.RegularFile);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
string[] expPaths = { "a.", "a", "a0b" };
FileMode[] expModes = { FileMode.RegularFile, FileMode.Tree, FileMode.RegularFile };
var expPos = new[] { 0, -1, 4 };
var iter = new DirCacheIterator(dc);
var tw = new TreeWalk(db);
tw.reset();
tw.addTree(iter);
tw.Recursive = false;
int pathIdx = 0;
while (tw.next())
{
Assert.AreSame(iter, tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator)));
Assert.AreEqual(expModes[pathIdx].Bits, tw.getRawMode(0));
Assert.AreSame(expModes[pathIdx], tw.getFileMode(0));
Assert.AreEqual(expPaths[pathIdx], tw.getPathString());
if (expPos[pathIdx] >= 0)
{
Assert.AreEqual(expPos[pathIdx], iter.Pointer);
Assert.AreSame(ents[expPos[pathIdx]], iter.getDirCacheEntry());
}
else
{
Assert.AreSame(FileMode.Tree, tw.getFileMode(0));
}
pathIdx++;
}
Assert.AreEqual(expPaths.Length, pathIdx);
}
示例9: testNoSubtree_WithTreeWalk
public void testNoSubtree_WithTreeWalk()
{
DirCache dc = DirCache.read(db);
string[] paths = { "a.", "a0b" };
FileMode[] modes = { FileMode.ExecutableFile, FileMode.GitLink };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].setFileMode(modes[i]);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
var iter = new DirCacheIterator(dc);
var tw = new TreeWalk(db);
tw.reset();
tw.addTree(iter);
int pathIdx = 0;
while (tw.next())
{
Assert.AreSame(iter, tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator)));
Assert.AreEqual(pathIdx, iter.Pointer);
Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry());
Assert.AreEqual(paths[pathIdx], tw.getPathString());
Assert.AreEqual(modes[pathIdx].Bits, tw.getRawMode(0));
Assert.AreSame(modes[pathIdx], tw.getFileMode(0));
pathIdx++;
}
Assert.AreEqual(paths.Length, pathIdx);
}