private GitObjectId ResolveReference(object reference)
        {
            if (reference is string)
            {
                if (!FileHelpers.TryOpen(Path.Combine(this.CommonDirectory, (string)reference), out FileStream? stream))
                {
                    return(GitObjectId.Empty);
                }

                using (stream)
                {
                    Span <byte> objectId = stackalloc byte[40];
                    stream !.Read(objectId);

                    return(GitObjectId.ParseHex(objectId));
                }
            }
            else if (reference is GitObjectId)
            {
                return((GitObjectId)reference);
            }
            else
            {
                throw new GitException();
            }
        }
        private static GitObjectId ReadTree(ReadOnlySpan <byte> line)
        {
            // Format: tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579\n
            // 47 bytes:
            //  tree: 5 bytes
            //  space: 1 byte
            //  hash: 40 bytes
            //  \n: 1 byte
            Debug.Assert(line.Slice(0, TreeStart.Length).SequenceEqual(TreeStart));
            Debug.Assert(line[TreeLineLength - 1] == (byte)'\n');

            return(GitObjectId.ParseHex(line.Slice(TreeStart.Length, 40)));
        }
        private static bool TryReadParent(ReadOnlySpan <byte> line, out GitObjectId parent)
        {
            // Format: "parent ef079ebcca375f6fd54aa0cb9f35e3ecc2bb66e7\n"
            parent = GitObjectId.Empty;

            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);
        }
示例#4
0
        public static object ReadReference(Span <byte> value)
        {
            if (value.Length == 41 && !value.StartsWith(RefPrefix))
            {
                // Skip the trailing \n
                return(GitObjectId.ParseHex(value.Slice(0, 40)));
            }
            else
            {
                if (!value.StartsWith(RefPrefix))
                {
                    throw new GitException();
                }

                // Skip the terminating \n character
                return(GitRepository.GetString(value.Slice(RefPrefix.Length, value.Length - RefPrefix.Length - 1)));
            }
        }