Skip to content

Commit 0bcb276

Browse files
committed
ParentsList doesn't need to implement IList<>
1 parent 053570a commit 0bcb276

File tree

1 file changed

+11
-62
lines changed

1 file changed

+11
-62
lines changed

LibGit2Sharp/NewCommit.cs

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
namespace LibGit2Sharp
88
{
9-
internal class ParentsList : IList<NewCommit>
9+
internal class ParentsList : IEnumerable<NewCommit>
1010
{
1111
private readonly Lazy<IList<NewCommit>> _parents;
1212
private readonly Lazy<int> _count;
1313

14-
public ParentsList(Repository repo, NewCommit c)
14+
public ParentsList(Repository repo, ObjectId id)
1515
{
16-
_count = new Lazy<int>(() => Proxy.git_commit_parentcount(repo.Handle, c.Id));
17-
_parents = new Lazy<IList<NewCommit>>(() => RetrieveParentsOfCommit(repo, c.Id, _count));
16+
_count = new Lazy<int>(() => Proxy.git_commit_parentcount(repo.Handle, id));
17+
_parents = new Lazy<IList<NewCommit>>(() => RetrieveParentsOfCommit(repo, id));
1818
}
1919

20-
private IList<NewCommit> RetrieveParentsOfCommit(Repository repo, ObjectId oid, Lazy<int> pCount)
20+
private IList<NewCommit> RetrieveParentsOfCommit(Repository repo, ObjectId oid)
2121
{
2222
var parents = new List<NewCommit>();
2323

2424
using (var obj = new ObjectSafeWrapper(oid, repo.Handle))
2525
{
26-
int parentsCount = pCount.Value;
26+
int parentsCount = _count.Value;
2727

2828
for (uint i = 0; i < parentsCount; i++)
2929
{
@@ -37,68 +37,17 @@ private IList<NewCommit> RetrieveParentsOfCommit(Repository repo, ObjectId oid,
3737

3838
public IEnumerator<NewCommit> GetEnumerator()
3939
{
40-
throw new System.NotImplementedException();
40+
return _parents.Value.GetEnumerator();
4141
}
4242

4343
IEnumerator IEnumerable.GetEnumerator()
4444
{
4545
return GetEnumerator();
4646
}
4747

48-
public void Add(NewCommit item)
49-
{
50-
throw new System.NotImplementedException();
51-
}
52-
53-
public void Clear()
54-
{
55-
throw new System.NotImplementedException();
56-
}
57-
58-
public bool Contains(NewCommit item)
59-
{
60-
throw new System.NotImplementedException();
61-
}
62-
63-
public void CopyTo(NewCommit[] array, int arrayIndex)
64-
{
65-
throw new System.NotImplementedException();
66-
}
67-
68-
public bool Remove(NewCommit item)
69-
{
70-
throw new System.NotImplementedException();
71-
}
72-
7348
public int Count
7449
{
75-
get { return _count.Value; }
76-
}
77-
78-
public bool IsReadOnly
79-
{
80-
get { throw new System.NotImplementedException(); }
81-
}
82-
83-
public int IndexOf(NewCommit item)
84-
{
85-
throw new System.NotImplementedException();
86-
}
87-
88-
public void Insert(int index, NewCommit item)
89-
{
90-
throw new System.NotImplementedException();
91-
}
92-
93-
public void RemoveAt(int index)
94-
{
95-
throw new System.NotImplementedException();
96-
}
97-
98-
public NewCommit this[int index]
99-
{
100-
get { return _parents.Value[index]; }
101-
set { throw new System.NotImplementedException(); }
50+
get { return _parents.Value.Count; }
10251
}
10352
}
10453

@@ -109,7 +58,7 @@ public class NewCommit : GitObject
10958
private readonly LazyGroup group1;
11059
private readonly LazyGroup group2;
11160

112-
private readonly IList<NewCommit> parents;
61+
private readonly ParentsList parents;
11362
private readonly LazyProperty<string> _lazyMessage;
11463
private readonly LazyProperty<string> _lazyEncoding;
11564
private readonly LazyProperty<Signature> _lazyAuthor;
@@ -133,7 +82,7 @@ public NewCommit(Repository repo, ObjectId id)
13382
_lazyEncoding = group2.AddLazy<string>(RetrieveEncodingOf);
13483
_lazyCommitter = group2.AddLazy<Signature>(Proxy.git_commit_committer);
13584

136-
parents = new ParentsList(repo, this);
85+
parents = new ParentsList(repo, id);
13786
}
13887

13988
// Lazy batch loaded properies
@@ -148,7 +97,7 @@ public NewCommit(Repository repo, ObjectId id)
14897
public IEnumerable<NewCommit> Parents { get { return parents; } }
14998

15099
// Other properties
151-
public int ParentsCount { get { return Proxy.git_commit_parentcount(repo.Handle, Id); } }
100+
public int ParentsCount { get { return parents.Count; } }
152101

153102
public Tree Tree { get { return repo.Lookup<Tree>(TreeId); } }
154103

0 commit comments

Comments
 (0)