internal Tree(ObjectStorage storage ,string id, long size, Func<byte[]> loader, Tree parent = null, string name = null, string mode = null) : base(id, parent, name, mode) { this.Size = size; this._storage = storage; this._loader = loader.Try(n => new Lazy<byte[]>(loader)); }
internal TreeEntry(string id, Tree parent, string name, string mode) : base(id) { this.Parent = parent; this.Name = name; this.Mode = mode; }
internal Blob(string id, long size, Func<byte[]> loader, Tree parent = null, string name = null, string mode = null) : base(id, parent, name, mode) { _loader = new Lazy<byte[]>(loader); this.Size = size; }
private static IEnumerable<TreeEntry> RecursiveTreeEnumerator(Tree tree) { var stack = new Stack<IEnumerator<TreeEntry>>(); stack.Push(tree.Items.GetEnumerator()); do { var enumerator = stack.Pop(); while (enumerator.MoveNext()) { if (enumerator.Current.Type == ObjectType.Tree) { stack.Push(enumerator); enumerator = ((Tree) enumerator.Current).Items.GetEnumerator(); } else { yield return enumerator.Current; } } } while (stack.Count > 0); }
private void EnsureLoaded() { if (_loaded) return; this._reader.Load(stream => { var bytesRead = 0; var reader = new StreamReader(stream); string line; while (!string.IsNullOrEmpty(line = reader.ReadLine())) { bytesRead += line.Length + 1; //add 1 for LF var parts = line.Split(new[] {' '}, 2); switch (parts[0]) { case "tree": this._tree = _storage.Read<Tree>(parts[1]); break; case "author": this._author = parts[1]; break; case "committer": this._commiter = parts[1]; break; case "parent": var parent = _storage.Read<Commit>(parts[1]); if(parent != null) this._parents.Add(parent); break; default: throw new NotSupportedException(string.Format("{0} is not a supported commit field.", parts[0])); } } var messageSize = this._reader.Size - bytesRead; var buffer = new char[messageSize]; var read = reader.Read(buffer, 0, buffer.Length); this._message = new string(buffer, 0, read); }); this._loaded = true; }