| 266 | " the hunks will be merged into a one.\n"); |
| 267 | |
| 268 | PyObject * |
| 269 | Tree_diff_to_index(Tree *self, PyObject *args, PyObject *kwds) |
| 270 | { |
| 271 | git_diff_options opts = GIT_DIFF_OPTIONS_INIT; |
| 272 | git_diff *diff; |
| 273 | git_index *index; |
| 274 | char *buffer; |
| 275 | Py_ssize_t length; |
| 276 | PyObject *py_idx; |
| 277 | int err; |
| 278 | |
| 279 | if (!PyArg_ParseTuple(args, "O|IHH", &py_idx, &opts.flags, |
| 280 | &opts.context_lines, |
| 281 | &opts.interhunk_lines)) |
| 282 | return NULL; |
| 283 | |
| 284 | /* Check whether the first argument is an index. |
| 285 | * FIXME Uses duck typing. This would be easy and correct if we had |
| 286 | * _pygit2.Index. */ |
| 287 | PyObject *pygit2_index = PyObject_GetAttrString(py_idx, "_index"); |
| 288 | if (!pygit2_index) { |
| 289 | PyErr_SetString(PyExc_TypeError, "argument must be an Index"); |
| 290 | return NULL; |
| 291 | } |
| 292 | Py_DECREF(pygit2_index); |
| 293 | |
| 294 | /* Get git_index from cffi's pointer */ |
| 295 | PyObject *py_idx_ptr = PyObject_GetAttrString(py_idx, "_pointer"); |
| 296 | if (!py_idx_ptr) |
| 297 | return NULL; |
| 298 | |
| 299 | /* Here we need to do the opposite conversion from the _pointer getters */ |
| 300 | if (PyBytes_AsStringAndSize(py_idx_ptr, &buffer, &length)) |
| 301 | goto error; |
| 302 | |
| 303 | if (length != sizeof(git_index *)) { |
| 304 | PyErr_SetString(PyExc_TypeError, "passed value is not a pointer"); |
| 305 | goto error; |
| 306 | } |
| 307 | |
| 308 | index = *((git_index **) buffer); /* the "buffer" contains the pointer */ |
| 309 | |
| 310 | /* Call git_diff_tree_to_index */ |
| 311 | if (Object__load((Object*)self) == NULL) { return NULL; } // Lazy load |
| 312 | |
| 313 | err = git_diff_tree_to_index(&diff, self->repo->repo, self->tree, index, &opts); |
| 314 | Py_DECREF(py_idx_ptr); |
| 315 | |
| 316 | if (err < 0) |
| 317 | return Error_set(err); |
| 318 | |
| 319 | return wrap_diff(diff, self->repo); |
| 320 | |
| 321 | error: |
| 322 | Py_DECREF(py_idx_ptr); |
| 323 | return NULL; |
| 324 | } |
| 325 |
nothing calls this directly
no test coverage detected
searching dependent graphs…