예제 #1
0
 /// <summary>Create a new in-core index representation, lock it, and read from disk.</summary>
 /// <remarks>
 /// Create a new in-core index representation, lock it, and read from disk.
 /// <p>
 /// The new index will be locked and then read before it is returned to the
 /// caller. Read failures are reported as exceptions and therefore prevent
 /// the method from returning a partially populated index. On read failure,
 /// the lock is released.
 /// </remarks>
 /// <param name="indexLocation">location of the index file on disk.</param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to perform
 /// certain file system operations.
 /// </param>
 /// <param name="indexChangedListener">listener to be informed when DirCache is committed
 ///     </param>
 /// <returns>
 /// a cache representing the contents of the specified index file (if
 /// it exists) or an empty cache if the file does not exist.
 /// </returns>
 /// <exception cref="System.IO.IOException">
 /// the index file is present but could not be read, or the lock
 /// could not be obtained.
 /// </exception>
 /// <exception cref="NGit.Errors.CorruptObjectException">
 /// the index file is using a format or extension that this
 /// library does not support.
 /// </exception>
 public static NGit.Dircache.DirCache Lock(FilePath indexLocation, FS fs, IndexChangedListener
                                           indexChangedListener)
 {
     NGit.Dircache.DirCache c = Lock(indexLocation, fs);
     c.RegisterIndexChangedListener(indexChangedListener);
     return(c);
 }
예제 #2
0
파일: DirCache.cs 프로젝트: ashmind/ngit
 /// <summary>Create a new in-core index representation, lock it, and read from disk.</summary>
 /// <remarks>
 /// Create a new in-core index representation, lock it, and read from disk.
 /// <p>
 /// The new index will be locked and then read before it is returned to the
 /// caller. Read failures are reported as exceptions and therefore prevent
 /// the method from returning a partially populated index. On read failure,
 /// the lock is released.
 /// </remarks>
 /// <param name="indexLocation">location of the index file on disk.</param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to perform
 /// certain file system operations.
 /// </param>
 /// <returns>
 /// a cache representing the contents of the specified index file (if
 /// it exists) or an empty cache if the file does not exist.
 /// </returns>
 /// <exception cref="System.IO.IOException">
 /// the index file is present but could not be read, or the lock
 /// could not be obtained.
 /// </exception>
 /// <exception cref="NGit.Errors.CorruptObjectException">
 /// the index file is using a format or extension that this
 /// library does not support.
 /// </exception>
 public static NGit.Dircache.DirCache Lock(FilePath indexLocation, FS fs)
 {
     NGit.Dircache.DirCache c = new NGit.Dircache.DirCache(indexLocation, fs);
     if (!c.Lock())
     {
         throw new IOException(MessageFormat.Format(JGitText.Get().cannotLock, indexLocation
                                                    ));
     }
     try
     {
         c.Read();
     }
     catch (IOException e)
     {
         c.Unlock();
         throw;
     }
     catch (RuntimeException e)
     {
         c.Unlock();
         throw;
     }
     catch (Error e)
     {
         c.Unlock();
         throw;
     }
     return(c);
 }
예제 #3
0
 /// <summary>Create a new in-core index representation, lock it, and read from disk.</summary>
 /// <remarks>
 /// Create a new in-core index representation, lock it, and read from disk.
 /// <p>
 /// The new index will be locked and then read before it is returned to the
 /// caller. Read failures are reported as exceptions and therefore prevent
 /// the method from returning a partially populated index. On read failure,
 /// the lock is released.
 /// </remarks>
 /// <param name="indexLocation">location of the index file on disk.</param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to perform
 /// certain file system operations.
 /// </param>
 /// <returns>
 /// a cache representing the contents of the specified index file (if
 /// it exists) or an empty cache if the file does not exist.
 /// </returns>
 /// <exception cref="System.IO.IOException">
 /// the index file is present but could not be read, or the lock
 /// could not be obtained.
 /// </exception>
 /// <exception cref="NGit.Errors.CorruptObjectException">
 /// the index file is using a format or extension that this
 /// library does not support.
 /// </exception>
 public static NGit.Dircache.DirCache Lock(FilePath indexLocation, FS fs)
 {
     NGit.Dircache.DirCache c = new NGit.Dircache.DirCache(indexLocation, fs);
     if (!c.Lock())
     {
         throw new LockFailedException(indexLocation);
     }
     try
     {
         c.Read();
     }
     catch (IOException e)
     {
         c.Unlock();
         throw;
     }
     catch (RuntimeException e)
     {
         c.Unlock();
         throw;
     }
     catch (Error e)
     {
         c.Unlock();
         throw;
     }
     return(c);
 }
