private void Resort() { Array.Sort(Entries, 0, EntryCnt, new GenericComparer <DirCacheEntry>(DirCache.EntryComparer)); for (int entryIdx = 1; entryIdx < EntryCnt; entryIdx++) { DirCacheEntry pe = Entries[entryIdx - 1]; DirCacheEntry ce = Entries[entryIdx]; int cr = DirCache.Compare(pe, ce); if (cr == 0) { // Same file path; we can only allow this if the stages // are 1-3 and no 0 exists. // int peStage = pe.getStage(); int ceStage = ce.getStage(); if (peStage == ceStage) { throw Bad(ce, "Duplicate stages not allowed"); } if (peStage == 0 || ceStage == 0) { throw Bad(ce, "Mixed stages not allowed"); } } } _sorted = true; }
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); } }
private int ComputeSize(DirCacheEntry[] cache, int cIdx, int pathOffset, ObjectWriter ow) { int endIdx = cIdx + _entrySpan; int childIdx = 0; int entryIdx = cIdx; int size = 0; while (entryIdx < endIdx) { DirCacheEntry e = cache[entryIdx]; if (e.getStage() != 0) { throw new UnmergedPathException(e); } byte[] ep = e.Path; if (childIdx < _childCount) { DirCacheTree st = _children[childIdx]; if (st.contains(ep, pathOffset, ep.Length)) { int stOffset = pathOffset + st.nameLength() + 1; st.writeTree(cache, entryIdx, stOffset, ow); size += FileMode.Tree.copyToLength(); size += st.nameLength(); size += Constants.OBJECT_ID_LENGTH + 2; entryIdx += st._entrySpan; childIdx++; continue; } } FileMode mode = e.getFileMode(); size += mode.copyToLength(); size += ep.Length - pathOffset; size += Constants.OBJECT_ID_LENGTH + 2; entryIdx++; } return(size); }
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.Compare(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.Core.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()); }
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()); }
private void BeforeAdd(DirCacheEntry newEntry) { if (_sorted && EntryCnt > 0) { DirCacheEntry lastEntry = Entries[EntryCnt - 1]; int cr = DirCache.Compare(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; } } }
private static InvalidOperationException Bad(DirCacheEntry a, string msg) { return new InvalidOperationException(msg + ": " + a.getStage() + " " + a.getPathString()); }
private static InvalidOperationException Bad(DirCacheEntry a, string msg) { return(new InvalidOperationException(msg + ": " + a.getStage() + " " + a.getPathString())); }