@@ -134,51 +134,33 @@ private static bool PointsAtTheHead(string shaOrRefName)
134
134
/// <returns>The generated <see cref = "Commit" />.</returns>
135
135
public Commit Create ( string message , Signature author , Signature committer , bool amendPreviousCommit )
136
136
{
137
- Ensure . ArgumentNotNull ( message , "message" ) ;
138
- Ensure . ArgumentNotNull ( author , "author" ) ;
139
- Ensure . ArgumentNotNull ( committer , "committer" ) ;
140
-
141
137
if ( amendPreviousCommit && repo . Info . IsEmpty )
142
138
{
143
139
throw new LibGit2Exception ( "Can not amend anything. The Head doesn't point at any commit." ) ;
144
140
}
145
141
146
142
GitOid treeOid ;
147
- int res = NativeMethods . git_tree_create_fromindex ( out treeOid , repo . Index . Handle ) ;
148
- Ensure . Success ( res ) ;
149
-
150
- var parentIds = RetrieveParentIdsOfTheCommitBeingCreated ( repo , amendPreviousCommit ) ;
151
-
152
- GitOid commitOid ;
153
- using ( var treePtr = new ObjectSafeWrapper ( new ObjectId ( treeOid ) , repo ) )
154
- using ( var parentObjectPtrs = new DisposableEnumerable < ObjectSafeWrapper > ( parentIds . Select ( id => new ObjectSafeWrapper ( id , repo ) ) ) )
155
- using ( SignatureSafeHandle authorHandle = author . BuildHandle ( ) )
156
- using ( SignatureSafeHandle committerHandle = committer . BuildHandle ( ) )
157
- {
158
- string encoding = null ; //TODO: Handle the encoding of the commit to be created
143
+ Ensure . Success ( NativeMethods . git_tree_create_fromindex ( out treeOid , repo . Index . Handle ) ) ;
144
+ var tree = repo . Lookup < Tree > ( new ObjectId ( treeOid ) ) ;
159
145
160
- IntPtr [ ] parentsPtrs = parentObjectPtrs . Select ( o => o . ObjectPtr . DangerousGetHandle ( ) ) . ToArray ( ) ;
161
- res = NativeMethods . git_commit_create ( out commitOid , repo . Handle , repo . Refs [ "HEAD" ] . CanonicalName , authorHandle ,
162
- committerHandle , encoding , message , treePtr . ObjectPtr , parentObjectPtrs . Count ( ) , parentsPtrs ) ;
163
- Ensure . Success ( res ) ;
164
- }
146
+ var parents = RetrieveParentsOfTheCommitBeingCreated ( repo , amendPreviousCommit ) ;
165
147
166
- return repo . Lookup < Commit > ( new ObjectId ( commitOid ) ) ;
148
+ return repo . ObjectDatabase . CreateCommit ( message , author , committer , tree , parents , "HEAD" ) ;
167
149
}
168
150
169
- private static IEnumerable < ObjectId > RetrieveParentIdsOfTheCommitBeingCreated ( Repository repo , bool amendPreviousCommit )
151
+ private static IEnumerable < Commit > RetrieveParentsOfTheCommitBeingCreated ( Repository repo , bool amendPreviousCommit )
170
152
{
171
153
if ( amendPreviousCommit )
172
154
{
173
- return repo . Head . Tip . Parents . Select ( c => c . Id ) ;
155
+ return repo . Head . Tip . Parents ;
174
156
}
175
157
176
158
if ( repo . Info . IsEmpty )
177
159
{
178
- return Enumerable . Empty < ObjectId > ( ) ;
160
+ return Enumerable . Empty < Commit > ( ) ;
179
161
}
180
162
181
- return new [ ] { repo . Head . Tip . Id } ;
163
+ return new [ ] { repo . Head . Tip } ;
182
164
}
183
165
184
166
private class CommitEnumerator : IEnumerator < Commit >
0 commit comments