| 297 | "of the filters.\n"); |
| 298 | |
| 299 | PyObject * |
| 300 | filter_register(PyObject *self, PyObject *args, PyObject *kwds) |
| 301 | { |
| 302 | const char *name; |
| 303 | Py_ssize_t size; |
| 304 | PyObject *py_filter_cls; |
| 305 | int priority = GIT_FILTER_DRIVER_PRIORITY; |
| 306 | char *keywords[] = {"name", "filter_cls", "priority", NULL}; |
| 307 | pygit2_filter *filter; |
| 308 | int err; |
| 309 | |
| 310 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#O|i", keywords, |
| 311 | &name, &size, &py_filter_cls, &priority)) |
| 312 | return NULL; |
| 313 | |
| 314 | /* py_attrs = py_filter_cls.attributes */ |
| 315 | PyObject* py_attrs = PyObject_GetAttrString(py_filter_cls, "attributes"); |
| 316 | if (py_attrs == NULL) { |
| 317 | return NULL; |
| 318 | } |
| 319 | char* attrs = pgit_strdup(py_attrs); |
| 320 | Py_DECREF(py_attrs); |
| 321 | if (attrs == NULL) { |
| 322 | return NULL; |
| 323 | } |
| 324 | |
| 325 | /* allocate memory */ |
| 326 | filter = malloc(sizeof(pygit2_filter)); |
| 327 | if (filter == NULL) { |
| 328 | free(attrs); |
| 329 | return PyErr_NoMemory(); |
| 330 | } |
| 331 | memset(filter, 0, sizeof(pygit2_filter)); |
| 332 | |
| 333 | /* initialize git_filter */ |
| 334 | git_filter_init(&filter->filter, GIT_FILTER_VERSION); |
| 335 | filter->filter.attributes = attrs; |
| 336 | filter->filter.shutdown = pygit2_filter_shutdown; |
| 337 | filter->filter.check = pygit2_filter_check; |
| 338 | filter->filter.stream = pygit2_filter_stream; |
| 339 | filter->filter.cleanup = pygit2_filter_cleanup; |
| 340 | |
| 341 | /* keep reference to Python filter */ |
| 342 | filter->py_filter_cls = py_filter_cls; |
| 343 | |
| 344 | /* git register filter */ |
| 345 | if ((err = git_filter_register(name, &filter->filter, priority)) < 0) { |
| 346 | free(attrs); |
| 347 | free(filter); |
| 348 | return Error_set(err); |
| 349 | } |
| 350 | |
| 351 | Py_INCREF(py_filter_cls); /* libgit2 now owns this reference, will decref in shutdown */ |
| 352 | Py_RETURN_NONE; |
| 353 | } |
| 354 | |
| 355 | static void |
| 356 | forget_enums(void) |
nothing calls this directly
no test coverage detected
searching dependent graphs…