| 1108 | "Create a new commit but return it as a string."); |
| 1109 | |
| 1110 | PyObject * |
| 1111 | Repository_create_commit_string(Repository *self, PyObject *args) |
| 1112 | { |
| 1113 | Signature *py_author, *py_committer; |
| 1114 | PyObject *py_oid, *py_message, *py_parents, *py_parent; |
| 1115 | PyObject *str = NULL; |
| 1116 | char *encoding = NULL; |
| 1117 | git_oid oid; |
| 1118 | git_tree *tree = NULL; |
| 1119 | int parent_count; |
| 1120 | git_commit **parents = NULL; |
| 1121 | git_buf buf = { 0 }; |
| 1122 | int i = 0; |
| 1123 | |
| 1124 | if (!PyArg_ParseTuple(args, "O!O!OOO!|s", |
| 1125 | &SignatureType, &py_author, |
| 1126 | &SignatureType, &py_committer, |
| 1127 | &py_message, |
| 1128 | &py_oid, |
| 1129 | &PyList_Type, &py_parents, |
| 1130 | &encoding)) |
| 1131 | return NULL; |
| 1132 | |
| 1133 | size_t len = py_oid_to_git_oid(py_oid, &oid); |
| 1134 | if (len == 0) |
| 1135 | return NULL; |
| 1136 | |
| 1137 | PyObject *tmessage; |
| 1138 | const char *message = pgit_borrow_encoding(py_message, encoding, NULL, &tmessage); |
| 1139 | if (message == NULL) |
| 1140 | return NULL; |
| 1141 | |
| 1142 | int err = git_tree_lookup_prefix(&tree, self->repo, &oid, len); |
| 1143 | if (err < 0) { |
| 1144 | Error_set(err); |
| 1145 | goto out; |
| 1146 | } |
| 1147 | |
| 1148 | parent_count = (int)PyList_Size(py_parents); |
| 1149 | parents = malloc(parent_count * sizeof(git_commit*)); |
| 1150 | if (parents == NULL) { |
| 1151 | PyErr_SetNone(PyExc_MemoryError); |
| 1152 | goto out; |
| 1153 | } |
| 1154 | for (; i < parent_count; i++) { |
| 1155 | py_parent = PyList_GetItemRef(py_parents, i); |
| 1156 | if (py_parent == NULL) |
| 1157 | goto out; |
| 1158 | len = py_oid_to_git_oid(py_parent, &oid); |
| 1159 | Py_DECREF(py_parent); |
| 1160 | if (len == 0) |
| 1161 | goto out; |
| 1162 | err = git_commit_lookup_prefix(&parents[i], self->repo, &oid, len); |
| 1163 | if (err < 0) { |
| 1164 | Error_set(err); |
| 1165 | goto out; |
| 1166 | } |
| 1167 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…