Exemple #1
0
        public void testTrivialTwoWay_rightDFconflict2()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("d", FileMode.RegularFile));

                o.add(MakeEntry("d/o", FileMode.RegularFile));

                t.add(MakeEntry("d", FileMode.RegularFile, "t !"));

                b.finish();
                o.finish();
                t.finish();
            }

            var      ow = new ObjectWriter(db);
            ObjectId B  = Commit(ow, treeB, new ObjectId[] { });
            ObjectId O  = Commit(ow, treeO, new[] { B });
            ObjectId T  = Commit(ow, treeT, new[] { B });

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool   merge     = ourMerger.Merge(new[] { O, T });

            Assert.IsFalse(merge);
        }
        public void testNoPostOrder()
        {
            DirCache tree = DirCache.read(db);
            {
                DirCacheBuilder b = tree.builder();

                b.add(makeFile("a"));
                b.add(makeFile("b/c"));
                b.add(makeFile("b/d"));
                b.add(makeFile("q"));

                b.finish();
                Assert.AreEqual(4, tree.getEntryCount());
            }

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);

            tw.reset();
            tw.PostOrderTraversal = false;
            tw.addTree(new DirCacheIterator(tree));

            assertModes("a", FileMode.RegularFile, tw);
            assertModes("b", FileMode.Tree, tw);
            Assert.IsTrue(tw.isSubtree());
            Assert.IsFalse(tw.isPostChildren());
            tw.enterSubtree();
            assertModes("b/c", FileMode.RegularFile, tw);
            assertModes("b/d", FileMode.RegularFile, tw);
            assertModes("q", FileMode.RegularFile, tw);
        }
Exemple #3
0
        public void testBuilderClear()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a.b", "a/b", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }
            {
                DirCacheBuilder b = dc.builder();
                for (int i = 0; i < ents.Length; i++)
                {
                    b.add(ents[i]);
                }
                b.finish();
            }
            Assert.AreEqual(paths.Length, dc.getEntryCount());
            {
                DirCacheBuilder b = dc.builder();
                b.finish();
            }
            Assert.AreEqual(0, dc.getEntryCount());
        }
Exemple #4
0
        public void testBuildThenClear()
        {
            DirCache dc = DirCache.read(db);

            string[] paths = { "a.", "a.b", "a/b", "a0b" };

            var ents = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }

            b.finish();

            Assert.AreEqual(paths.Length, dc.getEntryCount());
            dc.clear();
            Assert.AreEqual(0, dc.getEntryCount());
        }
Exemple #5
0
        public void testFindSingleFile()
        {
            string          path = "a-File-path";
            DirCache        dc   = DirCache.read(db);
            DirCacheBuilder b    = dc.builder();

            Assert.IsNotNull(b);

            DirCacheEntry entOrig = new DirCacheEntry(path);

            entOrig.setFileMode(FileMode.RegularFile);
            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            b.add(entOrig);
            b.finish();

            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));
            Assert.AreEqual(0, dc.findEntry(path));

            Assert.AreEqual(-1, dc.findEntry("@@-before"));
            Assert.AreEqual(0, real(dc.findEntry("@@-before")));

            Assert.AreEqual(-2, dc.findEntry("a-zoo"));
            Assert.AreEqual(1, real(dc.findEntry("a-zoo")));

            Assert.AreSame(entOrig, dc.getEntry(path));
        }
Exemple #6
0
        public void testAdd_ReverseGitSortOrder()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a.b", "a/b", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = ents.Length - 1; i >= 0; i--)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.AreEqual(paths.Length, dc.getEntryCount());
            for (int i = 0; i < paths.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
                Assert.AreEqual(paths[i], dc.getEntry(i).getPathString());
                Assert.AreEqual(i, dc.findEntry(paths[i]));
                Assert.AreSame(ents[i], dc.getEntry(paths[i]));
            }
        }
