示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Initializes the <see cref="IDocumentStore" />.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">You must specify a valid Path</exception>
        public IDocumentStore Initialize()
        {
            if (this.Path == null)
                throw new InvalidOperationException("You must specify a valid Path");

            string gitDirectory = System.IO.Path.Combine(this.Path, ".git");

            if (!Directory.Exists(gitDirectory))
                Directory.CreateDirectory(gitDirectory);

            var location = Helper.MakeAbsolutePath(gitDirectory);


            _objectStorage = new ObjectStorage(location);
            _refStorage = new RefStorage(location);
            return this;
        }