コード例 #1
0
        public Stream GetObject(long offset, string objectType)
        {
            if (!histogram.TryAdd(offset, 1))
            {
                histogram[offset] += 1;
            }

            if (this.cache.TryOpen(offset, out Stream stream))
            {
                return(stream);
            }

            GitPackObjectType packObjectType;

            switch (objectType)
            {
            case "commit":
                packObjectType = GitPackObjectType.OBJ_COMMIT;
                break;

            case "tree":
                packObjectType = GitPackObjectType.OBJ_TREE;
                break;

            case "blob":
                packObjectType = GitPackObjectType.OBJ_BLOB;
                break;

            default:
                throw new GitException();
            }

            var    packStream   = this.GetPackStream();
            Stream objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType);

            return(this.cache.Add(offset, objectStream));
        }
コード例 #2
0
        public Stream GetObject(int offset, string objectType)
        {
            if (!histogram.TryAdd(offset, 1))
            {
                histogram[offset] += 1;
            }

            if (this.cache.TryOpen(offset, out Stream stream))
            {
                return(stream);
            }

            GitPackObjectType packObjectType;

            switch (objectType)
            {
            case "commit":
                packObjectType = GitPackObjectType.OBJ_COMMIT;
                break;

            case "tree":
                packObjectType = GitPackObjectType.OBJ_TREE;
                break;

            case "blob":
                packObjectType = GitPackObjectType.OBJ_BLOB;
                break;

            default:
                throw new GitException();
            }

            Stream packStream   = File.OpenRead(Path.Combine(this.repository.ObjectDirectory, "pack", $"{this.name}.pack"));
            Stream objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType);

            return(this.cache.Add(offset, objectStream));
        }