Exemple #7
0
        private void testLongPath(int len)
        {
            string longPath  = makeLongPath(len);
            string shortPath = "~~~ shorter-path";

            DirCacheEntry longEnt  = new DirCacheEntry(longPath);
            DirCacheEntry shortEnt = new DirCacheEntry(shortPath);

            Assert.AreEqual(longPath, longEnt.getPathString());
            Assert.AreEqual(shortPath, shortEnt.getPathString());

            DirCache        dc1 = DirCache.Lock(db);
            DirCacheBuilder b   = dc1.builder();

            b.add(longEnt);
            b.add(shortEnt);
            Assert.IsTrue(b.commit());
            Assert.AreEqual(2, dc1.getEntryCount());
            Assert.AreSame(longEnt, dc1.getEntry(0));
            Assert.AreSame(shortEnt, dc1.getEntry(1));

            DirCache dc2 = DirCache.read(db);

            Assert.AreEqual(2, dc2.getEntryCount());
            Assert.AreNotSame(longEnt, dc2.getEntry(0));
            Assert.AreEqual(longPath, dc2.getEntry(0).getPathString());
            Assert.AreNotSame(shortEnt, dc2.getEntry(1));
            Assert.AreEqual(shortPath, dc2.getEntry(1).getPathString());
        }
Exemple #8
0
        public void testWriteReadTree()
        {
            DirCache dc = DirCache.Lock(db);

            string A = string.Format("a%2000s", "a");
            string B = string.Format("b%2000s", "b");

            string[] paths = { A + ".", A + "." + B, A + "/" + B, A + "0" + B };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }

            b.commit();
            DirCache read = DirCache.read(db);

            Assert.AreEqual(paths.Length, read.getEntryCount());
            Assert.AreEqual(1, read.getCacheTree(true).getChildCount());
        }
        public virtual void testDF_NoGap()
        {
            DirCache tree0 = DirCache.read(db);
            DirCache tree1 = DirCache.read(db);
            {
                DirCacheBuilder b0 = tree0.builder();
                DirCacheBuilder b1 = tree1.builder();

                b0.add(makeEntry("a", REGULAR_FILE));
                b0.add(makeEntry("a.b", EXECUTABLE_FILE));
                b1.add(makeEntry("a/b", REGULAR_FILE));
                b0.add(makeEntry("a0b", SYMLINK));

                b0.finish();
                b1.finish();
                Assert.AreEqual(3, tree0.getEntryCount());
                Assert.AreEqual(1, tree1.getEntryCount());
            }

            NameConflictTreeWalk tw = new NameConflictTreeWalk(db);

            tw.reset();
            tw.addTree(new DirCacheIterator(tree0));
            tw.addTree(new DirCacheIterator(tree1));

            assertModes("a", REGULAR_FILE, TREE, tw);
            Assert.IsTrue(tw.isSubtree());
            tw.enterSubtree();
            assertModes("a/b", MISSING, REGULAR_FILE, tw);
            assertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
            assertModes("a0b", SYMLINK, MISSING, tw);
        }
        public void testNoSubtree_NoTreeWalk()
        {
            DirCache dc = DirCache.read(db);

            string[] paths = { "a.", "a0b" };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }

            b.finish();

            var iter    = new DirCacheIterator(dc);
            int pathIdx = 0;

            for (; !iter.eof(); iter.next(1))
            {
                Assert.AreEqual(pathIdx, iter.Pointer);
                Assert.AreSame(ents[pathIdx], iter.getDirCacheEntry());
                pathIdx++;
            }

            Assert.AreEqual(paths.Length, pathIdx);
        }
        public void testUnsupportedOptionalExtension()
        {
            var dc = new DirCache(pathOf("gitgit.index.ZZZZ"));

            dc.read();
            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreEqual("A", dc.getEntry(0).getPathString());
        }
