本文整理汇总了C#中TreeWalk.GetRawMode方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.GetRawMode方法的具体用法?C# TreeWalk.GetRawMode怎么用?C# TreeWalk.GetRawMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.GetRawMode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateCommitDiff
static IEnumerable<Change> CalculateCommitDiff (NGit.Repository repo, TreeWalk walk, RevCommit[] commits)
{
while (walk.Next ()) {
int m0 = walk.GetRawMode (0);
if (walk.TreeCount == 2) {
int m1 = walk.GetRawMode (1);
var change = new Change { ReferenceCommit = commits[0], ComparedCommit = commits[1], ReferencePermissions = walk.GetFileMode (0).GetBits (), ComparedPermissions = walk.GetFileMode (1).GetBits (), Name = walk.NameString, Path = walk.PathString };
if (m0 != 0 && m1 == 0) {
change.ChangeType = ChangeType.Added;
change.ComparedObject = walk.GetObjectId (0);
} else if (m0 == 0 && m1 != 0) {
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = walk.GetObjectId (0);
} else if (m0 != m1 && walk.IdEqual (0, 1)) {
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = walk.GetObjectId (0);
change.ComparedObject = walk.GetObjectId (1);
} else {
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = walk.GetObjectId (0);
change.ComparedObject = walk.GetObjectId (1);
}
yield return change;
} else {
var raw_modes = new int[walk.TreeCount - 1];
for (int i = 0; i < walk.TreeCount - 1; i++)
raw_modes[i] = walk.GetRawMode (i + 1);
//ComparedCommit = compared,
var change = new Change { ReferenceCommit = commits[0], Name = walk.NameString, Path = walk.PathString };
if (m0 != 0 && raw_modes.All (m1 => m1 == 0)) {
change.ChangeType = ChangeType.Added;
change.ComparedObject = walk.GetObjectId (0);
yield return change;
} else if (m0 == 0 && raw_modes.Any (m1 => m1 != 0)) {
change.ChangeType = ChangeType.Deleted;
yield return change;
// TODO: not sure if this condition suffices in some special cases.
} else if (raw_modes.Select ((m1, i) => new { Mode = m1, Index = i + 1 }).All (x => !walk.IdEqual (0, x.Index))) {
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = 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 = walk.GetObjectId (0);
yield return change;
}
}
}
}
示例2: 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);
}
示例3: 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());
}
}
示例4: TestNoSubtree_WithTreeWalk
public virtual void TestNoSubtree_WithTreeWalk()
{
DirCache dc = DirCache.NewInCore();
string[] paths = new string[] { "a.", "a0b" };
FileMode[] modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK };
DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
ents[i].FileMode = modes[i];
}
DirCacheBuilder b = dc.Builder();
for (int i_1 = 0; i_1 < ents.Length; i_1++)
{
b.Add(ents[i_1]);
}
b.Finish();
DirCacheIterator i_2 = new DirCacheIterator(dc);
TreeWalk tw = new TreeWalk(db);
tw.AddTree(i_2);
int pathIdx = 0;
while (tw.Next())
{
NUnit.Framework.Assert.AreSame(i_2, tw.GetTree<DirCacheIterator>(0));
NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr);
NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry());
NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString);
NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0));
NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0));
pathIdx++;
}
NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx);
}
示例5: TestSingleSubtree_NoRecursion
public virtual void TestSingleSubtree_NoRecursion()
{
DirCache dc = DirCache.NewInCore();
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 = FileMode.REGULAR_FILE;
}
DirCacheBuilder b = dc.Builder();
for (int i_1 = 0; i_1 < ents.Length; i_1++)
{
b.Add(ents[i_1]);
}
b.Finish();
string[] expPaths = new string[] { "a.", "a", "a0b" };
FileMode[] expModes = new FileMode[] { FileMode.REGULAR_FILE, FileMode.TREE, FileMode
.REGULAR_FILE };
int[] expPos = new int[] { 0, -1, 4 };
DirCacheIterator i_2 = new DirCacheIterator(dc);
TreeWalk tw = new TreeWalk(db);
tw.AddTree(i_2);
tw.Recursive = false;
int pathIdx = 0;
while (tw.Next())
{
NUnit.Framework.Assert.AreSame(i_2, tw.GetTree<DirCacheIterator>(0));
NUnit.Framework.Assert.AreEqual(expModes[pathIdx].GetBits(), tw.GetRawMode(0));
NUnit.Framework.Assert.AreSame(expModes[pathIdx], tw.GetFileMode(0));
NUnit.Framework.Assert.AreEqual(expPaths[pathIdx], tw.PathString);
if (expPos[pathIdx] >= 0)
{
NUnit.Framework.Assert.AreEqual(expPos[pathIdx], i_2.ptr);
NUnit.Framework.Assert.AreSame(ents[expPos[pathIdx]], i_2.GetDirCacheEntry());
}
else
{
NUnit.Framework.Assert.AreSame(FileMode.TREE, tw.GetFileMode(0));
}
pathIdx++;
}
NUnit.Framework.Assert.AreEqual(expPaths.Length, pathIdx);
}
示例6: Include
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
/// <exception cref="System.IO.IOException"></exception>
public override bool Include(TreeWalk tw)
{
// If the working tree file doesn't exist, it does exist for at least
// one other so include this difference.
int wm = tw.GetRawMode(workingTree);
if (wm == 0)
{
return true;
}
// If the path does not appear in the DirCache and its ignored
// we can avoid returning a result here, but only if its not in any
// other tree.
int cnt = tw.TreeCount;
int dm = tw.GetRawMode(dirCache);
if (dm == 0)
{
if (honorIgnores && WorkingTree(tw).IsEntryIgnored())
{
int i = 0;
for (; i < cnt; i++)
{
if (i == dirCache || i == workingTree)
{
continue;
}
if (tw.GetRawMode(i) != 0)
{
break;
}
}
// If i is cnt then the path does not appear in any other tree,
// and this working tree entry can be safely ignored.
return i == cnt ? false : true;
}
else
{
// In working tree and not ignored, and not in DirCache.
return true;
}
}
// Always include subtrees as WorkingTreeIterator cannot provide
// efficient elimination of unmodified subtrees.
if (tw.IsSubtree)
{
return true;
}
// Try the inexpensive comparisons between index and all real trees
// first. Only if we don't find a diff here we have to bother with
// the working tree
for (int i_1 = 0; i_1 < cnt; i_1++)
{
if (i_1 == dirCache || i_1 == workingTree)
{
continue;
}
if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
{
return true;
}
}
// Only one chance left to detect a diff: between index and working
// tree. Make use of the WorkingTreeIterator#isModified() method to
// avoid computing SHA1 on filesystem content if not really needed.
WorkingTreeIterator wi = WorkingTree(tw);
DirCacheIterator di = tw.GetTree<DirCacheIterator>(dirCache);
return wi.IsModified(di.GetDirCacheEntry(), true);
}
示例7: Include
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
/// <exception cref="System.IO.IOException"></exception>
public override bool Include(TreeWalk tw)
{
int cnt = tw.TreeCount;
int wm = tw.GetRawMode(workingTree);
string path = tw.PathString;
if (!tw.PostOrderTraversal)
{
// detect untracked Folders
// Whenever we enter a folder in the workingtree assume it will
// contain only untracked files and add it to
// untrackedParentFolders. If we later find tracked files we will
// remove it from this list
if (FileMode.TREE.Equals(wm))
{
// Clean untrackedParentFolders. This potentially moves entries
// from untrackedParentFolders to untrackedFolders
CopyUntrackedFolders(path);
// add the folder we just entered to untrackedParentFolders
untrackedParentFolders.AddFirst(path);
}
// detect untracked Folders
// Whenever we see a tracked file we know that all of its parent
// folders do not belong into untrackedParentFolders anymore. Clean
// it.
for (int i = 0; i < cnt; i++)
{
int rmode = tw.GetRawMode(i);
if (i != workingTree && rmode != 0 && FileMode.TREE.Equals(rmode))
{
untrackedParentFolders.Clear();
break;
}
}
}
// If the working tree file doesn't exist, it does exist for at least
// one other so include this difference.
if (wm == 0)
{
return true;
}
// If the path does not appear in the DirCache and its ignored
// we can avoid returning a result here, but only if its not in any
// other tree.
int dm = tw.GetRawMode(dirCache);
WorkingTreeIterator wi = WorkingTree(tw);
if (dm == 0)
{
if (honorIgnores && wi.IsEntryIgnored())
{
ignoredPaths.AddItem(wi.EntryPathString);
int i = 0;
for (; i < cnt; i++)
{
if (i == dirCache || i == workingTree)
{
continue;
}
if (tw.GetRawMode(i) != 0)
{
break;
}
}
// If i is cnt then the path does not appear in any other tree,
// and this working tree entry can be safely ignored.
return i == cnt ? false : true;
}
else
{
// In working tree and not ignored, and not in DirCache.
return true;
}
}
// Always include subtrees as WorkingTreeIterator cannot provide
// efficient elimination of unmodified subtrees.
if (tw.IsSubtree)
{
return true;
}
// Try the inexpensive comparisons between index and all real trees
// first. Only if we don't find a diff here we have to bother with
// the working tree
for (int i_1 = 0; i_1 < cnt; i_1++)
{
if (i_1 == dirCache || i_1 == workingTree)
{
continue;
}
if (tw.GetRawMode(i_1) != dm || !tw.IdEqual(i_1, dirCache))
{
return true;
}
}
// Only one chance left to detect a diff: between index and working
// tree. Make use of the WorkingTreeIterator#isModified() method to
// avoid computing SHA1 on filesystem content if not really needed.
DirCacheIterator di = tw.GetTree<DirCacheIterator>(dirCache);
return wi.IsModified(di.GetDirCacheEntry(), true);
//.........这里部分代码省略.........
示例8: GetChanges
// Modified version of GitSharp's Commit class
private Change[] GetChanges(Repository repository, ObjectId id1, ObjectId id2)
{
var list = new List<Change>();
TreeWalk walk = new TreeWalk(repository);
walk.Reset(id1, id2);
walk.Recursive = true;
walk.Filter = TreeFilter.ANY_DIFF;
while (walk.Next())
{
int m0 = walk.GetRawMode(0);
if (walk.TreeCount == 2)
{
int m1 = walk.GetRawMode(1);
var change = new Change
{
Name = walk.PathString,
};
if (m0 != 0 && m1 == 0)
{
change.ChangeType = ChangeType.Added;
}
else if (m0 == 0 && m1 != 0)
{
change.ChangeType = ChangeType.Deleted;
}
else if (m0 != m1 && walk.IdEqual(0, 1))
{
change.ChangeType = ChangeType.TypeChanged;
}
else
{
change.ChangeType = ChangeType.Modified;
}
list.Add(change);
}
else
{
var raw_modes = new int[walk.TreeCount - 1];
for (int i = 0; i < walk.TreeCount - 1; i++)
raw_modes[i] = walk.GetRawMode(i + 1);
var change = new Change
{
Name = walk.PathString,
};
if (m0 != 0 && raw_modes.All(m1 => m1 == 0))
{
change.ChangeType = ChangeType.Added;
list.Add(change);
}
else if (m0 == 0 && raw_modes.Any(m1 => m1 != 0))
{
change.ChangeType = ChangeType.Deleted;
list.Add(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;
list.Add(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;
list.Add(change);
}
}
}
return list.ToArray();
}
示例9: Include
public override bool Include(TreeWalk walker)
{
int n = walker.TreeCount;
if (n == 1)
{
// Assume they meant difference to empty tree.
return true;
}
int m = walker.GetRawMode(0);
for (int i = 1; i < n; i++)
{
if (walker.GetRawMode(i) != m || !walker.IdEqual(i, 0))
{
return true;
}
}
return false;
}
示例10: 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));
}
}