public static async ValueTask <GitId> ReadGitIdAsync(this Bucket bucket, GitIdType type) { if (bucket is null) { throw new ArgumentNullException(nameof(bucket)); } int hl = type.HashLength(); var bb = await bucket.ReadFullAsync(hl).ConfigureAwait(false); if (bb.Length == hl) { return(new GitId(type, bb.ToArray())); } else { throw new BucketEofException(bucket); } }
protected override async ValueTask InitAsync() { await base.InitAsync().ConfigureAwait(false); _haveV2 = GetChunkLength("GDA2").HasValue; if (_baseCommitGraphs > 0) { byte[] baseGraphs = new byte[_baseCommitGraphs * IdType.HashLength()]; if (baseGraphs.Length != await ReadFromChunkAsync("BASE", 0, baseGraphs).ConfigureAwait(false)) { throw new GitException($"Can't read commit-graph base chunks from {ChunkReader} Bucket"); } GitId parentId = GitId.FromByteArrayOffset(IdType, baseGraphs, (_baseCommitGraphs - 1) * IdType.HashLength()); ParentGraph = _graphRoot !.GetCommitGraph(parentId); } }
private bool TryFindId(byte[] oids, GitId oid, out uint index) { int sz; if (oids.Length == 0) { index = 0; return(false); } if (_ver == 2) { sz = _idType.HashLength(); } else if (_ver == 1) { sz = _idType.HashLength() + 4; } else { index = 0; return(false); } int first = 0, count = oids.Length / sz; int c = count; if (c == 0) { index = 0; return(false); } while (first + 1 < c) { int mid = first + (c - first) / 2; var check = GitId.FromByteArrayOffset(_idType, oids, sz * mid); int n = oid.CompareTo(check); if (n == 0) { index = (uint)mid; return(true); } else if (n < 0) { c = mid; } else { first = mid + 1; } } if (first >= count) { index = (uint)count; return(false); } var check2 = GitId.FromByteArrayOffset(_idType, oids, sz * first); index = (uint)first; c = oid.CompareTo(check2); if (c == 0) { return(true); } else if (c > 0) { index++; } return(false); }