Exemple #12
0
        public void testTrivialTwoWay_validSubtreeSort()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                b.add(MakeEntry("libelf/c", FileMode.RegularFile));

                o.add(MakeEntry("Makefile", FileMode.RegularFile));
                o.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                o.add(MakeEntry("libelf/c", FileMode.RegularFile));

                t.add(MakeEntry("libelf-po/a", FileMode.RegularFile));
                t.add(MakeEntry("libelf/c", FileMode.RegularFile, "blah"));

                b.finish();
                o.finish();
                t.finish();
            }

            var      ow = new ObjectWriter(db);
            ObjectId B  = Commit(ow, treeB, new ObjectId[] { });
            ObjectId O  = Commit(ow, treeO, new[] { B });
            ObjectId T  = Commit(ow, treeT, new[] { B });

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool   merge     = ourMerger.Merge(new[] { O, T });

            Assert.IsTrue(merge);

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db)
            {
                Recursive = true
            };

            tw.reset(ourMerger.GetResultTreeId());

            Assert.IsTrue(tw.next());
            Assert.AreEqual("Makefile", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("libelf-po/a", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("libelf/c", tw.getPathString());
            AssertCorrectId(treeT, tw);

            Assert.IsFalse(tw.next());
        }
        public void testEmptyTree_NoTreeWalk()
        {
            DirCache dc = DirCache.read(db);

            Assert.AreEqual(0, dc.getEntryCount());

            var i = new DirCacheIterator(dc);

            Assert.IsTrue(i.eof());
        }
Exemple #14
0
        public void testEmptyCache_Clear_NoCacheTree()
        {
            DirCache     dc   = DirCache.read(db);
            DirCacheTree tree = dc.getCacheTree(true);

            Assert.IsNotNull(tree);
            dc.clear();
            Assert.IsNull(dc.getCacheTree(false));
            Assert.AreNotSame(tree, dc.getCacheTree(true));
        }
Exemple #15
0
        public void testTwoLevelSubtree()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "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].setFileMode(FileMode.RegularFile);
            }
            int aFirst  = 1;
            int aLast   = 4;
            int acFirst = 2;
            int acLast  = 3;

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.IsNull(dc.getCacheTree(false));
            DirCacheTree root = dc.getCacheTree(true);

            Assert.IsNotNull(root);
            Assert.AreSame(root, dc.getCacheTree(true));
            Assert.AreEqual(string.Empty, root.getNameString());
            Assert.AreEqual(string.Empty, root.getPathString());
            Assert.AreEqual(1, root.getChildCount());
            Assert.AreEqual(dc.getEntryCount(), root.getEntrySpan());
            Assert.IsFalse(root.isValid());

            DirCacheTree aTree = root.getChild(0);

            Assert.IsNotNull(aTree);
            Assert.AreSame(aTree, root.getChild(0));
            Assert.AreEqual("a", aTree.getNameString());
            Assert.AreEqual("a/", aTree.getPathString());
            Assert.AreEqual(1, aTree.getChildCount());
            Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan());
            Assert.IsFalse(aTree.isValid());

            DirCacheTree acTree = aTree.getChild(0);

            Assert.IsNotNull(acTree);
            Assert.AreSame(acTree, aTree.getChild(0));
            Assert.AreEqual("c", acTree.getNameString());
            Assert.AreEqual("a/c/", acTree.getPathString());
            Assert.AreEqual(0, acTree.getChildCount());
            Assert.AreEqual(acLast - acFirst + 1, acTree.getEntrySpan());
            Assert.IsFalse(acTree.isValid());
        }
Exemple #16
0
        public void testReadMissing_TempIndex()
        {
            var idx = new FileInfo(db.Directory + "/tmp_index");

            Assert.IsFalse(File.Exists(idx.FullName));

            DirCache dc = DirCache.read(idx);

            Assert.IsNotNull(dc);
            Assert.AreEqual(0, dc.getEntryCount());
        }
        public void testSingleSubtree_NoRecursion()
        {
            DirCache dc = DirCache.read(db);

            string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            string[]   expPaths = { "a.", "a", "a0b" };
            FileMode[] expModes = { FileMode.RegularFile, FileMode.Tree, FileMode.RegularFile };
            var        expPos   = new[] { 0, -1, 4 };

            var iter = new DirCacheIterator(dc);
            var tw   = new TreeWalk(db);

            tw.reset();
            tw.addTree(iter);
            tw.Recursive = false;
            int pathIdx = 0;

            while (tw.next())
            {
                Assert.AreSame(iter, tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator)));
                Assert.AreEqual(expModes[pathIdx].Bits, tw.getRawMode(0));
                Assert.AreSame(expModes[pathIdx], tw.getFileMode(0));
                Assert.AreEqual(expPaths[pathIdx], tw.getPathString());

                if (expPos[pathIdx] >= 0)
                {
                    Assert.AreEqual(expPos[pathIdx], iter.Pointer);
                    Assert.AreSame(ents[expPos[pathIdx]], iter.getDirCacheEntry());
                }
                else
                {
                    Assert.AreSame(FileMode.Tree, tw.getFileMode(0));
                }

                pathIdx++;
            }
            Assert.AreEqual(expPaths.Length, pathIdx);
        }
