File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,28 @@ Commit_parents__get__(Commit *self)
199199 return list ;
200200}
201201
202+ PyDoc_STRVAR (Commit_parent_ids__doc__ , "The list of parent commits' ids." );
203+
204+ PyObject *
205+ Commit_parent_ids__get__ (Commit * self )
206+ {
207+ unsigned int i , parent_count ;
208+ const git_oid * id ;
209+ PyObject * list ;
210+
211+ parent_count = git_commit_parentcount (self -> commit );
212+ list = PyList_New (parent_count );
213+ if (!list )
214+ return NULL ;
215+
216+ for (i = 0 ; i < parent_count ; i ++ ) {
217+ id = git_commit_parent_id (self -> commit , i );
218+ PyList_SET_ITEM (list , i , git_oid_to_python (id ));
219+ }
220+
221+ return list ;
222+ }
223+
202224PyGetSetDef Commit_getseters [] = {
203225 GETTER (Commit , message_encoding ),
204226 GETTER (Commit , message ),
@@ -210,6 +232,7 @@ PyGetSetDef Commit_getseters[] = {
210232 GETTER (Commit , tree ),
211233 GETTER (Commit , tree_id ),
212234 GETTER (Commit , parents ),
235+ GETTER (Commit , parent_ids ),
213236 {NULL }
214237};
215238
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ def test_new_commit(self):
9595 self .assertEqual (Oid (hex = tree ), commit .tree_id )
9696 self .assertEqual (1 , len (commit .parents ))
9797 self .assertEqual (COMMIT_SHA , commit .parents [0 ].hex )
98+ self .assertEqual (Oid (hex = COMMIT_SHA ), commit .parent_ids [0 ])
9899
99100 def test_new_commit_encoding (self ):
100101 repo = self .repo
@@ -122,6 +123,7 @@ def test_new_commit_encoding(self):
122123 self .assertEqual (Oid (hex = tree ), commit .tree_id )
123124 self .assertEqual (1 , len (commit .parents ))
124125 self .assertEqual (COMMIT_SHA , commit .parents [0 ].hex )
126+ self .assertEqual (Oid (hex = COMMIT_SHA ), commit .parent_ids [0 ])
125127
126128 def test_modify_commit (self ):
127129 message = 'New commit.\n \n Message.\n '
You can’t perform that action at this time.
0 commit comments