MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Repository_create_commit_string

Function Repository_create_commit_string

src/repository.c:1110–1190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1108 "Create a new commit but return it as a string.");
1109
1110PyObject *
1111Repository_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 }

Callers

nothing calls this directly

Calls 5

py_oid_to_git_oidFunction · 0.85
pgit_borrow_encodingFunction · 0.85
Error_setFunction · 0.85
PyList_GetItemRefFunction · 0.85
to_unicode_nFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…