Пример #1
0
        /// <inheritdoc />
        public override int ReadPrefix(string shortSha, out LibGit2Sharp.ObjectId oid, out UnmanagedMemoryStream data, out ObjectType objectType)
        {
            var lastItem = _lastItem; // Thread safety

            if (lastItem?.Sha.StartsWith(shortSha, StringComparison.OrdinalIgnoreCase) ?? false)
            {
                oid        = new LibGit2Sharp.ObjectId(lastItem.Sha);
                data       = AllocateAndBuildFrom(lastItem.Data);
                objectType = lastItem.ObjectType;
                return((int)ReturnCode.GIT_OK);
            }

            var entries = _database.FileStorage.Find(shortSha).ToList();

            if (entries.Count == 1)
            {
                ExtractData(entries[0], out oid, out data, out objectType);
                return((int)ReturnCode.GIT_OK);
            }
            else
            {
                oid        = default;
                data       = default;
                objectType = default;
                return((int)(entries.Count == 0 ? ReturnCode.GIT_ENOTFOUND : ReturnCode.GIT_EAMBIGUOUS));
            }
        }
Пример #2
0
 private static void ExtractData(LiteFileInfo file, out LibGit2Sharp.ObjectId oid, out int length, out ObjectType objectType)
 {
     using (var reader = new BinaryReader(file.OpenRead()))
     {
         oid        = new LibGit2Sharp.ObjectId(reader.ReadString());
         objectType = (ObjectType)reader.ReadInt32();
         length     = reader.ReadInt32();
     }
 }
Пример #3
0
 private static void WriteData(LibGit2Sharp.ObjectId id, ObjectType objectType, byte[] data, LiteFileStream stream)
 {
     using (var writer = new BinaryWriter(stream, Encoding.Default, leaveOpen: true))
     {
         writer.Write(id.Sha);
         writer.Write((int)objectType);
         writer.Write(data.Length);
         writer.Write(data);
     }
 }
Пример #4
0
        /// <inheritdoc />
        public override int Write(LibGit2Sharp.ObjectId id, Stream dataStream, long length, ObjectType objectType)
        {
            var data = (byte[])Array.CreateInstance(typeof(byte), length);

            dataStream.Read(data, 0, (int)length);

            using (var stream = _database.FileStorage.OpenWrite(id.Sha, null))
            {
                WriteData(id, objectType, data, stream);

                _lastItem = new StoreItem(id.Sha, objectType, data);
            }
            return((int)ReturnCode.GIT_OK);
        }
Пример #5
0
        private void ExtractData(LiteFileInfo file, out LibGit2Sharp.ObjectId oid, out UnmanagedMemoryStream data, out ObjectType objectType)
        {
            using (var reader = new BinaryReader(file.OpenRead()))
            {
                oid        = new LibGit2Sharp.ObjectId(reader.ReadString());
                objectType = (ObjectType)reader.ReadInt32();
                var length = reader.ReadInt32();
                var bytes  = reader.ReadBytes(length);
                data = AllocateAndBuildFrom(bytes);

                // Update last item
                _lastItem = new StoreItem(oid.Sha, objectType, bytes);
            }
        }
Пример #6
0
        /// <inheritdoc />
        public override int ReadStream(LibGit2Sharp.ObjectId id, out OdbBackendStream stream)
        {
            var lastItem = _lastItem; // Thread safety

            if (lastItem?.Sha.Equals(id.Sha, StringComparison.OrdinalIgnoreCase) ?? false)
            {
                stream = new LiteDbOdbBackendStream(this, new MemoryStream(lastItem.Data));
                return((int)ReturnCode.GIT_OK);
            }
            var entry = _database.FileStorage.FindById(id.Sha);

            if (entry != null)
            {
                stream = new LiteDbOdbBackendStream(this, entry.OpenRead());
                return((int)ReturnCode.GIT_OK);
            }
            else
            {
                stream = default;
                return((int)ReturnCode.GIT_ENOTFOUND);
            }
        }
Пример #7
0
        /// <inheritdoc />
        public override int ExistsPrefix(string shortSha, out LibGit2Sharp.ObjectId found)
        {
            var lastItem = _lastItem; // Thread safety

            if (lastItem?.Sha.StartsWith(shortSha, StringComparison.OrdinalIgnoreCase) ?? false)
            {
                found = new LibGit2Sharp.ObjectId(lastItem.Sha);
                return((int)ReturnCode.GIT_OK);
            }

            var entries = _database.FileStorage.Find(shortSha).ToList();

            if (entries.Count == 1)
            {
                ExtractData(entries[0], out found, out int _, out var __);
                return((int)ReturnCode.GIT_OK);
            }
            else
            {
                found = default;
                return((int)(entries.Count == 0 ? ReturnCode.GIT_ENOTFOUND : ReturnCode.GIT_EAMBIGUOUS));
            }
        }