Exemple #18
0
        public void testEntriesWithin()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "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].setFileMode(FileMode.RegularFile);
            }

            int aFirst = 1;
            int aLast  = 3;

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.AreEqual(paths.Length, dc.getEntryCount());
            for (int i = 0; i < ents.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
            }

            DirCacheEntry[] aContents = dc.getEntriesWithin("a");
            Assert.IsNotNull(aContents);
            Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
            for (int i = aFirst, j = 0; i <= aLast; i++, j++)
            {
                Assert.AreSame(ents[i], aContents[j]);
            }

            aContents = dc.getEntriesWithin("a/");
            Assert.IsNotNull(aContents);
            Assert.AreEqual(aLast - aFirst + 1, aContents.Length);
            for (int i = aFirst, j = 0; i <= aLast; i++, j++)
            {
                Assert.AreSame(ents[i], aContents[j]);
            }

            Assert.IsNotNull(dc.getEntriesWithin("a."));
            Assert.AreEqual(0, dc.getEntriesWithin("a.").Length);

            Assert.IsNotNull(dc.getEntriesWithin("a0b"));
            Assert.AreEqual(0, dc.getEntriesWithin("a0b.").Length);

            Assert.IsNotNull(dc.getEntriesWithin("zoo"));
            Assert.AreEqual(0, dc.getEntriesWithin("zoo.").Length);
        }
        public void testEmptyTree_WithTreeWalk()
        {
            DirCache dc = DirCache.read(db);

            Assert.AreEqual(0, dc.getEntryCount());

            var tw = new TreeWalk(db);

            tw.reset();
            tw.addTree(new DirCacheIterator(dc));
            Assert.IsFalse(tw.next());
        }
        public FullTextIndex(string path)
        {
            this.fullpath = path;
            var dir   = Path.GetDirectoryName(path);
            var fname = Path.GetFileName(path);

            this.lastModified = File.GetLastWriteTimeUtc(path);

            DirCache dcache;

            if (!dirCaches.TryGetValue(dir, out dcache))
            {
                dcache = new DirCache();
                dcache.read(dir + ".search_index");
                dirCaches[dir] = dcache;
            }

            if (dcache.cache.ContainsKey(fname))
            {
                var fti = dcache.cache[fname];
                if (fti.lastModified == this.lastModified)
                {
                    this.data         = fti.data;
                    this.suffix_array = fti.suffix_array;
                    return;
                }
            }

            try
            {
                data = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path).ToLowerInvariant());
            }
            catch (IOException) { return; }
            catch (UnauthorizedAccessException) { return; }

            if (suffix_array == null)
            {
                var temp = new int[data.Length + 3];
                for (int i = 0; i < data.Length; i++)
                {
                    temp[i] = data[i];
                }
                temp[data.Length] = temp[data.Length + 1] = temp[data.Length + 2] = 0;
                suffix_array      = new int[data.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    suffix_array[i] = i;
                }
                suffixArray(temp, suffix_array, data.Length, 255);

                dcache.Add(this);
            }
        }
        public void testRecursiveFiltering()
        {
            var             ow        = new ObjectWriter(db);
            ObjectId        aSth      = ow.WriteBlob("a.sth".getBytes());
            ObjectId        aTxt      = ow.WriteBlob("a.txt".getBytes());
            ObjectId        bSth      = ow.WriteBlob("b.sth".getBytes());
            ObjectId        bTxt      = ow.WriteBlob("b.txt".getBytes());
            DirCache        dc        = DirCache.read(db);
            DirCacheBuilder builder   = dc.builder();
            var             aSthEntry = new DirCacheEntry("a.sth");

            aSthEntry.setFileMode(FileMode.RegularFile);
            aSthEntry.setObjectId(aSth);
            var aTxtEntry = new DirCacheEntry("a.txt");

            aTxtEntry.setFileMode(FileMode.RegularFile);
            aTxtEntry.setObjectId(aTxt);
            builder.add(aSthEntry);
            builder.add(aTxtEntry);
            var bSthEntry = new DirCacheEntry("sub/b.sth");

            bSthEntry.setFileMode(FileMode.RegularFile);
            bSthEntry.setObjectId(bSth);
            var bTxtEntry = new DirCacheEntry("sub/b.txt");

            bTxtEntry.setFileMode(FileMode.RegularFile);
            bTxtEntry.setObjectId(bTxt);
            builder.add(bSthEntry);
            builder.add(bTxtEntry);
            builder.finish();
            ObjectId treeId = dc.writeTree(ow);


            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);

            tw.Recursive = true;
            tw.setFilter(PathSuffixFilter.create(".txt"));
            tw.addTree(treeId);

            var paths = new LinkedList <string>();

            while (tw.next())
            {
                paths.AddLast(tw.getPathString());
            }

            var expected = new LinkedList <string>();

            expected.AddLast("a.txt");
            expected.AddLast("sub/b.txt");

            Assert.AreEqual(expected, paths);
        }
