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

Function filter_register

src/pygit2.c:299–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297 "of the filters.\n");
298
299PyObject *
300filter_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
355static void
356forget_enums(void)

Callers

nothing calls this directly

Calls 2

pgit_strdupFunction · 0.85
Error_setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…