Пример #8
0
        /// <inheritdoc />
        public override int Read(LibGit2Sharp.ObjectId id, out UnmanagedMemoryStream data, out ObjectType objectType)
        {
            var lastItem = _lastItem; // Thread safety

            if (lastItem?.Sha.Equals(id.Sha, StringComparison.OrdinalIgnoreCase) ?? false)
            {
                data       = AllocateAndBuildFrom(lastItem.Data);
                objectType = lastItem.ObjectType;
                return((int)ReturnCode.GIT_OK);
            }
            var entry = _database.FileStorage.FindById(id.Sha);

            if (entry != null)
            {
                ExtractData(entry, out var _, out data, out objectType);
                return((int)ReturnCode.GIT_OK);
            }
            else
            {
                data       = default;
                objectType = default;
                return((int)ReturnCode.GIT_ENOTFOUND);
            }
        }
Пример #9
0
        /// <inheritdoc />
        public override int ReadHeader(LibGit2Sharp.ObjectId id, out int length, out ObjectType objectType)
        {
            var lastItem = _lastItem; // Thread safety

            if (lastItem?.Sha.Equals(id.Sha, StringComparison.OrdinalIgnoreCase) ?? false)
            {
                length     = lastItem.Data.Length;
                objectType = lastItem.ObjectType;
                return((int)ReturnCode.GIT_OK);
            }
            var entry = _database.FileStorage.FindById(id.Sha);

            if (entry != null)
            {
                ExtractData(entry, out var _, out length, out objectType);
                return((int)ReturnCode.GIT_OK);
            }
            else
            {
                length     = default;
                objectType = default;
                return((int)ReturnCode.GIT_ENOTFOUND);
            }
        }
Пример #10
0
 public void SetRepositoryData(GitObjectDb.Git.RepositoryDescription repositoryDescription, LibGit2Sharp.ObjectId commitId)
 {
     RepositoryDescription = repositoryDescription ?? throw new ArgumentNullException(nameof(repositoryDescription));
     CommitId = commitId ?? throw new ArgumentNullException(nameof(commitId));
 }
 public override int FinalizeWrite(LibGit2Sharp.ObjectId id)
 {
     _stream.Seek(0L, SeekOrigin.Begin);
     return(Backend.Write(id, _stream, _length, _objectType));
 }
Пример #12
0
 /// <inheritdoc />
 public override bool Exists(LibGit2Sharp.ObjectId id) =>
 (_lastItem?.Sha.Equals(id.Sha, StringComparison.OrdinalIgnoreCase) ?? false) ||
 _database.FileStorage.Exists(id.Sha);
Пример #13
0
 internal Stash(Repository repo, ObjectId targetId, int index)
     : base(repo, new DirectReference(string.Format("stash@{{{0}}}", index), repo, targetId), r => r.CanonicalName)
 {
 }
Пример #14
0
        /// <summary>
        /// Retrieves the header of a GitObject from the object database. The header contains the Size
        /// and Type of the object. Note that most backends do not support reading only the header
        /// of an object, so the whole object will be read and then size would be returned.
        /// </summary>
        /// <param name="objectId">Object Id of the queried object</param>
        /// <returns>GitObjectMetadata object instance containg object header information</returns>
        public virtual GitObjectMetadata RetrieveObjectMetadata(ObjectId objectId)
        {
            Ensure.ArgumentNotNull(objectId, "objectId");

            return(Proxy.git_odb_read_header(handle, objectId));
        }
Пример #15
0
        /// <summary>
        /// Determines if the given object can be found in the object database.
        /// </summary>
        /// <param name="objectId">Identifier of the object being searched for.</param>
        /// <returns>True if the object has been found; false otherwise.</returns>
        public virtual bool Contains(ObjectId objectId)
        {
            Ensure.ArgumentNotNull(objectId, "objectId");

            return(Proxy.git_odb_exists(handle, objectId));
        }
Пример #16
0
 internal TagAnnotation(ObjectId id)
     : base(id)
 {
 }