예제 #4
0
 /// <summary>Create a new in-core index representation, lock it, and read from disk.</summary>
 /// <remarks>
 /// Create a new in-core index representation, lock it, and read from disk.
 /// <p>
 /// The new index will be locked and then read before it is returned to the
 /// caller. Read failures are reported as exceptions and therefore prevent
 /// the method from returning a partially populated index. On read failure,
 /// the lock is released.
 /// </remarks>
 /// <param name="repository">repository containing the index to lock and read</param>
 /// <param name="indexChangedListener">listener to be informed when DirCache is committed
 ///     </param>
 /// <returns>
 /// a cache representing the contents of the specified index file (if
 /// it exists) or an empty cache if the file does not exist.
 /// </returns>
 /// <exception cref="System.IO.IOException">
 /// the index file is present but could not be read, or the lock
 /// could not be obtained.
 /// </exception>
 /// <exception cref="NGit.Errors.CorruptObjectException">
 /// the index file is using a format or extension that this
 /// library does not support.
 /// </exception>
 /// <since>2.0</since>
 public static NGit.Dircache.DirCache Lock(Repository repository, IndexChangedListener
                                           indexChangedListener)
 {
     NGit.Dircache.DirCache c = Lock(repository.GetIndexFile(), repository.FileSystem,
                                     indexChangedListener);
     c.repository = repository;
     return(c);
 }
예제 #5
0
 internal DirCacheIterator(NGit.Dircache.DirCacheIterator p, DirCacheTree dct) : base
         (p, p.path, p.pathLen + 1)
 {
     cache     = p.cache;
     tree      = dct;
     treeStart = p.ptr;
     treeEnd   = treeStart + tree.GetEntrySpan();
     subtreeId = p.subtreeId;
     ptr       = p.ptr;
     ParseEntry();
 }
