Example #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());
            }
        }
Example #2
0
        /// <summary>Returns the number of objects stored in pack files.</summary>
        /// <remarks>
        /// Returns the number of objects stored in pack files. If an object is
        /// contained in multiple pack files it is counted as often as it occurs.
        /// </remarks>
        /// <returns>the number of objects stored in pack files</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual GC.RepoStatistics GetStatistics()
        {
            GC.RepoStatistics      ret   = new GC.RepoStatistics(this);
            ICollection <PackFile> packs = ((ObjectDirectory)repo.ObjectDatabase).GetPacks();

            foreach (PackFile f in packs)
            {
                ret.numberOfPackedObjects += f.GetIndex().GetObjectCount();
                ret.numberOfPackFiles++;
                ret.sizeOfPackedObjects += f.GetPackFile().Length();
            }
            FilePath objDir = repo.ObjectsDirectory;

            string[] fanout = objDir.List();
            if (fanout != null && fanout.Length > 0)
            {
                foreach (string d in fanout)
                {
                    if (d.Length != 2)
                    {
                        continue;
                    }
                    FilePath[] entries = new FilePath(objDir, d).ListFiles();
                    if (entries == null)
                    {
                        continue;
                    }
                    foreach (FilePath f_1 in entries)
                    {
                        if (f_1.GetName().Length != Constants.OBJECT_ID_STRING_LENGTH - 2)
                        {
                            continue;
                        }
                        ret.numberOfLooseObjects++;
                        ret.sizeOfLooseObjects += f_1.Length();
                    }
                }
            }
            RefDatabase refDb = repo.RefDatabase;

            foreach (Ref r in refDb.GetRefs(RefDatabase.ALL).Values)
            {
                RefStorage storage = r.GetStorage();
                if (storage == RefStorage.LOOSE || storage == RefStorage.LOOSE_PACKED)
                {
                    ret.numberOfLooseRefs++;
                }
                if (storage == RefStorage.PACKED || storage == RefStorage.LOOSE_PACKED)
                {
                    ret.numberOfPackedRefs++;
                }
            }
            return(ret);
        }
Example #3
0
 public virtual void TestPackRepoWithNoRefs()
 {
     tr.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);
     gc.Gc();
     stats = gc.GetStatistics();
     NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
     NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
     NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackFiles);
 }
Example #4
0
 public virtual void TestPackAllObjectsInOnePack()
 {
     tr.Branch("refs/heads/master").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);
     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);
 }
Example #5
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());
                }
            }
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }