private void beforeAdd(DirCacheEntry newEntry) { if (FileMode.Tree.Equals(newEntry.getRawMode())) throw bad(newEntry, "Adding subtree not allowed"); if (sorted && entryCnt > 0) { DirCacheEntry lastEntry = entries[entryCnt - 1]; int cr = DirCache.cmp(lastEntry, newEntry); if (cr > 0) { // The new entry sorts before the old entry; we are // no longer sorted correctly. We'll need to redo // the sorting before we can close out the build. // sorted = false; } else if (cr == 0) { // Same file path; we can only insert this if the // stages won't be violated. // int peStage = lastEntry.getStage(); int dceStage = newEntry.getStage(); if (peStage == dceStage) throw bad(newEntry, "Duplicate stages not allowed"); if (peStage == 0 || dceStage == 0) throw bad(newEntry, "Mixed stages not allowed"); if (peStage > dceStage) sorted = false; } } }
public void testBuildOneFile_FinishWriteCommit() { string path = "a-File-path"; var mode = GitSharp.FileMode.RegularFile; long lastModified = 1218123387057L; int Length = 1342; DirCacheEntry entOrig; DirCache dc = DirCache.Lock(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); entOrig = new DirCacheEntry(path); entOrig.setFileMode(mode); entOrig.setLastModified(lastModified); entOrig.setLength(Length); Assert.AreNotSame(path, entOrig.getPathString()); Assert.AreEqual(path, entOrig.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); b.add(entOrig); b.finish(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreSame(entOrig, dc.getEntry(0)); dc.write(); Assert.IsTrue(dc.commit()); dc = DirCache.read(db); Assert.AreEqual(1, dc.getEntryCount()); DirCacheEntry entRead = dc.getEntry(0); Assert.AreNotSame(entOrig, entRead); Assert.AreEqual(path, entRead.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); }
public static bool Equals(CGitIndexRecord cgir, DirCacheEntry dirCacheEntry) { return cgir.Mode == dirCacheEntry.getRawMode() && cgir.Id == dirCacheEntry.getObjectId() && cgir.Stage == dirCacheEntry.getStage() && cgir.Path == dirCacheEntry.getPathString(); }
private void ParseEntry() { _currentEntry = Cache.getEntry(_pointer); byte[] cep = _currentEntry.Path; if (_nextSubtreePos != Tree.getChildCount()) { DirCacheTree s = Tree.getChild(_nextSubtreePos); if (s.contains(cep, PathOffset, cep.Length)) { // The current position is the first file of this subtree. // Use the subtree instead as the current position. // _currentSubtree = s; _nextSubtreePos++; if (s.isValid()) { s.getObjectId().copyRawTo(SubtreeId, 0); } else { SubtreeId.Fill((byte)0); } Mode = FileMode.Tree.Bits; Path = cep; PathLen = PathOffset + s.nameLength(); return; } } // The current position is a file/symlink/gitlink so we // do not have a subtree located here. // Mode = _currentEntry.getRawMode(); Path = cep; PathLen = cep.Length; _currentSubtree = null; }
private static void AssertAreEqual(CGitIndexRecord c, DirCacheEntry j) { Assert.IsNotNull(c); Assert.IsNotNull(j); Assert.AreEqual(c.Path, j.getPathString()); Assert.AreEqual(c.Id, j.getObjectId()); Assert.AreEqual(c.Mode, j.getRawMode()); Assert.AreEqual(c.Stage, j.getStage()); }