6
6
7
7
namespace LibGit2Sharp
8
8
{
9
- internal class ParentsList : IList < NewCommit >
9
+ internal class ParentsList : IEnumerable < NewCommit >
10
10
{
11
11
private readonly Lazy < IList < NewCommit > > _parents ;
12
12
private readonly Lazy < int > _count ;
13
13
14
- public ParentsList ( Repository repo , NewCommit c )
14
+ public ParentsList ( Repository repo , ObjectId id )
15
15
{
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 ) ) ;
18
18
}
19
19
20
- private IList < NewCommit > RetrieveParentsOfCommit ( Repository repo , ObjectId oid , Lazy < int > pCount )
20
+ private IList < NewCommit > RetrieveParentsOfCommit ( Repository repo , ObjectId oid )
21
21
{
22
22
var parents = new List < NewCommit > ( ) ;
23
23
24
24
using ( var obj = new ObjectSafeWrapper ( oid , repo . Handle ) )
25
25
{
26
- int parentsCount = pCount . Value ;
26
+ int parentsCount = _count . Value ;
27
27
28
28
for ( uint i = 0 ; i < parentsCount ; i ++ )
29
29
{
@@ -37,68 +37,17 @@ private IList<NewCommit> RetrieveParentsOfCommit(Repository repo, ObjectId oid,
37
37
38
38
public IEnumerator < NewCommit > GetEnumerator ( )
39
39
{
40
- throw new System . NotImplementedException ( ) ;
40
+ return _parents . Value . GetEnumerator ( ) ;
41
41
}
42
42
43
43
IEnumerator IEnumerable . GetEnumerator ( )
44
44
{
45
45
return GetEnumerator ( ) ;
46
46
}
47
47
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
-
73
48
public int Count
74
49
{
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 ; }
102
51
}
103
52
}
104
53
@@ -109,7 +58,7 @@ public class NewCommit : GitObject
109
58
private readonly LazyGroup group1 ;
110
59
private readonly LazyGroup group2 ;
111
60
112
- private readonly IList < NewCommit > parents ;
61
+ private readonly ParentsList parents ;
113
62
private readonly LazyProperty < string > _lazyMessage ;
114
63
private readonly LazyProperty < string > _lazyEncoding ;
115
64
private readonly LazyProperty < Signature > _lazyAuthor ;
@@ -133,7 +82,7 @@ public NewCommit(Repository repo, ObjectId id)
133
82
_lazyEncoding = group2 . AddLazy < string > ( RetrieveEncodingOf ) ;
134
83
_lazyCommitter = group2 . AddLazy < Signature > ( Proxy . git_commit_committer ) ;
135
84
136
- parents = new ParentsList ( repo , this ) ;
85
+ parents = new ParentsList ( repo , id ) ;
137
86
}
138
87
139
88
// Lazy batch loaded properies
@@ -148,7 +97,7 @@ public NewCommit(Repository repo, ObjectId id)
148
97
public IEnumerable < NewCommit > Parents { get { return parents ; } }
149
98
150
99
// Other properties
151
- public int ParentsCount { get { return Proxy . git_commit_parentcount ( repo . Handle , Id ) ; } }
100
+ public int ParentsCount { get { return parents . Count ; } }
152
101
153
102
public Tree Tree { get { return repo . Lookup < Tree > ( TreeId ) ; } }
154
103
0 commit comments