| 1021 | "Create a new commit object, return its oid."); |
| 1022 | |
| 1023 | PyObject * |
| 1024 | Repository_create_commit(Repository *self, PyObject *args) |
| 1025 | { |
| 1026 | Signature *py_author, *py_committer; |
| 1027 | PyObject *py_oid, *py_message, *py_parents, *py_parent; |
| 1028 | PyObject *py_result = NULL; |
| 1029 | char *update_ref = NULL; |
| 1030 | char *encoding = NULL; |
| 1031 | git_oid oid; |
| 1032 | git_tree *tree = NULL; |
| 1033 | int parent_count; |
| 1034 | git_commit **parents = NULL; |
| 1035 | int i = 0; |
| 1036 | |
| 1037 | if (!PyArg_ParseTuple(args, "zO!O!OOO!|s", |
| 1038 | &update_ref, |
| 1039 | &SignatureType, &py_author, |
| 1040 | &SignatureType, &py_committer, |
| 1041 | &py_message, |
| 1042 | &py_oid, |
| 1043 | &PyList_Type, &py_parents, |
| 1044 | &encoding)) |
| 1045 | return NULL; |
| 1046 | |
| 1047 | size_t len = py_oid_to_git_oid(py_oid, &oid); |
| 1048 | if (len == 0) |
| 1049 | return NULL; |
| 1050 | |
| 1051 | PyObject *tmessage; |
| 1052 | const char *message = pgit_borrow_encoding(py_message, encoding, NULL, &tmessage); |
| 1053 | if (message == NULL) |
| 1054 | return NULL; |
| 1055 | |
| 1056 | int err = git_tree_lookup_prefix(&tree, self->repo, &oid, len); |
| 1057 | if (err < 0) { |
| 1058 | Error_set(err); |
| 1059 | goto out; |
| 1060 | } |
| 1061 | |
| 1062 | parent_count = (int)PyList_Size(py_parents); |
| 1063 | parents = malloc(parent_count * sizeof(git_commit*)); |
| 1064 | if (parents == NULL) { |
| 1065 | PyErr_SetNone(PyExc_MemoryError); |
| 1066 | goto out; |
| 1067 | } |
| 1068 | for (; i < parent_count; i++) { |
| 1069 | py_parent = PyList_GetItemRef(py_parents, i); |
| 1070 | if (py_parent == NULL) |
| 1071 | goto out; |
| 1072 | len = py_oid_to_git_oid(py_parent, &oid); |
| 1073 | Py_DECREF(py_parent); |
| 1074 | if (len == 0) |
| 1075 | goto out; |
| 1076 | err = git_commit_lookup_prefix(&parents[i], self->repo, &oid, len); |
| 1077 | if (err < 0) { |
| 1078 | Error_set(err); |
| 1079 | goto out; |
| 1080 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…