예제 #6
0
 /// <summary>Create a new iterator for an already loaded DirCache instance.</summary>
 /// <remarks>
 /// Create a new iterator for an already loaded DirCache instance.
 /// <p>
 /// The iterator implementation may copy part of the cache's data during
 /// construction, so the cache must be read in prior to creating the
 /// iterator.
 /// </remarks>
 /// <param name="dc">the cache to walk. It must be already loaded into memory.</param>
 public DirCacheIterator(DirCache dc)
 {
     cache     = dc;
     tree      = dc.GetCacheTree(true);
     treeStart = 0;
     treeEnd   = tree.GetEntrySpan();
     subtreeId = new byte[Constants.OBJECT_ID_LENGTH];
     if (!Eof)
     {
         ParseEntry();
     }
 }
        public virtual void TestTwoLevelSubtree()
        {
            DirCache dc = db.ReadDirCache();

            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 = FileMode.REGULAR_FILE;
            }
            int             aFirst  = 1;
            int             aLast   = 4;
            int             acFirst = 2;
            int             acLast  = 3;
            DirCacheBuilder b       = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            NUnit.Framework.Assert.IsNull(dc.GetCacheTree(false));
            DirCacheTree root = dc.GetCacheTree(true);

            NUnit.Framework.Assert.IsNotNull(root);
            NUnit.Framework.Assert.AreSame(root, dc.GetCacheTree(true));
            NUnit.Framework.Assert.AreEqual(string.Empty, root.GetNameString());
            NUnit.Framework.Assert.AreEqual(string.Empty, root.GetPathString());
            NUnit.Framework.Assert.AreEqual(1, root.GetChildCount());
            NUnit.Framework.Assert.AreEqual(dc.GetEntryCount(), root.GetEntrySpan());
            NUnit.Framework.Assert.IsFalse(root.IsValid());
            DirCacheTree aTree = root.GetChild(0);

            NUnit.Framework.Assert.IsNotNull(aTree);
            NUnit.Framework.Assert.AreSame(aTree, root.GetChild(0));
            NUnit.Framework.Assert.AreEqual("a", aTree.GetNameString());
            NUnit.Framework.Assert.AreEqual("a/", aTree.GetPathString());
            NUnit.Framework.Assert.AreEqual(1, aTree.GetChildCount());
            NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aTree.GetEntrySpan());
            NUnit.Framework.Assert.IsFalse(aTree.IsValid());
            DirCacheTree acTree = aTree.GetChild(0);

            NUnit.Framework.Assert.IsNotNull(acTree);
            NUnit.Framework.Assert.AreSame(acTree, aTree.GetChild(0));
            NUnit.Framework.Assert.AreEqual("c", acTree.GetNameString());
            NUnit.Framework.Assert.AreEqual("a/c/", acTree.GetPathString());
            NUnit.Framework.Assert.AreEqual(0, acTree.GetChildCount());
            NUnit.Framework.Assert.AreEqual(acLast - acFirst + 1, acTree.GetEntrySpan());
            NUnit.Framework.Assert.IsFalse(acTree.IsValid());
        }
        public virtual void TestEmptyCache_CreateEmptyCacheTree()
        {
            DirCache     dc   = db.ReadDirCache();
            DirCacheTree tree = dc.GetCacheTree(true);

            NUnit.Framework.Assert.IsNotNull(tree);
            NUnit.Framework.Assert.AreSame(tree, dc.GetCacheTree(false));
            NUnit.Framework.Assert.AreSame(tree, dc.GetCacheTree(true));
            NUnit.Framework.Assert.AreEqual(string.Empty, tree.GetNameString());
            NUnit.Framework.Assert.AreEqual(string.Empty, tree.GetPathString());
            NUnit.Framework.Assert.AreEqual(0, tree.GetChildCount());
            NUnit.Framework.Assert.AreEqual(0, tree.GetEntrySpan());
            NUnit.Framework.Assert.IsFalse(tree.IsValid());
        }
예제 #9
0
        public virtual void TestEntriesWithin()
        {
            DirCache dc = db.ReadDirCache();

            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 = FileMode.REGULAR_FILE;
            }
            int             aFirst = 1;
            int             aLast  = 3;
            DirCacheBuilder b      = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            NUnit.Framework.Assert.AreEqual(paths.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));
            }
            {
                DirCacheEntry[] aContents = dc.GetEntriesWithin("a");
                NUnit.Framework.Assert.IsNotNull(aContents);
                NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
                for (int i_3 = aFirst, j = 0; i_3 <= aLast; i_3++, j++)
                {
                    NUnit.Framework.Assert.AreSame(ents[i_3], aContents[j]);
                }
            }
            {
                DirCacheEntry[] aContents = dc.GetEntriesWithin("a/");
                NUnit.Framework.Assert.IsNotNull(aContents);
                NUnit.Framework.Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
                for (int i_3 = aFirst, j = 0; i_3 <= aLast; i_3++, j++)
                {
                    NUnit.Framework.Assert.AreSame(ents[i_3], aContents[j]);
                }
            }
            NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("a."));
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("a.").Length);
            NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("a0b"));
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("a0b.").Length);
            NUnit.Framework.Assert.IsNotNull(dc.GetEntriesWithin("zoo"));
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntriesWithin("zoo.").Length);
        }
예제 #10
0
        public virtual void TestCorruptChecksumAtFooter()
        {
            DirCache dc = new DirCache(PathOf("gitgit.index.badchecksum"), FS.DETECTED);

            try
            {
                dc.Read();
                NUnit.Framework.Assert.Fail("Cache loaded despite corrupt checksum");
            }
            catch (CorruptObjectException err)
            {
                NUnit.Framework.Assert.AreEqual("DIRC checksum mismatch", err.Message);
            }
        }
예제 #11
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());
     }
 }
예제 #12
0
        public virtual void TestUnsupportedRequiredExtension()
        {
            DirCache dc = new DirCache(PathOf("gitgit.index.aaaa"), FS.DETECTED);

            try
            {
                dc.Read();
                NUnit.Framework.Assert.Fail("Cache loaded an unsupported extension");
            }
            catch (CorruptObjectException err)
            {
                NUnit.Framework.Assert.AreEqual("DIRC extension 'aaaa'" + " not supported by this version."
                                                , err.Message);
            }
        }
