Esempio n. 1
0
        public virtual void TestNotPackTwice()
        {
            BranchBuilder bb    = tr.Branch("refs/heads/master");
            RevCommit     first = bb.Commit().Message("M").Add("M", "M").Create();

            bb.Commit().Message("B").Add("B", "Q").Create();
            bb.Commit().Message("A").Add("A", "A").Create();
            RevCommit second = tr.Commit().Parent(first).Message("R").Add("R", "Q").Create();

            tr.Update("refs/tags/t1", second);
            ICollection <PackFile> oldPacks = ((ObjectDirectory)tr.GetRepository().ObjectDatabase
                                               ).GetPacks();

            NUnit.Framework.Assert.AreEqual(0, oldPacks.Count);
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(11, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            gc.SetExpireAgeMillis(0);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
            Iterator <PackFile> pIt = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
                                          ();
            long c = pIt.Next().GetObjectCount();

            if (c == 9)
            {
                NUnit.Framework.Assert.AreEqual(2, pIt.Next().GetObjectCount());
            }
            else
            {
                NUnit.Framework.Assert.AreEqual(2, c);
                NUnit.Framework.Assert.AreEqual(9, pIt.Next().GetObjectCount());
            }
        }
Esempio n. 2
0
        public virtual void TestKeepFiles()
        {
            BranchBuilder bb = tr.Branch("refs/heads/master");

            bb.Commit().Add("A", "A").Add("B", "B").Create();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackFiles);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
            Iterator <PackFile> packIt = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
                                             ();
            PackFile singlePack = packIt.Next();

            NUnit.Framework.Assert.IsFalse(packIt.HasNext());
            FilePath keepFile = new FilePath(singlePack.GetPackFile().GetPath() + ".keep");

            NUnit.Framework.Assert.IsFalse(keepFile.Exists());
            NUnit.Framework.Assert.IsTrue(keepFile.CreateNewFile());
            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles);
            // check that no object is packed twice
            Iterator <PackFile> packs = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
                                            ();
            PackIndex ind1 = packs.Next().GetIndex();

            NUnit.Framework.Assert.AreEqual(4, ind1.GetObjectCount());
            PackIndex ind2 = packs.Next().GetIndex();

            NUnit.Framework.Assert.AreEqual(4, ind2.GetObjectCount());
            foreach (PackIndex.MutableEntry e in ind1)
            {
                if (ind2.HasObject(e.ToObjectId()))
                {
                    NUnit.Framework.Assert.IsFalse(ind2.HasObject(e.ToObjectId()), "the following object is in both packfiles: "
                                                   + e.ToObjectId());
                }
            }
        }
Esempio n. 3
0
        public virtual void TestPack2Commits()
        {
            BranchBuilder bb = tr.Branch("refs/heads/master");

            bb.Commit().Add("A", "A").Add("B", "B").Create();
            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
        }
Esempio n. 4
0
        public virtual void TestIndexSavesObjects()
        {
            BranchBuilder bb = tr.Branch("refs/heads/master");

            bb.Commit().Add("A", "A").Add("B", "B").Create();
            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            bb.Commit().Add("A", "A3");
            // this new content in index should survive
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(9, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
        }
Esempio n. 5
0
        public virtual void TestPackCommitsAndLooseOneWithPruneNow()
        {
            BranchBuilder bb    = tr.Branch("refs/heads/master");
            RevCommit     first = bb.Commit().Add("A", "A").Add("B", "B").Create();

            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            tr.Update("refs/heads/master", first);
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            gc.SetExpireAgeMillis(0);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles);
        }
Esempio n. 6
0
        public virtual void TestPruneNone()
        {
            BranchBuilder bb = tr.Branch("refs/heads/master");

            bb.Commit().Add("A", "A").Add("B", "B").Create();
            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            new FilePath(repo.Directory, Constants.LOGS + "/refs/heads/master").Delete();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
            gc.SetExpireAgeMillis(0);
            gc.Prune(Sharpen.Collections.EmptySet <ObjectId>());
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
            tr.Blob("x");
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(9, stats.numberOfLooseObjects);
            gc.Prune(Sharpen.Collections.EmptySet <ObjectId>());
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
        }
Esempio n. 7
0
        public virtual void TestPackCommitsAndLooseOneNoReflog()
        {
            BranchBuilder bb    = tr.Branch("refs/heads/master");
            RevCommit     first = bb.Commit().Add("A", "A").Add("B", "B").Create();

            bb.Commit().Add("A", "A2").Add("B", "B2").Create();
            tr.Update("refs/heads/master", first);
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
            FileUtils.Delete(new FilePath(repo.Directory, "logs/HEAD"), FileUtils.RETRY | FileUtils
                             .SKIP_MISSING);
            FileUtils.Delete(new FilePath(repo.Directory, "logs/refs/heads/master"), FileUtils
                             .RETRY | FileUtils.SKIP_MISSING);
            gc.Gc();
            stats = gc.GetStatistics();
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
            NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
            NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
        }
Esempio n. 8
0
        public virtual void TestExclude()
        {
            FileRepository repo = CreateBareRepository();
            TestRepository <FileRepository> testRepo = new TestRepository <FileRepository>(repo
                                                                                           );
            BranchBuilder bb       = testRepo.Branch("refs/heads/master");
            RevBlob       contentA = testRepo.Blob("A");
            RevCommit     c1       = bb.Commit().Add("f", contentA).Create();

            testRepo.GetRevWalk().ParseHeaders(c1);
            PackIndex pf1 = WritePack(repo, Sharpen.Collections.Singleton(c1), Sharpen.Collections
                                      .EmptySet <PackIndex>());

            AssertContent(pf1, Arrays.AsList(c1.Id, c1.Tree.Id, contentA.Id));
            RevBlob   contentB = testRepo.Blob("B");
            RevCommit c2       = bb.Commit().Add("f", contentB).Create();

            testRepo.GetRevWalk().ParseHeaders(c2);
            PackIndex pf2 = WritePack(repo, Sharpen.Collections.Singleton(c2), Sharpen.Collections
                                      .Singleton(pf1));

            AssertContent(pf2, Arrays.AsList(c2.Id, c2.Tree.Id, contentB.Id));
        }