public virtual void TestThreeEntries_BackwardsTwo() { ctp.Reset(tree3); ctp.Next(3); NUnit.Framework.Assert.IsTrue(ctp.Eof); ctp.Back(2); NUnit.Framework.Assert.IsFalse(ctp.Eof); NUnit.Framework.Assert.AreEqual(mt.GetBits(), ctp.mode); NUnit.Framework.Assert.AreEqual("b_sometree", Path()); NUnit.Framework.Assert.AreEqual(hash_sometree, ctp.EntryObjectId); ctp.Next(1); NUnit.Framework.Assert.IsFalse(ctp.Eof); NUnit.Framework.Assert.AreEqual(m644.GetBits(), ctp.mode); NUnit.Framework.Assert.AreEqual("foo", Path()); NUnit.Framework.Assert.AreEqual(hash_foo, ctp.EntryObjectId); ctp.Next(1); NUnit.Framework.Assert.IsTrue(ctp.Eof); }
public virtual void TestBuildOneFile_FinishWriteCommit() { string path = "a-file-path"; FileMode mode = FileMode.REGULAR_FILE; long lastModified = 1218123387057L; int length = 1342; DirCacheEntry entOrig; { DirCache dc = db.LockDirCache(); DirCacheBuilder b = dc.Builder(); NUnit.Framework.Assert.IsNotNull(b); entOrig = new DirCacheEntry(path); entOrig.FileMode = mode; entOrig.LastModified = lastModified; entOrig.SetLength(length); NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString); NUnit.Framework.Assert.AreEqual(path, entOrig.PathString); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId()); NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode); NUnit.Framework.Assert.AreEqual(0, entOrig.Stage); NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified); NUnit.Framework.Assert.AreEqual(length, entOrig.Length); NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid); b.Add(entOrig); b.Finish(); NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount()); NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0)); dc.Write(); NUnit.Framework.Assert.IsTrue(dc.Commit()); } { DirCache dc = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount()); DirCacheEntry entRead = dc.GetEntry(0); NUnit.Framework.Assert.AreNotSame(entOrig, entRead); NUnit.Framework.Assert.AreEqual(path, entRead.PathString); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId()); NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode); NUnit.Framework.Assert.AreEqual(0, entOrig.Stage); NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified); NUnit.Framework.Assert.AreEqual(length, entOrig.Length); NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid); } }
internal static bool SameType(FileMode a, FileMode b) { // Files have to be of the same type in order to rename them. // We would never want to rename a file to a gitlink, or a // symlink to a file. // int aType = a.GetBits() & FileMode.TYPE_MASK; int bType = b.GetBits() & FileMode.TYPE_MASK; return(aType == bType); }
public FakeTreeIterator(AbstractTreeIteratorTest _enclosing, string pathName, FileMode fileMode) : base(AbstractTreeIteratorTest.Prefix(pathName), new Config().Get(WorkingTreeOptions .KEY)) { this._enclosing = _enclosing; this.mode = fileMode.GetBits(); int s = pathName.LastIndexOf('/'); byte[] name = Constants.Encode(Sharpen.Runtime.Substring(pathName, s + 1)); this.EnsurePathCapacity(this.pathOffset + name.Length, this.pathOffset); System.Array.Copy(name, 0, this.path, this.pathOffset, name.Length); this.pathLen = this.pathOffset + name.Length; }
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)); } }
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()); } }
public virtual void TestSingleSubtree_Recursive() { DirCache dc = DirCache.NewInCore(); 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(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); 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); }
private static int LastPathChar(FileMode mode) { return(FileMode.TREE.Equals(mode.GetBits()) ? '/' : '\0'); }
private static bool IsFile(FileMode mode) { return((mode.GetBits() & FileMode.TYPE_MASK) == FileMode.TYPE_FILE); }
public virtual void TestOneEntry_Forward() { ctp.Reset(tree1); NUnit.Framework.Assert.IsTrue(ctp.First); NUnit.Framework.Assert.IsFalse(ctp.Eof); NUnit.Framework.Assert.AreEqual(m644.GetBits(), ctp.mode); NUnit.Framework.Assert.AreEqual("a", Path()); NUnit.Framework.Assert.AreEqual(hash_a, ctp.EntryObjectId); ctp.Next(1); NUnit.Framework.Assert.IsFalse(ctp.First); NUnit.Framework.Assert.IsTrue(ctp.Eof); }