@@ -877,9 +877,9 @@ PyObject* Repository_create_branch(Repository *self, PyObject *args)
877
877
878
878
879
879
PyDoc_STRVAR (Repository_listall_references__doc__ ,
880
- "listall_references() -> ( str, ...) \n"
880
+ "listall_references() -> [ str, ...] \n"
881
881
"\n"
882
- "Return a tuple with all the references in the repository." );
882
+ "Return a list with all the references in the repository." );
883
883
884
884
PyObject *
885
885
Repository_listall_references (Repository * self , PyObject * args )
@@ -895,18 +895,18 @@ Repository_listall_references(Repository *self, PyObject *args)
895
895
return Error_set (err );
896
896
897
897
/* Create a new PyTuple */
898
- py_result = PyTuple_New (c_result .count );
898
+ py_result = PyList_New (c_result .count );
899
899
if (py_result == NULL )
900
900
goto out ;
901
901
902
902
/* Fill it */
903
903
for (index = 0 ; index < c_result .count ; index ++ ) {
904
- py_string = to_path (( c_result .strings ) [index ]);
904
+ py_string = to_path (c_result .strings [index ]);
905
905
if (py_string == NULL ) {
906
906
Py_CLEAR (py_result );
907
907
goto out ;
908
908
}
909
- PyTuple_SET_ITEM (py_result , index , py_string );
909
+ PyList_SET_ITEM (py_result , index , py_string );
910
910
}
911
911
912
912
out :
@@ -916,7 +916,7 @@ Repository_listall_references(Repository *self, PyObject *args)
916
916
917
917
918
918
PyDoc_STRVAR (Repository_listall_branches__doc__ ,
919
- "listall_branches([flags]) -> ( str, ...) \n"
919
+ "listall_branches([flags]) -> [ str, ...] \n"
920
920
"\n"
921
921
"Return a tuple with all the branches in the repository." );
922
922
@@ -926,57 +926,49 @@ Repository_listall_branches(Repository *self, PyObject *args)
926
926
git_branch_t list_flags = GIT_BRANCH_LOCAL ;
927
927
git_branch_iterator * iter ;
928
928
git_reference * ref = NULL ;
929
- Py_ssize_t pos = 0 ;
930
929
int err ;
931
930
git_branch_t type ;
932
- PyObject * tuple ;
931
+ PyObject * list ;
933
932
934
933
/* 1- Get list_flags */
935
934
if (!PyArg_ParseTuple (args , "|I" , & list_flags ))
936
935
return NULL ;
937
936
938
- tuple = PyTuple_New ( 4 );
939
- if (tuple == NULL )
937
+ list = PyList_New ( 0 );
938
+ if (list == NULL )
940
939
return NULL ;
941
940
942
941
if ((err = git_branch_iterator_new (& iter , self -> repo , list_flags )) < 0 )
943
942
return Error_set (err );
944
943
945
944
while ((err = git_branch_next (& ref , & type , iter )) == 0 ) {
946
- if (PyTuple_Size (tuple ) <= pos ) {
947
- if (_PyTuple_Resize (& tuple , pos * 2 ) < 0 )
948
- goto on_error ;
949
- }
950
-
951
945
PyObject * py_branch_name = to_path (git_reference_shorthand (ref ));
952
946
git_reference_free (ref );
953
- ref = NULL ;
954
947
955
948
if (py_branch_name == NULL )
956
949
goto on_error ;
957
950
958
- PyTuple_SET_ITEM (tuple , pos ++ , py_branch_name );
951
+ err = PyList_Append (list , py_branch_name );
952
+ Py_DECREF (py_branch_name );
953
+
954
+ if (err < 0 )
955
+ goto on_error ;
959
956
}
960
957
961
958
git_branch_iterator_free (iter );
962
959
if (err == GIT_ITEROVER )
963
960
err = 0 ;
964
961
965
962
if (err < 0 ) {
966
- Py_CLEAR (tuple );
963
+ Py_CLEAR (list );
967
964
return Error_set (err );
968
965
}
969
966
970
- /* Remove the elements we might have overallocated in the loop */
971
- if (_PyTuple_Resize (& tuple , pos ) < 0 )
972
- return Error_set (err );
973
-
974
- return tuple ;
967
+ return list ;
975
968
976
969
on_error :
977
- git_reference_free (ref );
978
970
git_branch_iterator_free (iter );
979
- Py_CLEAR (tuple );
971
+ Py_CLEAR (list );
980
972
return NULL ;
981
973
}
982
974
0 commit comments