예제 #13
0
        public virtual void TestSingleSubtree_NoRecursion()
        {
            DirCache dc = DirCache.NewInCore();

            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 = FileMode.REGULAR_FILE;
            }
            DirCacheBuilder b = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            string[]   expPaths = new string[] { "a.", "a", "a0b" };
            FileMode[] expModes = new FileMode[] { FileMode.REGULAR_FILE, FileMode.TREE, FileMode
                                                   .REGULAR_FILE };
            int[]            expPos = new int[] { 0, -1, 4 };
            DirCacheIterator i_2    = new DirCacheIterator(dc);
            TreeWalk         tw     = new TreeWalk(db);

            tw.AddTree(i_2);
            tw.Recursive = false;
            int pathIdx = 0;

            while (tw.Next())
            {
                NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0));
                NUnit.Framework.Assert.AreEqual(expModes[pathIdx].GetBits(), tw.GetRawMode(0));
                NUnit.Framework.Assert.AreSame(expModes[pathIdx], tw.GetFileMode(0));
                NUnit.Framework.Assert.AreEqual(expPaths[pathIdx], tw.PathString);
                if (expPos[pathIdx] >= 0)
                {
                    NUnit.Framework.Assert.AreEqual(expPos[pathIdx], i_2.ptr);
                    NUnit.Framework.Assert.AreSame(ents[expPos[pathIdx]], i_2.GetDirCacheEntry());
                }
                else
                {
                    NUnit.Framework.Assert.AreSame(FileMode.TREE, tw.GetFileMode(0));
                }
                pathIdx++;
            }
            NUnit.Framework.Assert.AreEqual(expPaths.Length, pathIdx);
        }
예제 #14
0
        public virtual void TestWriteEmptyUnlock_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());
            dc.Unlock();
            NUnit.Framework.Assert.IsFalse(idx.Exists());
            NUnit.Framework.Assert.IsFalse(lck.Exists());
        }
예제 #15
0
        public virtual void TestLockMissing_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.IsNotNull(dc);
            NUnit.Framework.Assert.IsFalse(idx.Exists());
            NUnit.Framework.Assert.IsTrue(lck.Exists());
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
            dc.Unlock();
            NUnit.Framework.Assert.IsFalse(idx.Exists());
            NUnit.Framework.Assert.IsFalse(lck.Exists());
        }
예제 #16
0
        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));
            }
        }
예제 #17
0
        public virtual void TestReadIndex_LsFiles()
        {
            IDictionary <string, DirCacheCGitCompatabilityTest.CGitIndexRecord> ls = ReadLsFiles
                                                                                         ();
            DirCache dc = new DirCache(index, FS.DETECTED);

            NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
            dc.Read();
            NUnit.Framework.Assert.AreEqual(ls.Count, dc.GetEntryCount());
            {
                Iterator <DirCacheCGitCompatabilityTest.CGitIndexRecord> rItr = ls.Values.Iterator
                                                                                    ();
                for (int i = 0; rItr.HasNext(); i++)
                {
                    AssertEqual(rItr.Next(), dc.GetEntry(i));
                }
            }
        }
예제 #18
0
        public virtual void TestRemovedSubtree()
        {
            FilePath path = JGitTestUtil.GetTestResourceFile("dircache.testRemovedSubtree");
            DirCache dc   = DirCache.Read(path, FS.DETECTED);

            NUnit.Framework.Assert.AreEqual(2, dc.GetEntryCount());
            TreeWalk tw = new TreeWalk(db);

            tw.Recursive = true;
            tw.AddTree(new DirCacheIterator(dc));
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("a/a", tw.PathString);
            NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, tw.GetFileMode(0));
            NUnit.Framework.Assert.IsTrue(tw.Next());
            NUnit.Framework.Assert.AreEqual("q", tw.PathString);
            NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, tw.GetFileMode(0));
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }
예제 #19
0
        public virtual void TestBuildRejectsUnsetFileMode()
        {
            DirCache        dc = DirCache.NewInCore();
            DirCacheBuilder b  = dc.Builder();

            NUnit.Framework.Assert.IsNotNull(b);
            DirCacheEntry e = new DirCacheEntry("a");

            NUnit.Framework.Assert.AreEqual(0, e.RawMode);
            try
            {
                b.Add(e);
            }
            catch (ArgumentException err)
            {
                NUnit.Framework.Assert.AreEqual("FileMode not set for path a", err.Message);
            }
        }
