public static bool TryReadParent(Stream stream, out GitObjectId parent) { // Format: "parent ef079ebcca375f6fd54aa0cb9f35e3ecc2bb66e7\n" parent = GitObjectId.Empty; Span <byte> line = stackalloc byte[ParentLineLength]; if (stream.Read(line) != ParentLineLength) { return(false); } if (!line.Slice(0, ParentStart.Length).SequenceEqual(ParentStart)) { return(false); } if (line[ParentLineLength - 1] != (byte)'\n') { return(false); } parent = GitObjectId.ParseHex(line.Slice(ParentStart.Length, 40)); return(true); }
public GitObjectId ResolveReference(string reference) { using (var stream = File.OpenRead(Path.Combine(this.GitDirectory, reference))) { Span <byte> objectId = stackalloc byte[40]; stream.Read(objectId); return(GitObjectId.ParseHex(objectId)); } }
public static GitObjectId ReadTree(Stream stream) { // Format: tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579\n // 47 bytes: // tree: 5 bytes // space: 1 byte // hash: 40 bytes // \n: 1 byte Span <byte> line = stackalloc byte[TreeLineLength]; stream.Read(line); Debug.Assert(line.Slice(0, TreeStart.Length).SequenceEqual(TreeStart)); Debug.Assert(line[TreeLineLength - 1] == (byte)'\n'); return(GitObjectId.ParseHex(line.Slice(TreeStart.Length, 40))); }