Exemple #22
0
        public void testPathFilterGroup_DoesNotSkipTail()
        {
            DirCache dc = DirCache.read(db);

            var mode = FileMode.RegularFile;

            string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(mode);
            }

            DirCacheBuilder builder = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                builder.add(ents[i]);
            }
            builder.finish();

            const int       expIdx = 2;
            DirCacheBuilder b      = dc.builder();
            var             tw     = new GitSharp.Core.TreeWalk.TreeWalk(db);

            tw.reset();
            tw.addTree(new DirCacheBuildIterator(b));
            tw.Recursive = true;
            tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[expIdx] }));

            Assert.IsTrue(tw.next(), "found " + paths[expIdx]);
            var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator));

            Assert.IsNotNull(c);
            Assert.AreEqual(expIdx, c.Pointer);
            Assert.AreSame(ents[expIdx], c.getDirCacheEntry());
            Assert.AreEqual(paths[expIdx], tw.getPathString());
            Assert.AreEqual(mode.Bits, tw.getRawMode(0));
            Assert.AreSame(mode, tw.getFileMode(0));
            b.add(c.getDirCacheEntry());

            Assert.IsFalse(tw.next(), "no more entries");

            b.finish();
            Assert.AreEqual(ents.Length, dc.getEntryCount());
            for (int i = 0; i < ents.Length; i++)
            {
                Assert.AreSame(ents[i], dc.getEntry(i));
            }
        }
Exemple #23
0
        public void testBuildEmpty()
        {
            DirCache        dc = DirCache.Lock(db);
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);
            b.finish();
            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(0, dc.getEntryCount());
        }
Exemple #24
0
        public void testEmptyCache_CreateEmptyCacheTree()
        {
            DirCache     dc   = DirCache.read(db);
            DirCacheTree tree = dc.getCacheTree(true);

            Assert.IsNotNull(tree);
            Assert.AreSame(tree, dc.getCacheTree(false));
            Assert.AreSame(tree, dc.getCacheTree(true));
            Assert.AreEqual(string.Empty, tree.getNameString());
            Assert.AreEqual(string.Empty, tree.getPathString());
            Assert.AreEqual(0, tree.getChildCount());
            Assert.AreEqual(0, tree.getEntrySpan());
            Assert.IsFalse(tree.isValid());
        }
        public void testCorruptChecksumAtFooter()
        {
            var dc = new DirCache(pathOf("gitgit.index.badchecksum"));

            try
            {
                dc.read();
                Assert.Fail("Cache loaded despite corrupt checksum");
            }
            catch (CorruptObjectException err)
            {
                Assert.AreEqual("DIRC checksum mismatch", err.Message);
            }
        }
