예제 #1
0
 public virtual void TestBuildEmpty()
 {
     {
         DirCache        dc = db.LockDirCache();
         DirCacheBuilder b  = dc.Builder();
         NUnit.Framework.Assert.IsNotNull(b);
         b.Finish();
         dc.Write();
         NUnit.Framework.Assert.IsTrue(dc.Commit());
     }
     {
         DirCache dc = db.ReadDirCache();
         NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
     }
 }
예제 #2
0
        public virtual void TestWriteEmptyCommit_RealIndex()
        {
            FilePath idx = new FilePath(db.Directory, "index");
            FilePath lck = new FilePath(db.Directory, "index.lock");

            NUnit.Framework.Assert.IsFalse(idx.Exists());
            NUnit.Framework.Assert.IsFalse(lck.Exists());
            DirCache dc = db.LockDirCache();

            NUnit.Framework.Assert.AreEqual(0, lck.Length());
            dc.Write();
            NUnit.Framework.Assert.AreEqual(12 + 20, lck.Length());
            NUnit.Framework.Assert.IsTrue(dc.Commit());
            NUnit.Framework.Assert.IsTrue(idx.Exists());
            NUnit.Framework.Assert.IsFalse(lck.Exists());
            NUnit.Framework.Assert.AreEqual(12 + 20, idx.Length());
        }
예제 #3
0
        public virtual void TestWriteEmptyReadEmpty_RealIndex()
        {
            FilePath idx = new FilePath(db.Directory, "index");
            FilePath lck = new FilePath(db.Directory, "index.lock");

            NUnit.Framework.Assert.IsFalse(idx.Exists());
            NUnit.Framework.Assert.IsFalse(lck.Exists());
            {
                DirCache dc = db.LockDirCache();
                dc.Write();
                NUnit.Framework.Assert.IsTrue(dc.Commit());
                NUnit.Framework.Assert.IsTrue(idx.Exists());
            }
            {
                DirCache dc = db.ReadDirCache();
                NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
            }
        }
예제 #4
0
 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);
     }
 }
예제 #5
0
 /// <summary>Finish, write, commit this change, and release the index lock.</summary>
 /// <remarks>
 /// Finish, write, commit this change, and release the index lock.
 /// <p>
 /// If this method fails (returns false) the lock is still released.
 /// <p>
 /// This is a utility method for applications as the finish-write-commit
 /// pattern is very common after using a builder to update entries.
 /// </remarks>
 /// <returns>
 /// true if the commit was successful and the file contains the new
 /// data; false if the commit failed and the file remains with the
 /// old data.
 /// </returns>
 /// <exception cref="System.InvalidOperationException">the lock is not held.</exception>
 /// <exception cref="System.IO.IOException">
 /// the output file could not be created. The caller no longer
 /// holds the lock.
 /// </exception>
 public virtual bool Commit()
 {
     Finish();
     cache.Write();
     return(cache.Commit());
 }