From c2f6e5e438f8782caba2046c74e2107108ae78c8 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Fri, 26 Oct 2012 23:06:35 +0200 Subject: [PATCH 1/8] Spike - Group lazy loaded properties --- LibGit2Sharp/Core/LazyProperty.cs | 97 +++++++++++++++++++++++++++++++ LibGit2Sharp/Core/Proxy.cs | 7 ++- LibGit2Sharp/LibGit2Sharp.csproj | 2 + LibGit2Sharp/NewCommit.cs | 79 +++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 LibGit2Sharp/Core/LazyProperty.cs create mode 100644 LibGit2Sharp/NewCommit.cs diff --git a/LibGit2Sharp/Core/LazyProperty.cs b/LibGit2Sharp/Core/LazyProperty.cs new file mode 100644 index 000000000..8653b4170 --- /dev/null +++ b/LibGit2Sharp/Core/LazyProperty.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp.Core +{ + internal class LazyProperty : LazyPropertyBase + { + public LazyProperty(Func evaluator, LazyGroup lazyGroup) + : base(evaluator, lazyGroup) + { } + + public TType Value + { + get { return (TType)base.Value; } + } + } + + internal class LazyPropertyBase + { + private readonly Func evaluator; + private readonly LazyGroup lazyGroup; + + private object value; + private bool hasBeenEvaluated; + + public LazyPropertyBase(Func evaluator, LazyGroup lazyGroup) + { + this.evaluator = evaluator; + this.lazyGroup = lazyGroup; + } + + public object Value + { + get { return Evaluate(); } + } + + internal LazyGroup Group + { + get { return lazyGroup; } + } + + private object Evaluate() + { + if (!hasBeenEvaluated) + { + lock (Group) + { + if (!hasBeenEvaluated) + { + Group.TriggerEvaluation(); + } + } + } + + return value; + } + + internal void InternalEvaluate(GitObjectSafeHandle objectPtr) + { + hasBeenEvaluated = true; + value = evaluator(objectPtr); + } + } + + internal class LazyGroup + { + private readonly Repository repo; + private readonly ObjectId id; + + private readonly IList lazies = new List(); + + public LazyGroup(Repository repo, ObjectId id) + { + this.repo = repo; + this.id = id; + } + + public LazyProperty AddLazy(Func evaluator) + { + var lazy = new LazyProperty(evaluator, this); + lazies.Add(lazy); + return lazy; + } + + public void TriggerEvaluation() + { + using (var osw = new ObjectSafeWrapper(id, repo.Handle)) + { + foreach (var lazy in lazies) + { + lazy.InternalEvaluate(osw.ObjectPtr); + } + } + } + } +} \ No newline at end of file diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 823fca66d..988cbe645 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -257,7 +257,12 @@ public static int git_commit_parentcount(RepositorySafeHandle repo, ObjectId id) public static int git_commit_parentcount(ObjectSafeWrapper obj) { - return (int)NativeMethods.git_commit_parentcount(obj.ObjectPtr); + return git_commit_parentcount(obj.ObjectPtr); + } + + public static int git_commit_parentcount(GitObjectSafeHandle obj) + { + return (int)NativeMethods.git_commit_parentcount(obj); } public static ObjectId git_commit_tree_oid(GitObjectSafeHandle obj) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 8de2023b4..7703a6551 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -68,6 +68,8 @@ + + diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs new file mode 100644 index 000000000..c3d3d1493 --- /dev/null +++ b/LibGit2Sharp/NewCommit.cs @@ -0,0 +1,79 @@ +using System.Collections.Generic; +using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; +using LibGit2Sharp.Core.Handles; + +namespace LibGit2Sharp +{ + public class NewCommit : GitObject + { + private readonly Repository repo; + + private readonly LazyGroup group1; + private readonly LazyGroup group2; + + private readonly Lazy> parents; + private readonly LazyProperty _lazyMessage; + private readonly LazyProperty _lazyEncoding; + private readonly LazyProperty _lazyAuthor; + private readonly LazyProperty _lazyCommitter; + private readonly LazyProperty _lazyTreeId; + + protected NewCommit() + {} + + protected NewCommit(Repository repo, ObjectId id) + : base(id) + { + this.repo = repo; + group1 = new LazyGroup(repo, id); + group2 = new LazyGroup(repo, id); + + _lazyTreeId = group1.AddLazy(Proxy.git_commit_tree_oid); + _lazyAuthor = group1.AddLazy(Proxy.git_commit_author); + _lazyMessage = group1.AddLazy(Proxy.git_commit_message); + + _lazyEncoding = group2.AddLazy(RetrieveEncodingOf); + _lazyCommitter = group2.AddLazy(Proxy.git_commit_committer); + + parents = new Lazy>(() => RetrieveParentsOfCommit(id)); + } + + // Lazy batch loaded properies + private ObjectId TreeId { get { return _lazyTreeId.Value; } } + public Signature Author { get { return _lazyAuthor.Value; } } + public string Message { get { return _lazyMessage.Value; } } + + public string Encoding { get { return _lazyEncoding.Value; } } + public Signature Committer { get { return _lazyCommitter.Value; } } + + // On demand lazy loaded properties + public IEnumerable Parents { get { return parents.Value; } } + + // Other properties + public int ParentsCount { get { return Proxy.git_commit_parentcount(repo.Handle, Id); ; } } + + public Tree Tree { get { return repo.Lookup(TreeId); } } + + private static string RetrieveEncodingOf(GitObjectSafeHandle obj) + { + string encoding = Proxy.git_commit_message_encoding(obj); + + return encoding ?? "UTF-8"; + } + + private IEnumerable RetrieveParentsOfCommit(ObjectId oid) + { + using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) + { + int parentsCount = Proxy.git_commit_parentcount(obj); + + for (uint i = 0; i < parentsCount; i++) + { + ObjectId parentCommitId = Proxy.git_commit_parent_oid(obj.ObjectPtr, i); + yield return new NewCommit(repo, parentCommitId); + } + } + } + } +} From bd343d3c3ba3a6177b4cbb8e9454e819b95f75a4 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sat, 27 Oct 2012 21:03:29 +0200 Subject: [PATCH 2/8] How about dropping ParentCount and promoting Parents.Count()? Output from LibGit2Sharp.Tests.BranchFixture.Parents: Commits: 42000 Time: 2834 MaxParents: 8 Commits: 42000 Time: 3491 MaxParents: 8 --- LibGit2Sharp.Tests/BranchFixture.cs | 59 +++++++++++++++++++++++++++++ LibGit2Sharp/NewCommit.cs | 14 ++++--- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index 3f5321efe..7478c9577 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using LibGit2Sharp.Tests.TestHelpers; using Xunit; @@ -10,6 +12,63 @@ public class BranchFixture : BaseFixture { private readonly string[] expectedBranches = new[] { "br2", "master", "packed", "packed-test", "test", }; + [Fact] + public void Parents() + { + using (var repo = new Repository(@"D:\temp\linux\linux")) + { + int max = 42000; + var commits = new List(); + int iter = 0; + var s = new Stack(); + + var id = repo.Head.Tip.Id; + + s.Push(id); + + while (s.Count > 0 && iter < max) + { + var c = new NewCommit(repo, s.Pop()); + + var p = c.Parents.FirstOrDefault(); + s.Push(p.Id); + + commits.Add(new NewCommit(repo, c.Id)); + iter++; + } + + s.Clear(); + s = null; + + GC.Collect(); + + MaxNumberOfParents(commits, x => x.ParentsCount); + GC.Collect(); + + MaxNumberOfParents(commits, x => x.Parents.Count()); + } + } + + private void MaxNumberOfParents(List commits, Func parentCountEvaluator) + { + int maxP = -1; + + var sw = Stopwatch.StartNew(); + foreach (var newCommit in commits) + { + int count = parentCountEvaluator(newCommit); + if (maxP > count) + continue; + + maxP = count; + } + sw.Stop(); + + Console.WriteLine("Commits: {0}", commits.Count); + Console.WriteLine("Time: {0}", sw.ElapsedMilliseconds); + Console.WriteLine("MaxParents: {0}", maxP); + } + [Theory] [InlineData("unit_test")] [InlineData("Ångström")] diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs index c3d3d1493..19ea2d949 100644 --- a/LibGit2Sharp/NewCommit.cs +++ b/LibGit2Sharp/NewCommit.cs @@ -12,7 +12,7 @@ public class NewCommit : GitObject private readonly LazyGroup group1; private readonly LazyGroup group2; - private readonly Lazy> parents; + private readonly Lazy> parents; private readonly LazyProperty _lazyMessage; private readonly LazyProperty _lazyEncoding; private readonly LazyProperty _lazyAuthor; @@ -22,7 +22,7 @@ public class NewCommit : GitObject protected NewCommit() {} - protected NewCommit(Repository repo, ObjectId id) + public NewCommit(Repository repo, ObjectId id) : base(id) { this.repo = repo; @@ -36,7 +36,7 @@ protected NewCommit(Repository repo, ObjectId id) _lazyEncoding = group2.AddLazy(RetrieveEncodingOf); _lazyCommitter = group2.AddLazy(Proxy.git_commit_committer); - parents = new Lazy>(() => RetrieveParentsOfCommit(id)); + parents = new Lazy>(() => RetrieveParentsOfCommit(id)); } // Lazy batch loaded properies @@ -62,8 +62,10 @@ private static string RetrieveEncodingOf(GitObjectSafeHandle obj) return encoding ?? "UTF-8"; } - private IEnumerable RetrieveParentsOfCommit(ObjectId oid) + private IList RetrieveParentsOfCommit(ObjectId oid) { + var parents = new List(); + using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) { int parentsCount = Proxy.git_commit_parentcount(obj); @@ -71,9 +73,11 @@ private IEnumerable RetrieveParentsOfCommit(ObjectId oid) for (uint i = 0; i < parentsCount; i++) { ObjectId parentCommitId = Proxy.git_commit_parent_oid(obj.ObjectPtr, i); - yield return new NewCommit(repo, parentCommitId); + parents.Add(new NewCommit(repo, parentCommitId)); } } + + return parents; } } } From 49ec1811b8e476ff81c5ce7a121e09fcee79ac69 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 28 Oct 2012 08:07:02 +0100 Subject: [PATCH 3/8] Overkill? Output from LibGit2Sharp.Tests.BranchFixture.Parents: Commits: 42000 Time: 2358 MaxParents: 8 Commits: 42000 Time: 2389 MaxParents: 8 --- LibGit2Sharp/NewCommit.cs | 120 +++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 20 deletions(-) diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs index 19ea2d949..21bf77c89 100644 --- a/LibGit2Sharp/NewCommit.cs +++ b/LibGit2Sharp/NewCommit.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Collections.Generic; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Compat; @@ -5,6 +6,101 @@ namespace LibGit2Sharp { + internal class ParentsList : IList + { + private Lazy> parents; + private Lazy count; + public ParentsList(Repository repo, NewCommit c) + { + parents = new Lazy>(() => RetrieveParentsOfCommit(repo, c.Id)); + count = new Lazy(() => Proxy.git_commit_parentcount(repo.Handle, c.Id)); + } + + private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid) + { + var parents = new List(); + + using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) + { + int parentsCount = Proxy.git_commit_parentcount(obj); + + for (uint i = 0; i < parentsCount; i++) + { + ObjectId parentCommitId = Proxy.git_commit_parent_oid(obj.ObjectPtr, i); + parents.Add(new NewCommit(repo, parentCommitId)); + } + } + + return parents; + } + + public IEnumerator GetEnumerator() + { + throw new System.NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(NewCommit item) + { + throw new System.NotImplementedException(); + } + + public void Clear() + { + throw new System.NotImplementedException(); + } + + public bool Contains(NewCommit item) + { + throw new System.NotImplementedException(); + } + + public void CopyTo(NewCommit[] array, int arrayIndex) + { + throw new System.NotImplementedException(); + } + + public bool Remove(NewCommit item) + { + throw new System.NotImplementedException(); + } + + public int Count + { + get { return count.Value; } + } + + public bool IsReadOnly + { + get { throw new System.NotImplementedException(); } + } + + public int IndexOf(NewCommit item) + { + throw new System.NotImplementedException(); + } + + public void Insert(int index, NewCommit item) + { + throw new System.NotImplementedException(); + } + + public void RemoveAt(int index) + { + throw new System.NotImplementedException(); + } + + public NewCommit this[int index] + { + get { return parents.Value[index]; } + set { throw new System.NotImplementedException(); } + } + } + public class NewCommit : GitObject { private readonly Repository repo; @@ -12,7 +108,7 @@ public class NewCommit : GitObject private readonly LazyGroup group1; private readonly LazyGroup group2; - private readonly Lazy> parents; + private readonly IList parents; private readonly LazyProperty _lazyMessage; private readonly LazyProperty _lazyEncoding; private readonly LazyProperty _lazyAuthor; @@ -36,7 +132,7 @@ public NewCommit(Repository repo, ObjectId id) _lazyEncoding = group2.AddLazy(RetrieveEncodingOf); _lazyCommitter = group2.AddLazy(Proxy.git_commit_committer); - parents = new Lazy>(() => RetrieveParentsOfCommit(id)); + parents = new ParentsList(repo, this); } // Lazy batch loaded properies @@ -48,10 +144,10 @@ public NewCommit(Repository repo, ObjectId id) public Signature Committer { get { return _lazyCommitter.Value; } } // On demand lazy loaded properties - public IEnumerable Parents { get { return parents.Value; } } + public IEnumerable Parents { get { return parents; } } // Other properties - public int ParentsCount { get { return Proxy.git_commit_parentcount(repo.Handle, Id); ; } } + public int ParentsCount { get { return Proxy.git_commit_parentcount(repo.Handle, Id); } } public Tree Tree { get { return repo.Lookup(TreeId); } } @@ -62,22 +158,6 @@ private static string RetrieveEncodingOf(GitObjectSafeHandle obj) return encoding ?? "UTF-8"; } - private IList RetrieveParentsOfCommit(ObjectId oid) - { - var parents = new List(); - - using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) - { - int parentsCount = Proxy.git_commit_parentcount(obj); - for (uint i = 0; i < parentsCount; i++) - { - ObjectId parentCommitId = Proxy.git_commit_parent_oid(obj.ObjectPtr, i); - parents.Add(new NewCommit(repo, parentCommitId)); - } - } - - return parents; - } } } From c7c0e801148197001cee380ec46b5e9785a4a766 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 28 Oct 2012 15:11:59 +0100 Subject: [PATCH 4/8] Overkillest? Output from LibGit2Sharp.Tests.BranchFixture.Parents: Commits: 42000 Time: 2579 MaxParents: 8 Commits: 42000 Time: 2287 MaxParents: 8 --- LibGit2Sharp/NewCommit.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs index 21bf77c89..0406a6a53 100644 --- a/LibGit2Sharp/NewCommit.cs +++ b/LibGit2Sharp/NewCommit.cs @@ -8,21 +8,22 @@ namespace LibGit2Sharp { internal class ParentsList : IList { - private Lazy> parents; - private Lazy count; + private readonly Lazy> _parents; + private readonly Lazy _count; + public ParentsList(Repository repo, NewCommit c) { - parents = new Lazy>(() => RetrieveParentsOfCommit(repo, c.Id)); - count = new Lazy(() => Proxy.git_commit_parentcount(repo.Handle, c.Id)); + _count = new Lazy(() => Proxy.git_commit_parentcount(repo.Handle, c.Id)); + _parents = new Lazy>(() => RetrieveParentsOfCommit(repo, c.Id, _count)); } - private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid) + private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid, Lazy pCount) { var parents = new List(); using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) { - int parentsCount = Proxy.git_commit_parentcount(obj); + int parentsCount = pCount.Value; for (uint i = 0; i < parentsCount; i++) { @@ -71,7 +72,7 @@ public bool Remove(NewCommit item) public int Count { - get { return count.Value; } + get { return _count.Value; } } public bool IsReadOnly @@ -96,7 +97,7 @@ public void RemoveAt(int index) public NewCommit this[int index] { - get { return parents.Value[index]; } + get { return _parents.Value[index]; } set { throw new System.NotImplementedException(); } } } From 034dd8cf18c478f00f4be5d6e153f9381efae22c Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sun, 28 Oct 2012 21:42:32 -0500 Subject: [PATCH 5/8] Use interface instead of base class --- LibGit2Sharp/Core/LazyProperty.cs | 37 +++++++++++++------------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/LibGit2Sharp/Core/LazyProperty.cs b/LibGit2Sharp/Core/LazyProperty.cs index 8653b4170..6981f9e15 100644 --- a/LibGit2Sharp/Core/LazyProperty.cs +++ b/LibGit2Sharp/Core/LazyProperty.cs @@ -4,33 +4,21 @@ namespace LibGit2Sharp.Core { - internal class LazyProperty : LazyPropertyBase + internal class LazyProperty : IEvaluator { - public LazyProperty(Func evaluator, LazyGroup lazyGroup) - : base(evaluator, lazyGroup) - { } - - public TType Value - { - get { return (TType)base.Value; } - } - } - - internal class LazyPropertyBase - { - private readonly Func evaluator; + private readonly Func evaluator; private readonly LazyGroup lazyGroup; - private object value; + private TType value; private bool hasBeenEvaluated; - public LazyPropertyBase(Func evaluator, LazyGroup lazyGroup) + public LazyProperty(Func evaluator, LazyGroup lazyGroup) { this.evaluator = evaluator; this.lazyGroup = lazyGroup; } - public object Value + public TType Value { get { return Evaluate(); } } @@ -40,7 +28,7 @@ internal LazyGroup Group get { return lazyGroup; } } - private object Evaluate() + private TType Evaluate() { if (!hasBeenEvaluated) { @@ -56,19 +44,24 @@ private object Evaluate() return value; } - internal void InternalEvaluate(GitObjectSafeHandle objectPtr) + void IEvaluator.Evaluate(GitObjectSafeHandle objectPtr) { hasBeenEvaluated = true; value = evaluator(objectPtr); } } + internal interface IEvaluator + { + void Evaluate(T input); + } + internal class LazyGroup { private readonly Repository repo; private readonly ObjectId id; - private readonly IList lazies = new List(); + private readonly IList> lazies = new List>(); public LazyGroup(Repository repo, ObjectId id) { @@ -76,7 +69,7 @@ public LazyGroup(Repository repo, ObjectId id) this.id = id; } - public LazyProperty AddLazy(Func evaluator) + public LazyProperty AddLazy(Func evaluator) { var lazy = new LazyProperty(evaluator, this); lazies.Add(lazy); @@ -89,7 +82,7 @@ public void TriggerEvaluation() { foreach (var lazy in lazies) { - lazy.InternalEvaluate(osw.ObjectPtr); + lazy.Evaluate(osw.ObjectPtr); } } } From 053570aa3c8a450f1a0f551d95f1404660ff8ffd Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sun, 28 Oct 2012 21:50:55 -0500 Subject: [PATCH 6/8] Remove unused LazyProperty.Group --- LibGit2Sharp/Core/LazyProperty.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/LibGit2Sharp/Core/LazyProperty.cs b/LibGit2Sharp/Core/LazyProperty.cs index 6981f9e15..08de3996c 100644 --- a/LibGit2Sharp/Core/LazyProperty.cs +++ b/LibGit2Sharp/Core/LazyProperty.cs @@ -23,20 +23,15 @@ public TType Value get { return Evaluate(); } } - internal LazyGroup Group - { - get { return lazyGroup; } - } - private TType Evaluate() { if (!hasBeenEvaluated) { - lock (Group) + lock (lazyGroup) { if (!hasBeenEvaluated) { - Group.TriggerEvaluation(); + lazyGroup.TriggerEvaluation(); } } } From 0bcb276cb558e16a8953fcc901392e3af3a54b5e Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sun, 28 Oct 2012 21:51:53 -0500 Subject: [PATCH 7/8] ParentsList doesn't need to implement IList<> --- LibGit2Sharp/NewCommit.cs | 73 ++++++--------------------------------- 1 file changed, 11 insertions(+), 62 deletions(-) diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs index 0406a6a53..3513f2e07 100644 --- a/LibGit2Sharp/NewCommit.cs +++ b/LibGit2Sharp/NewCommit.cs @@ -6,24 +6,24 @@ namespace LibGit2Sharp { - internal class ParentsList : IList + internal class ParentsList : IEnumerable { private readonly Lazy> _parents; private readonly Lazy _count; - public ParentsList(Repository repo, NewCommit c) + public ParentsList(Repository repo, ObjectId id) { - _count = new Lazy(() => Proxy.git_commit_parentcount(repo.Handle, c.Id)); - _parents = new Lazy>(() => RetrieveParentsOfCommit(repo, c.Id, _count)); + _count = new Lazy(() => Proxy.git_commit_parentcount(repo.Handle, id)); + _parents = new Lazy>(() => RetrieveParentsOfCommit(repo, id)); } - private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid, Lazy pCount) + private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid) { var parents = new List(); using (var obj = new ObjectSafeWrapper(oid, repo.Handle)) { - int parentsCount = pCount.Value; + int parentsCount = _count.Value; for (uint i = 0; i < parentsCount; i++) { @@ -37,7 +37,7 @@ private IList RetrieveParentsOfCommit(Repository repo, ObjectId oid, public IEnumerator GetEnumerator() { - throw new System.NotImplementedException(); + return _parents.Value.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() @@ -45,60 +45,9 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } - public void Add(NewCommit item) - { - throw new System.NotImplementedException(); - } - - public void Clear() - { - throw new System.NotImplementedException(); - } - - public bool Contains(NewCommit item) - { - throw new System.NotImplementedException(); - } - - public void CopyTo(NewCommit[] array, int arrayIndex) - { - throw new System.NotImplementedException(); - } - - public bool Remove(NewCommit item) - { - throw new System.NotImplementedException(); - } - public int Count { - get { return _count.Value; } - } - - public bool IsReadOnly - { - get { throw new System.NotImplementedException(); } - } - - public int IndexOf(NewCommit item) - { - throw new System.NotImplementedException(); - } - - public void Insert(int index, NewCommit item) - { - throw new System.NotImplementedException(); - } - - public void RemoveAt(int index) - { - throw new System.NotImplementedException(); - } - - public NewCommit this[int index] - { - get { return _parents.Value[index]; } - set { throw new System.NotImplementedException(); } + get { return _parents.Value.Count; } } } @@ -109,7 +58,7 @@ public class NewCommit : GitObject private readonly LazyGroup group1; private readonly LazyGroup group2; - private readonly IList parents; + private readonly ParentsList parents; private readonly LazyProperty _lazyMessage; private readonly LazyProperty _lazyEncoding; private readonly LazyProperty _lazyAuthor; @@ -133,7 +82,7 @@ public NewCommit(Repository repo, ObjectId id) _lazyEncoding = group2.AddLazy(RetrieveEncodingOf); _lazyCommitter = group2.AddLazy(Proxy.git_commit_committer); - parents = new ParentsList(repo, this); + parents = new ParentsList(repo, id); } // Lazy batch loaded properies @@ -148,7 +97,7 @@ public NewCommit(Repository repo, ObjectId id) public IEnumerable Parents { get { return parents; } } // Other properties - public int ParentsCount { get { return Proxy.git_commit_parentcount(repo.Handle, Id); } } + public int ParentsCount { get { return parents.Count; } } public Tree Tree { get { return repo.Lookup(TreeId); } } From a0aa424803442deea30831c789223ff3f67809b8 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sun, 28 Oct 2012 22:09:42 -0500 Subject: [PATCH 8/8] Rename LazyGroup to GitObjectLazyGroup --- LibGit2Sharp/Core/LazyProperty.cs | 8 ++++---- LibGit2Sharp/NewCommit.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp/Core/LazyProperty.cs b/LibGit2Sharp/Core/LazyProperty.cs index 08de3996c..834a72d2e 100644 --- a/LibGit2Sharp/Core/LazyProperty.cs +++ b/LibGit2Sharp/Core/LazyProperty.cs @@ -7,12 +7,12 @@ namespace LibGit2Sharp.Core internal class LazyProperty : IEvaluator { private readonly Func evaluator; - private readonly LazyGroup lazyGroup; + private readonly GitObjectLazyGroup lazyGroup; private TType value; private bool hasBeenEvaluated; - public LazyProperty(Func evaluator, LazyGroup lazyGroup) + public LazyProperty(Func evaluator, GitObjectLazyGroup lazyGroup) { this.evaluator = evaluator; this.lazyGroup = lazyGroup; @@ -51,14 +51,14 @@ internal interface IEvaluator void Evaluate(T input); } - internal class LazyGroup + internal class GitObjectLazyGroup { private readonly Repository repo; private readonly ObjectId id; private readonly IList> lazies = new List>(); - public LazyGroup(Repository repo, ObjectId id) + public GitObjectLazyGroup(Repository repo, ObjectId id) { this.repo = repo; this.id = id; diff --git a/LibGit2Sharp/NewCommit.cs b/LibGit2Sharp/NewCommit.cs index 3513f2e07..39f36ed5e 100644 --- a/LibGit2Sharp/NewCommit.cs +++ b/LibGit2Sharp/NewCommit.cs @@ -55,8 +55,8 @@ public class NewCommit : GitObject { private readonly Repository repo; - private readonly LazyGroup group1; - private readonly LazyGroup group2; + private readonly GitObjectLazyGroup group1; + private readonly GitObjectLazyGroup group2; private readonly ParentsList parents; private readonly LazyProperty _lazyMessage; @@ -72,8 +72,8 @@ public NewCommit(Repository repo, ObjectId id) : base(id) { this.repo = repo; - group1 = new LazyGroup(repo, id); - group2 = new LazyGroup(repo, id); + group1 = new GitObjectLazyGroup(repo, id); + group2 = new GitObjectLazyGroup(repo, id); _lazyTreeId = group1.AddLazy(Proxy.git_commit_tree_oid); _lazyAuthor = group1.AddLazy(Proxy.git_commit_author);