Ejemplo n.º 1
0
 private static InvalidOperationException bad(DirCacheEntry a, String msg)
 {
     return new InvalidOperationException(msg + ": " + a.getStage() + " " + a.getPathString());
 }
Ejemplo n.º 2
0
 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 static bool Equals(CGitIndexRecord cgir, DirCacheEntry dirCacheEntry)
 {
     return cgir.Mode == dirCacheEntry.getRawMode() &&
            cgir.Id == dirCacheEntry.getObjectId() &&
            cgir.Stage == dirCacheEntry.getStage() &&
            cgir.Path == dirCacheEntry.getPathString();
 }
Ejemplo n.º 4
0
        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());
        }
        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());
        }