Пример #1
0
 internal static Commit Read(RepositoryReader reader, string hash, Stream stream)
 {
     using (var streamReader = new StreamReader(stream, Encoding.UTF8))
     {
         var line = streamReader.ReadLine();
         var tree = StringUtils.ReadSingleValue(line, "tree ", throwIfMissing: true);
         line = streamReader.ReadLine();
         var    parents = new List <string>();
         string parent;
         while ((parent = StringUtils.ReadSingleValue(line, "parent ", throwIfMissing: false)) != null)
         {
             parents.Add(parent);
             line = streamReader.ReadLine();
         }
         var author = StringUtils.ReadSingleValue(line, "author ", throwIfMissing: true);
         line = streamReader.ReadLine();
         var committer = StringUtils.ReadSingleValue(line, "committer ", throwIfMissing: true);
         streamReader.ReadLine();
         var message = streamReader.ReadToEnd().Trim();
         return(new Commit(
                    hash,
                    new Lazy <TreeCollection>(() => reader.Read <TreeCollection>(tree)),
                    new Lazy <IImmutableList <Commit> >(() => parents.Select(p => reader.Read <Commit>(p)).ToImmutableList()),
                    ParseSignature(author),
                    ParseSignature(committer), message));
     }
 }
Пример #2
0
        internal static TreeCollection Read(RepositoryReader reader, string hash, Stream stream, long length)
        {
            var entries = ImmutableList.CreateBuilder <Lazy <TreeEntry> >();

            while (length > 0)
            {
                var mode = stream.ReadUpTo(' ');
                var name = stream.ReadUpTo('\0');
                length -= mode.Length + 1 + name.Length + 1;
                var buffer = new byte[20];
                stream.Read(buffer, 0, 20);
                var childHash = string.Concat(buffer.Select(x => x.ToString("x2")));
                length -= 20;
                entries.Add(new Lazy <TreeEntry>(() =>
                {
                    var entry = reader.Read <Entry>(childHash);
                    return(new TreeEntry(name, entry, int.Parse(mode, CultureInfo.InvariantCulture)));
                }));
            }
            return(new TreeCollection(hash, entries.ToImmutable()));
        }