本文整理汇总了C#中GitSharp.Core.DirectoryCache.DirCacheEntry类的典型用法代码示例。如果您正苦于以下问题:C# DirCacheEntry类的具体用法?C# DirCacheEntry怎么用?C# DirCacheEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirCacheEntry类属于GitSharp.Core.DirectoryCache命名空间,在下文中一共展示了DirCacheEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testNonRecursiveFiltering
public void testNonRecursiveFiltering()
{
var ow = new ObjectWriter(db);
ObjectId aSth = ow.WriteBlob("a.sth".getBytes());
ObjectId aTxt = ow.WriteBlob("a.txt".getBytes());
DirCache dc = DirCache.read(db);
DirCacheBuilder builder = dc.builder();
var aSthEntry = new DirCacheEntry("a.sth");
aSthEntry.setFileMode(FileMode.RegularFile);
aSthEntry.setObjectId(aSth);
var aTxtEntry = new DirCacheEntry("a.txt");
aTxtEntry.setFileMode(FileMode.RegularFile);
aTxtEntry.setObjectId(aTxt);
builder.add(aSthEntry);
builder.add(aTxtEntry);
builder.finish();
ObjectId treeId = dc.writeTree(ow);
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
tw.setFilter(PathSuffixFilter.create(".txt"));
tw.addTree(treeId);
var paths = new LinkedList<string>();
while (tw.next())
{
paths.AddLast(tw.getPathString());
}
var expected = new LinkedList<string>();
expected.AddLast("a.txt");
Assert.AreEqual(expected, paths);
}
示例2: testNoSubtree_NoTreeWalk
public void testNoSubtree_NoTreeWalk()
{
DirCache dc = DirCache.read(db);
string[] paths = { "a.", "a0b" };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
var iter = new DirCacheIterator(dc);
int pathIdx = 0;
for (; !iter.eof(); iter.next(1))
{
Assert.AreEqual(pathIdx, iter.Pointer);
Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry());
pathIdx++;
}
Assert.AreEqual(paths.Length, pathIdx);
}
示例3: testLongPath
private void testLongPath(int len)
{
string longPath = makeLongPath(len);
string shortPath = "~~~ shorter-path";
DirCacheEntry longEnt = new DirCacheEntry(longPath);
DirCacheEntry shortEnt = new DirCacheEntry(shortPath);
longEnt.setFileMode(FileMode.RegularFile);
shortEnt.setFileMode(FileMode.RegularFile);
Assert.AreEqual(longPath, longEnt.getPathString());
Assert.AreEqual(shortPath, shortEnt.getPathString());
DirCache dc1 = DirCache.Lock(db);
DirCacheBuilder b = dc1.builder();
b.add(longEnt);
b.add(shortEnt);
Assert.IsTrue(b.commit());
Assert.AreEqual(2, dc1.getEntryCount());
Assert.AreSame(longEnt, dc1.getEntry(0));
Assert.AreSame(shortEnt, dc1.getEntry(1));
DirCache dc2 = DirCache.read(db);
Assert.AreEqual(2, dc2.getEntryCount());
Assert.AreNotSame(longEnt, dc2.getEntry(0));
Assert.AreEqual(longPath, dc2.getEntry(0).getPathString());
Assert.AreNotSame(shortEnt, dc2.getEntry(1));
Assert.AreEqual(shortPath, dc2.getEntry(1).getPathString());
}
示例4: testEntriesWithin
public void testEntriesWithin()
{
DirCache dc = DirCache.read(db);
string[] paths = { "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].setFileMode(FileMode.RegularFile);
}
int aFirst = 1;
int aLast = 3;
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
Assert.AreEqual(paths.Length, dc.getEntryCount());
for (int i = 0; i < ents.Length; i++)
{
Assert.AreSame(ents[i], dc.getEntry(i));
}
DirCacheEntry[] aContents = dc.getEntriesWithin("a");
Assert.IsNotNull(aContents);
Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
for (int i = aFirst, j = 0; i <= aLast; i++, j++)
{
Assert.AreSame(ents[i], aContents[j]);
}
aContents = dc.getEntriesWithin("a/");
Assert.IsNotNull(aContents);
Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
for (int i = aFirst, j = 0; i <= aLast; i++, j++)
{
Assert.AreSame(ents[i], aContents[j]);
}
Assert.IsNotNull(dc.getEntriesWithin("a."));
Assert.AreEqual(0, dc.getEntriesWithin("a.").Length);
Assert.IsNotNull(dc.getEntriesWithin("a0b"));
Assert.AreEqual(0, dc.getEntriesWithin("a0b.").Length);
Assert.IsNotNull(dc.getEntriesWithin("zoo"));
Assert.AreEqual(0, dc.getEntriesWithin("zoo.").Length);
}
示例5: testCreate_ByStringPathAndStage
public void testCreate_ByStringPathAndStage()
{
DirCacheEntry e;
e = new DirCacheEntry("a", 0);
Assert.AreEqual("a", e.getPathString());
Assert.AreEqual(0, e.getStage());
e = new DirCacheEntry("a/b", 1);
Assert.AreEqual("a/b", e.getPathString());
Assert.AreEqual(1, e.getStage());
e = new DirCacheEntry("a/c", 2);
Assert.AreEqual("a/c", e.getPathString());
Assert.AreEqual(2, e.getStage());
e = new DirCacheEntry("a/d", 3);
Assert.AreEqual("a/d", e.getPathString());
Assert.AreEqual(3, e.getStage());
try
{
new DirCacheEntry("/a", 1);
Assert.Fail("Incorrectly created DirCacheEntry");
}
catch (ArgumentException err)
{
Assert.AreEqual("Invalid path: /a", err.Message);
}
try
{
new DirCacheEntry("a", -11);
Assert.Fail("Incorrectly created DirCacheEntry");
}
catch (ArgumentException err)
{
Assert.AreEqual("Invalid stage -11 for path a", err.Message);
}
try
{
new DirCacheEntry("a", 4);
Assert.Fail("Incorrectly created DirCacheEntry");
}
catch (ArgumentException err)
{
Assert.AreEqual("Invalid stage 4 for path a", err.Message);
}
}
示例6: testPathFilterGroup_DoesNotSkipTail
public void testPathFilterGroup_DoesNotSkipTail()
{
DirCache dc = DirCache.read(db);
var mode = FileMode.RegularFile;
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(mode);
}
DirCacheBuilder builder = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
builder.add(ents[i]);
}
builder.finish();
const int expIdx = 2;
DirCacheBuilder b = dc.builder();
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
tw.reset();
tw.addTree(new DirCacheBuildIterator(b));
tw.Recursive = true;
tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[expIdx] }));
Assert.IsTrue(tw.next(), "found " + paths[expIdx]);
var c = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator));
Assert.IsNotNull(c);
Assert.AreEqual(expIdx, c.Pointer);
Assert.AreSame(ents[expIdx], c.getDirCacheEntry());
Assert.AreEqual(paths[expIdx], tw.getPathString());
Assert.AreEqual(mode.Bits, tw.getRawMode(0));
Assert.AreSame(mode, tw.getFileMode(0));
b.add(c.getDirCacheEntry());
Assert.IsFalse(tw.next(), "no more entries");
b.finish();
Assert.AreEqual(ents.Length, dc.getEntryCount());
for (int i = 0; i < ents.Length; i++)
{
Assert.AreSame(ents[i], dc.getEntry(i));
}
}
示例7: testBuildRejectsUnsetFileMode
public void testBuildRejectsUnsetFileMode()
{
DirCache dc = DirCache.newInCore();
DirCacheBuilder b = dc.builder();
Assert.IsNotNull(b);
DirCacheEntry e = new DirCacheEntry("a");
Assert.AreEqual(0, e.getRawMode());
try
{
b.add(e);
}
catch (ArgumentException err)
{
Assert.AreEqual("FileMode not set for path a", err.Message);
}
}
示例8: testAdd_InGitSortOrder
public void testAdd_InGitSortOrder()
{
DirCache dc = DirCache.read(db);
string[] paths = { "a.", "a.b", "a/b", "a0b" };
DirCacheEntry[] ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
ents[i] = new DirCacheEntry(paths[i]);
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
b.add(ents[i]);
b.finish();
Assert.AreEqual(paths.Length, dc.getEntryCount());
for (int i = 0; i < paths.Length; i++)
{
Assert.AreSame(ents[i], dc.getEntry(i));
Assert.AreEqual(paths[i], dc.getEntry(i).getPathString());
Assert.AreEqual(i, dc.findEntry(paths[i]));
Assert.AreSame(ents[i], dc.getEntry(paths[i]));
}
}
示例9: testBuildThenClear
public void testBuildThenClear()
{
DirCache dc = DirCache.read(db);
string[] paths = { "a.", "a.b", "a/b", "a0b" };
var ents = new DirCacheEntry[paths.Length];
for (int i = 0; i < paths.Length; i++)
{
ents[i] = new DirCacheEntry(paths[i]);
}
DirCacheBuilder b = dc.builder();
for (int i = 0; i < ents.Length; i++)
{
b.add(ents[i]);
}
b.finish();
Assert.AreEqual(paths.Length, dc.getEntryCount());
dc.clear();
Assert.AreEqual(0, dc.getEntryCount());
}
示例10: Compare
public static int Compare(DirCacheEntry a, DirCacheEntry b)
{
return Compare(a.Path, a.Path.Length, b);
}
示例11: ReadFrom
private void ReadFrom(Stream inStream)
{
var @in = new StreamReader(inStream);
MessageDigest md = Constants.newMessageDigest();
// Read the index header and verify we understand it.
//
var hdr = new byte[20];
IO.ReadFully(inStream, hdr, 0, 12);
md.Update(hdr, 0, 12);
if (!IsDIRC(hdr))
{
throw new CorruptObjectException("Not a DIRC file.");
}
int ver = NB.DecodeInt32(hdr, 4);
if (ver != 2)
{
throw new CorruptObjectException("Unknown DIRC version " + ver);
}
_entryCnt = NB.DecodeInt32(hdr, 8);
if (_entryCnt < 0)
{
throw new CorruptObjectException("DIRC has too many entries.");
}
// Load the individual file entries.
//
var infos = new byte[InfoLen * _entryCnt];
_sortedEntries = new DirCacheEntry[_entryCnt];
for (int i = 0; i < _entryCnt; i++)
{
_sortedEntries[i] = new DirCacheEntry(infos, i * InfoLen, inStream, md);
}
_lastModified = _liveFile.LastWriteTime;
// After the file entries are index extensions, and then a footer.
//
while (true)
{
var pos = inStream.Position;
IO.ReadFully(inStream, hdr, 0, 20);
int nextByte = @in.Read();
if (nextByte < 0 || inStream.Position == inStream.Length)
{
// No extensions present; the file ended where we expected.
//
break;
}
inStream.Seek(pos, SeekOrigin.Begin);
switch (NB.DecodeInt32(hdr, 0))
{
case ExtTree:
var raw = new byte[NB.DecodeInt32(hdr, 4)];
md.Update(hdr, 0, 8);
IO.skipFully(inStream, 8);
IO.ReadFully(inStream, raw, 0, raw.Length);
md.Update(raw, 0, raw.Length);
_cacheTree = new DirCacheTree(raw, new MutableInteger(), null);
break;
default:
if (hdr[0] >= (byte)'A' && hdr[0] <= (byte)'Z')
{
// The extension is optional and is here only as
// a performance optimization. Since we do not
// understand it, we can safely skip past it.
//
IO.skipFully(inStream, NB.decodeUInt32(hdr, 4));
}
else
{
// The extension is not an optimization and is
// _required_ to understand this index format.
// Since we did not trap it above we must abort.
//
throw new CorruptObjectException("DIRC extension '"
+ Constants.CHARSET.GetString(hdr.Take(4).ToArray())
+ "' not supported by this version.");
}
break;
}
}
byte[] exp = md.Digest();
if (!exp.SequenceEqual(hdr))
{
throw new CorruptObjectException("DIRC checksum mismatch");
}
}
示例12: replace
public void replace(DirCacheEntry[] e, int cnt)
{
_sortedEntries = e;
_entryCnt = cnt;
_cacheTree = null;
}
示例13: 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 GitSharp.Core.TreeWalk.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());
}
}
示例14: testFindSingleFile
public void testFindSingleFile()
{
string path = "a-File-path";
DirCache dc = DirCache.read(db);
DirCacheBuilder b = dc.builder();
Assert.IsNotNull(b);
DirCacheEntry entOrig = new DirCacheEntry(path);
Assert.AreNotSame(path, entOrig.getPathString());
Assert.AreEqual(path, entOrig.getPathString());
b.add(entOrig);
b.finish();
Assert.AreEqual(1, dc.getEntryCount());
Assert.AreSame(entOrig, dc.getEntry(0));
Assert.AreEqual(0, dc.findEntry(path));
Assert.AreEqual(-1, dc.findEntry("@@-before"));
Assert.AreEqual(0, real(dc.findEntry("@@-before")));
Assert.AreEqual(-2, dc.findEntry("a-zoo"));
Assert.AreEqual(1, real(dc.findEntry("a-zoo")));
Assert.AreSame(entOrig, dc.getEntry(path));
}
示例15: 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 GitSharp.Core.TreeWalk.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);
}