コード例 #1
0
        public async ValueTask <GitSignatureRecord> ReadTaggerAsync()
        {
            if (_author is null)
            {
                if (_tagName is null)
                {
                    await ReadTagNameAsync().ConfigureAwait(false);
                }

                var(bb, eol) = await Inner.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);

                if (bb.StartsWithASCII("tagger ") &&
                    GitSignatureRecord.TryReadFromBucket(bb.Slice("tagger ".Length, eol), out var author))
                {
                    _author = author;
                }
                else if (bb.IsEmpty(eol))
                {
                    _author = new GitSignatureRecord()
                    {
                        When = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)
                    };
                    _readHeaders = true;
                    // Special case. Bad commit in linux repository doesn't have a tagger
                }
                else
                {
                    throw new GitBucketException($"Expected 'tagger' in tag in '{Inner.Name}'");
                }
            }

            return(_author);
        }
コード例 #2
0
        public void CheckSignatureLines()
        {
            {
                GitSignatureRecord sig = new GitSignatureRecord {
                    Name = "User", Email = "u@m", When = new DateTime(2002, 12, 5, 5, 6, 7, DateTimeKind.Utc)
                };

                Assert.AreEqual("User <u@m> 1039064767 +0000", sig.ToString());
                Assert.IsTrue(GitSignatureRecord.TryReadFromBucket(Encoding.UTF8.GetBytes(sig.ToString()), out var utcStartRb), "Can read record");
                Assert.AreEqual(sig, utcStartRb);
            }

            {
                GitSignatureRecord sig = new GitSignatureRecord {
                    Name = "EU User", Email = "nl@eu", When = new DateTimeOffset(2003, 05, 27, 3, 3, 3, new TimeSpan(2, 0, 0))
                };

                Assert.AreEqual("EU User <nl@eu> 1053997383 +0200", sig.ToString());
                Assert.IsTrue(GitSignatureRecord.TryReadFromBucket(Encoding.UTF8.GetBytes(sig.ToString()), out var cestStartRb), "Can read record");
                Assert.AreEqual(sig, cestStartRb);
            }


            {
                GitSignatureRecord sig = new GitSignatureRecord {
                    Name = "India User ", Email = "india@in", When = new DateTimeOffset(2004, 04, 02, 3, 3, 3, new TimeSpan(5, 30, 0))
                };

                Assert.AreEqual("India User  <india@in> 1080855183 +0530", sig.ToString());
                Assert.IsTrue(GitSignatureRecord.TryReadFromBucket(Encoding.UTF8.GetBytes(sig.ToString()), out var cestStartRb), "Can read record");
                Assert.AreEqual(sig, cestStartRb);
            }

            {
                GitSignatureRecord sig = new GitSignatureRecord {
                    Name = "NegIndia User ", Email = "net-india@ni", When = new DateTimeOffset(2004, 04, 02, 3, 3, 3, -new TimeSpan(5, 30, 0))
                };

                Assert.AreEqual("NegIndia User  <net-india@ni> 1080894783 -0530", sig.ToString());
                Assert.IsTrue(GitSignatureRecord.TryReadFromBucket(Encoding.UTF8.GetBytes(sig.ToString()), out var cestStartRb), "Can read record");
                Assert.AreEqual(sig, cestStartRb);
            }

            {
                GitSignatureRecord sig = new GitSignatureRecord {
                    Name = " US User ", Email = " us@white space ", When = new DateTimeOffset(2003, 05, 27, 3, 3, 3, new TimeSpan(-6, 0, 0))
                };

                Assert.AreEqual(" US User  < us@white space > 1054026183 -0600", sig.ToString());
                Assert.IsTrue(GitSignatureRecord.TryReadFromBucket(Encoding.UTF8.GetBytes(sig.ToString()), out var cestStartRb), "Can read record");
                Assert.AreEqual(sig, cestStartRb);
            }
        }