예제 #20
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());
            }
        }
예제 #21
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);
     }
 }
예제 #22
0
        public virtual void TestDetectUnmergedPaths()
        {
            DirCache dc = db.ReadDirCache();

            DirCacheEntry[] ents = new DirCacheEntry[3];
            ents[0]          = new DirCacheEntry("a", 1);
            ents[0].FileMode = FileMode.REGULAR_FILE;
            ents[1]          = new DirCacheEntry("a", 2);
            ents[1].FileMode = FileMode.REGULAR_FILE;
            ents[2]          = new DirCacheEntry("a", 3);
            ents[2].FileMode = FileMode.REGULAR_FILE;
            DirCacheBuilder b = dc.Builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.Add(ents[i]);
            }
            b.Finish();
            NUnit.Framework.Assert.IsTrue(dc.HasUnmergedPaths());
        }
예제 #23
0
        public virtual void TestReadIndex_DirCacheTree()
        {
            IDictionary <string, DirCacheCGitCompatabilityTest.CGitIndexRecord> cList = ReadLsFiles
                                                                                            ();
            IDictionary <string, DirCacheCGitCompatabilityTest.CGitLsTreeRecord> cTree = ReadLsTree
                                                                                             ();
            DirCache dc = new DirCache(index, FS.DETECTED);

            NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
            dc.Read();
            NUnit.Framework.Assert.AreEqual(cList.Count, dc.GetEntryCount());
            DirCacheTree jTree = dc.GetCacheTree(false);

            NUnit.Framework.Assert.IsNotNull(jTree);
            NUnit.Framework.Assert.AreEqual(string.Empty, jTree.GetNameString());
            NUnit.Framework.Assert.AreEqual(string.Empty, jTree.GetPathString());
            NUnit.Framework.Assert.IsTrue(jTree.IsValid());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("698dd0b8d0c299f080559a1cffc7fe029479a408"
                                                                ), jTree.GetObjectId());
            NUnit.Framework.Assert.AreEqual(cList.Count, jTree.GetEntrySpan());
            AList <DirCacheCGitCompatabilityTest.CGitLsTreeRecord> subtrees = new AList <DirCacheCGitCompatabilityTest.CGitLsTreeRecord
                                                                                         >();

            foreach (DirCacheCGitCompatabilityTest.CGitLsTreeRecord r in cTree.Values)
            {
                if (FileMode.TREE.Equals(r.mode))
                {
                    subtrees.AddItem(r);
                }
            }
            NUnit.Framework.Assert.AreEqual(subtrees.Count, jTree.GetChildCount());
            for (int i = 0; i < jTree.GetChildCount(); i++)
            {
                DirCacheTree sj = jTree.GetChild(i);
                DirCacheCGitCompatabilityTest.CGitLsTreeRecord sc = subtrees[i];
                NUnit.Framework.Assert.AreEqual(sc.path, sj.GetNameString());
                NUnit.Framework.Assert.AreEqual(sc.path + "/", sj.GetPathString());
                NUnit.Framework.Assert.IsTrue(sj.IsValid());
                NUnit.Framework.Assert.AreEqual(sc.id, sj.GetObjectId());
            }
        }
예제 #24
0
 private void BeforeAdd(DirCacheEntry newEntry)
 {
     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.Stage;
                 int dceStage = newEntry.Stage;
                 if (peStage == dceStage)
                 {
                     throw Bad(newEntry, JGitText.Get().duplicateStagesNotAllowed);
                 }
                 if (peStage == 0 || dceStage == 0)
                 {
                     throw Bad(newEntry, JGitText.Get().mixedStagesNotAllowed);
                 }
                 if (peStage > dceStage)
                 {
                     sorted = false;
                 }
             }
         }
     }
 }
예제 #25
0
        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);
        }