Exemple #26
0
        public void testBuildOneFile_FinishWriteCommit()
        {
            string        path         = "a-File-path";
            var           mode         = 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 void testUnsupportedRequiredExtension()
        {
            var dc = new DirCache(pathOf("gitgit.index.aaaa"));

            try
            {
                dc.read();
                Assert.Fail("Cache loaded an unsupported extension");
            }
            catch (CorruptObjectException err)
            {
                Assert.AreEqual("DIRC extension 'aaaa'"
                                + " not supported by this version.", err.Message);
            }
        }
Exemple #28
0
        public void testWriteEmptyReadEmpty_RealIndex()
        {
            var idx = new FileInfo(db.Directory + "/index");
            var lck = new FileInfo(db.Directory + "/index.lock");

            Assert.IsFalse(File.Exists(idx.FullName));
            Assert.IsFalse(File.Exists(lck.FullName));

            DirCache dc = DirCache.Lock(db);

            dc.write();
            Assert.IsTrue(dc.commit());
            Assert.IsTrue(File.Exists(idx.FullName));

            dc = DirCache.read(db);
            Assert.AreEqual(0, dc.getEntryCount());
        }
        public void testReadIndex_LsFiles()
        {
            List <CGitIndexRecord> ls = ReadLsFiles();
            var dc = new DirCache(_index);

            Assert.AreEqual(0, dc.getEntryCount());
            dc.read();
            Assert.AreEqual(ls.Count, dc.getEntryCount());

            int i = 0;

            foreach (var val in ls)
            {
                AssertAreEqual(val, dc.getEntry(i));
                i++;
            }
        }
Exemple #30
0
        public FullTextIndex(string path)
        {
            this.fullpath = path;
            var dir = Path.GetDirectoryName(path);
            var fname = Path.GetFileName(path);
            this.lastModified = File.GetLastWriteTimeUtc(path);

            DirCache dcache;
            if (!dirCaches.TryGetValue(dir, out dcache)) {
                dcache = new DirCache();
                dcache.read(dir + ".search_index");
                dirCaches[dir] = dcache;
            }

            if (dcache.cache.ContainsKey(fname))
            {
                var fti = dcache.cache[fname];
                if (fti.lastModified == this.lastModified)
                {
                    this.data = fti.data;
                    this.suffix_array = fti.suffix_array;
                    return;
                }
            }

            try
            {
                data = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path).ToLowerInvariant());
            }
            catch (IOException) { return; }
            catch (UnauthorizedAccessException) { return;  }

            if (suffix_array == null) {
                var temp = new int[data.Length + 3];
                for (int i = 0; i < data.Length; i++)
                    temp[i] = data[i];
                temp[data.Length] = temp[data.Length + 1] = temp[data.Length + 2] = 0;
                suffix_array = new int[data.Length];
                for (int i = 0; i < data.Length; i++)
                    suffix_array[i] = i;
                suffixArray(temp, suffix_array, data.Length, 255);

                dcache.Add(this);
            }
        }
        public void testSingleSubtree_Recursive()
        {
            DirCache dc = DirCache.read(db);

            FileMode mode = FileMode.RegularFile;

            string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
            var      ents  = new DirCacheEntry[paths.Length];

            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(mode);
            }

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            var iter = new DirCacheIterator(dc);
            var tw   = new TreeWalk(db);

            tw.reset();
            tw.addTree(iter);
            tw.Recursive = true;
            int pathIdx = 0;

            while (tw.next())
            {
                var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator));
                Assert.IsNotNull(c);
                Assert.AreEqual(pathIdx, c.Pointer);
                Assert.AreSame(ents[pathIdx], c.getDirCacheEntry());
                Assert.AreEqual(paths[pathIdx], tw.getPathString());
                Assert.AreEqual(mode.Bits, tw.getRawMode(0));
                Assert.AreSame(mode, tw.getFileMode(0));
                pathIdx++;
            }

            Assert.AreEqual(paths.Length, pathIdx);
        }