コード例 #1
0
        protected GitObjectBase(ObjectHash hash, GitObjectType type)
        {
            Hash = hash;
            Type = type;

            _hashCode = hash.GetHashCode();
        }
コード例 #2
0
        public Tag(ObjectHash hash, Memory<byte> content) : base(hash, GitObjectType.Tag)
        {
            _content = content;

            var nextNewLine = content.Span.IndexOf<byte>(10);
            while (nextNewLine != -1)
            {
                var contentSpan = content.Span;
                if (contentSpan.StartsWith(ObjectPrefixes.ObjectPrefix))
                {
                    _object = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.TypePrefix))
                {
                    _type = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.TagPrefix))
                {
                    _tag = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.TaggerPrefix))
                {
                    _tagger = content.Slice(0, nextNewLine);
                }
                else
                {
                    _message = content;
                    break;
                }

                content = content.Slice(nextNewLine + 1);
                nextNewLine = content.Span.IndexOf<byte>(10);
            }
        }
コード例 #3
0
ファイル: Tree.cs プロジェクト: twwilliams/GitRewrite
            public TreeLine(ReadOnlyMemory <byte> text, ObjectHash hash)
            {
                TextBytes = text;
                Hash      = hash;

                FileNameBytes = TextBytes.Slice(TextBytes.Span.IndexOf((byte)' ') + 1);
            }
コード例 #4
0
        public Commit(ObjectHash hash, byte[] bytes) : base(hash, GitObjectType.Commit)
        {
            _content = bytes;
            var content = bytes.AsMemory();

            _parents = new List <ObjectHash>();

            var nextNewLine = content.Span.IndexOf((byte)'\n');

            while (nextNewLine != -1)
            {
                var contentSpan = content.Span;
                if (contentSpan.StartsWith(ObjectPrefixes.TreePrefix))
                {
                    _treeHash = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.ParentPrefix))
                {
                    _parents.Add(new ObjectHash(content.Span.Slice(7, nextNewLine - 7)));
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.AuthorPrefix))
                {
                    _authorLine = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.CommitterPrefix))
                {
                    _committerLine = content.Slice(0, nextNewLine);
                }
                else if (contentSpan.StartsWith(ObjectPrefixes.GpgSigPrefix))
                {
                    // gpgsig are not really handled, instead a gpgsig is not written back when rewriting the object
                    var pgpSignatureEnd = content.Span.IndexOf(PgpSignatureEnd);
                    content     = content.Slice(pgpSignatureEnd + PgpSignatureEnd.Length + 1);
                    nextNewLine = content.Span.IndexOf((byte)'\n');
                }
                else
                {
                    // We view everything that is not defined above as commit message
                    _commitMessage = content;
                    break;
                }

                content     = content.Slice(nextNewLine + 1);
                nextNewLine = content.Span.IndexOf((byte)'\n');
            }
        }
コード例 #5
0
ファイル: Tree.cs プロジェクト: twwilliams/GitRewrite
        public Tree(ObjectHash hash, ReadOnlyMemory <byte> bytes) : base(hash, GitObjectType.Tree)
        {
            var nullTerminatorIndex = bytes.Span.IndexOf((byte)'\0');

            var lines = new List <TreeLine>();

            while (nullTerminatorIndex > 0)
            {
                var textSpan = bytes.Slice(0, nullTerminatorIndex);

                var lineHashInBytes = bytes.Slice(nullTerminatorIndex + 1, 20);

                var objectHash = new ObjectHash(lineHashInBytes.ToArray());

                lines.Add(new TreeLine(textSpan, objectHash));

                bytes = bytes.Slice(nullTerminatorIndex + 21);

                nullTerminatorIndex = bytes.Span.IndexOf((byte)'\0');
            }

            Lines = lines;
        }
コード例 #6
0
ファイル: Blob.cs プロジェクト: twwilliams/GitRewrite
 public Blob(ObjectHash hash, in ReadOnlyMemory <byte> plainContent) : base(hash, GitObjectType.Blob) => _content = plainContent;