예제 #26
0
        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 TestAddDeleteTrickyNames()
        {
            DirCache       dc     = DirCache.NewInCore();
            DirCacheEditor editor = dc.Editor();

            editor.Add(new DirCachePathEditTest.AddEdit("a/b"));
            editor.Add(new DirCachePathEditTest.AddEdit("a."));
            editor.Add(new DirCachePathEditTest.AddEdit("ab"));
            editor.Finish();
            NUnit.Framework.Assert.AreEqual(3, dc.GetEntryCount());
            // Validate sort order
            NUnit.Framework.Assert.AreEqual("a.", dc.GetEntry(0).PathString);
            NUnit.Framework.Assert.AreEqual("a/b", dc.GetEntry(1).PathString);
            NUnit.Framework.Assert.AreEqual("ab", dc.GetEntry(2).PathString);
            editor = dc.Editor();
            // Sort order should not confuse DeleteTree
            editor.Add(new DirCacheEditor.DeleteTree("a"));
            editor.Finish();
            NUnit.Framework.Assert.AreEqual(2, dc.GetEntryCount());
            NUnit.Framework.Assert.AreEqual("a.", dc.GetEntry(0).PathString);
            NUnit.Framework.Assert.AreEqual("ab", dc.GetEntry(1).PathString);
        }
예제 #28
0
        public virtual void TestFindSingleFile()
        {
            string          path = "a-file-path";
            DirCache        dc   = db.ReadDirCache();
            DirCacheBuilder b    = dc.Builder();

            NUnit.Framework.Assert.IsNotNull(b);
            DirCacheEntry entOrig = new DirCacheEntry(path);

            entOrig.FileMode = FileMode.REGULAR_FILE;
            NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString);
            NUnit.Framework.Assert.AreEqual(path, entOrig.PathString);
            b.Add(entOrig);
            b.Finish();
            NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
            NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0));
            NUnit.Framework.Assert.AreEqual(0, dc.FindEntry(path));
            NUnit.Framework.Assert.AreEqual(-1, dc.FindEntry("@@-before"));
            NUnit.Framework.Assert.AreEqual(0, Real(dc.FindEntry("@@-before")));
            NUnit.Framework.Assert.AreEqual(-2, dc.FindEntry("a-zoo"));
            NUnit.Framework.Assert.AreEqual(1, Real(dc.FindEntry("a-zoo")));
            NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(path));
        }
예제 #29
0
        public virtual void TestNoSubtree_WithTreeWalk()
        {
            DirCache dc = DirCache.NewInCore();

            string[]        paths = new string[] { "a.", "a0b" };
            FileMode[]      modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i]          = new DirCacheEntry(paths[i]);
                ents[i].FileMode = modes[i];
            }
            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);
            int pathIdx = 0;

            while (tw.Next())
            {
                NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0));
                NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr);
                NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry());
                NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString);
                NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0));
                NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0));
                pathIdx++;
            }
            NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx);
        }
        public virtual void TestAddDeletePathAndTreeNormalNames()
        {
            DirCache       dc     = DirCache.NewInCore();
            DirCacheEditor editor = dc.Editor();

            editor.Add(new DirCachePathEditTest.AddEdit("a"));
            editor.Add(new DirCachePathEditTest.AddEdit("b/c"));
            editor.Add(new DirCachePathEditTest.AddEdit("c/d"));
            editor.Finish();
            NUnit.Framework.Assert.AreEqual(3, dc.GetEntryCount());
            NUnit.Framework.Assert.AreEqual("a", dc.GetEntry(0).PathString);
            NUnit.Framework.Assert.AreEqual("b/c", dc.GetEntry(1).PathString);
            NUnit.Framework.Assert.AreEqual("c/d", dc.GetEntry(2).PathString);
            editor = dc.Editor();
            editor.Add(new DirCacheEditor.DeletePath("b/c"));
            editor.Finish();
            NUnit.Framework.Assert.AreEqual(2, dc.GetEntryCount());
            NUnit.Framework.Assert.AreEqual("a", dc.GetEntry(0).PathString);
            NUnit.Framework.Assert.AreEqual("c/d", dc.GetEntry(1).PathString);
            editor = dc.Editor();
            editor.Add(new DirCacheEditor.DeleteTree(string.Empty));
            editor.Finish();
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
        }