コード例 #3
0
        public async ValueTask <GitId?> ReadFirstParentIdAsync()
        {
            if (_parents is not null)
            {
                return(_parents.First());
            }
            else if (_treeId is null)
            {
                await ReadTreeIdAsync().ConfigureAwait(false);
            }

            // Typically every commit has a parent, so optimize for that case
            var(bb, eol) = await Inner.ReadUntilEolFullAsync(AcceptedEols, requested : ParentLineReadLength).ConfigureAwait(false);

            if (bb.IsEof || eol == BucketEol.None || !bb.StartsWithASCII("parent "))
            {
                if (bb.IsEof || !bb.StartsWithASCII("author "))
                {
                    throw new GitBucketException($"Expected 'parent' or 'author', but got neither in commit {Name} Bucket");
                }

                _parents = Array.Empty <GitId>();

                // We accidentally read the first part of the author line. Let's keep things clean

                if (eol == BucketEol.None)
                {
                    var authorBucket = (bb.Slice("author ".Length).ToArray().AsBucket() + Inner);
                    (bb, eol) = await authorBucket.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);
                }

                _author = GitSignatureRecord.TryReadFromBucket(bb.Slice(eol), out var author) ? author : throw new GitBucketException($"Invalid author line in {Name} Bucket");
                return(null);
            }
            else if (GitId.TryParse(bb.Slice("parent ".Length, eol), out var id))
            {
                _parents = new List <GitId>()
                {
                    id
                };
                return(id);
            }
            else
            {
                throw new GitBucketException($"Invalid parent line in '{Inner.Name}");
            }
        }
コード例 #4
0
        public async ValueTask <GitSignatureRecord> ReadCommitterAsync()
        {
            if (_committer is not null)
            {
                return(_committer);
            }
            else if (_author is null)
            {
                await ReadAuthorAsync().ConfigureAwait(false);
            }

            var(bb, eol) = await Inner.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);

            if (bb.IsEof ||
                eol == BucketEol.None ||
                !bb.StartsWithASCII("committer ") ||
                !GitSignatureRecord.TryReadFromBucket(bb.Slice("committer ".Length, eol), out var cm))
            {
                throw new GitBucketException($"Unable to read committer header from '{Inner.Name}'");
            }

            return(_committer = cm);
        }
コード例 #5
0
        public async ValueTask <GitSignatureRecord> ReadAuthorAsync()
        {
            if (_author is null)
            {
                if (_parents is null || _parents is List <GitId> )
                {
                    await ReadAllParentIdsAsync().ConfigureAwait(false);
                }

                var(bb, eol) = await Inner.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);

                if (bb.StartsWithASCII("author ") &&
                    GitSignatureRecord.TryReadFromBucket(bb.Slice("author ".Length, eol), out var author))
                {
                    _author = author;
                }
                else
                {
                    throw new GitBucketException($"Expected 'author' in commit '{Inner.Name}'");
                }
            }

            return(_author ?? throw new GitBucketException($"Unable to read author header from '{Inner.Name}'"));
        }
コード例 #6
0
        public async ValueTask <IReadOnlyCollection <GitId> > ReadAllParentIdsAsync()
        {
            List <GitId> parents;

            if (_parents is not null)
            {
                if (_parents is not List <GitId> lst)
                {
                    return(_parents); // Already done
                }
                parents = lst;        // Still collecting after ReadFirstParentIdAsync()
            }
            else if (_treeId is null)
            {
                await ReadTreeIdAsync().ConfigureAwait(false);

                parents = new();
            }
            else
            {
                parents = new();
            }

            while (true)
            {
                var(bb, eol) = await Inner.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);

                if (bb.IsEof)
                {
                    return(_parents = parents.Count > 0 ? parents.AsReadOnly() : Array.Empty <GitId>());
                }
                else if (bb.StartsWithASCII("parent ") &&
                         GitId.TryParse(bb.Slice("parent ".Length, eol), out var id))
                {
                    parents.Add(id);

                    // Stop scanning if we don't have more parents
                    bb = Inner.Peek();
                    if (!bb.IsEmpty && bb[0] != 'p')
                    {
                        return(_parents = parents.AsReadOnly());
                    }

                    continue;
                }
                else if (bb.StartsWithASCII("author "))
                {
                    // Auch. We overread.
                    if (eol == BucketEol.None)
                    {
                        var authorBucket = (bb.Slice("author ".Length).ToArray().AsBucket() + Inner);
                        (bb, eol) = await authorBucket.ReadUntilEolFullAsync(AcceptedEols, requested : MaxHeader).ConfigureAwait(false);
                    }

                    _author = GitSignatureRecord.TryReadFromBucket(bb.Slice(eol), out var author) ? author : throw new GitBucketException($"Invalid author line in {Name} Bucket");
                    return(_parents = parents.AsReadOnly());
                }
                else
                {
                    throw new GitBucketException($"Expected 'parent' or 'author', but got neither in commit '{Inner.Name}'");
                }
            }
        }
コード例 #7
0
ファイル: GitSignature.cs プロジェクト: AmpScm/AmpScm
 internal GitSignature(GitSignatureRecord signature)
 {
     _name  = signature.Name;
     _email = signature.Email;
     _when  = signature.When;
 }