From e19ea4d0bf18b790b9b69aacfa099f094b491467 Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 30 Jul 2024 17:22:17 +0100 Subject: [PATCH] Expose MWINDOW_FILE_LIMIT options from libgit2 --- pygit2/enums.py | 4 ++-- src/options.c | 32 ++++++++++++++++++++++++++++++++ src/options.h | 6 ++++++ src/pygit2.c | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/pygit2/enums.py b/pygit2/enums.py index 344ea714..e5bd54d9 100644 --- a/pygit2/enums.py +++ b/pygit2/enums.py @@ -979,8 +979,8 @@ class Option(IntEnum): SET_PACK_MAX_OBJECTS = _pygit2.GIT_OPT_SET_PACK_MAX_OBJECTS DISABLE_PACK_KEEP_FILE_CHECKS = _pygit2.GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS # ENABLE_HTTP_EXPECT_CONTINUE = _pygit2.GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE - # GET_MWINDOW_FILE_LIMIT = _pygit2.GIT_OPT_GET_MWINDOW_FILE_LIMIT - # SET_MWINDOW_FILE_LIMIT = _pygit2.GIT_OPT_SET_MWINDOW_FILE_LIMIT + GET_MWINDOW_FILE_LIMIT = _pygit2.GIT_OPT_GET_MWINDOW_FILE_LIMIT + SET_MWINDOW_FILE_LIMIT = _pygit2.GIT_OPT_SET_MWINDOW_FILE_LIMIT # SET_ODB_PACKED_PRIORITY = _pygit2.GIT_OPT_SET_ODB_PACKED_PRIORITY # SET_ODB_LOOSE_PRIORITY = _pygit2.GIT_OPT_SET_ODB_LOOSE_PRIORITY # GET_EXTENSIONS = _pygit2.GIT_OPT_GET_EXTENSIONS diff --git a/src/options.c b/src/options.c index 2d27839c..60a76f79 100644 --- a/src/options.c +++ b/src/options.c @@ -141,6 +141,38 @@ option(PyObject *self, PyObject *args) Py_RETURN_NONE; } + case GIT_OPT_GET_MWINDOW_FILE_LIMIT: + { + size_t limit; + + error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_FILE_LIMIT, &limit); + if (error < 0) + return Error_set(error); + + return PyLong_FromSize_t(limit); + } + + case GIT_OPT_SET_MWINDOW_FILE_LIMIT: + { + size_t limit; + PyObject *py_limit; + + py_limit = PyTuple_GetItem(args, 1); + if (!py_limit) + return NULL; + + if (!PyLong_Check(py_limit)) + return Error_type_error( + "size should be an integer, got %.200s", py_limit); + + limit = PyLong_AsSize_t(py_limit); + error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, limit); + if (error < 0) + return Error_set(error); + + Py_RETURN_NONE; + } + case GIT_OPT_GET_SEARCH_PATH: { PyObject *py_level; diff --git a/src/options.h b/src/options.h index 2ac7e175..90b91d9e 100644 --- a/src/options.h +++ b/src/options.h @@ -52,6 +52,12 @@ PyDoc_STRVAR(option__doc__, "GIT_OPT_SET_MWINDOW_SIZE, size\n" " Set the maximum mmap window size.\n" "\n" + "GIT_OPT_GET_MWINDOW_FILE_LIMIT\n" + " Get the maximum number of files that will be mapped at any time by the library.\n" + "\n" + "GIT_OPT_SET_MWINDOW_FILE_LIMIT, size\n" + " Set the maximum number of files that can be mapped at any time by the library. The default (0) is unlimited.\n" + "\n" "GIT_OPT_GET_OWNER_VALIDATION\n" " Gets the owner validation setting for repository directories.\n" "\n" diff --git a/src/pygit2.c b/src/pygit2.c index 9b275752..3c661773 100644 --- a/src/pygit2.c +++ b/src/pygit2.c @@ -504,6 +504,8 @@ PyInit__pygit2(void) ADD_CONSTANT_INT(m, GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS); ADD_CONSTANT_INT(m, GIT_OPT_GET_OWNER_VALIDATION); ADD_CONSTANT_INT(m, GIT_OPT_SET_OWNER_VALIDATION); + ADD_CONSTANT_INT(m, GIT_OPT_GET_MWINDOW_FILE_LIMIT); + ADD_CONSTANT_INT(m, GIT_OPT_SET_MWINDOW_FILE_LIMIT); /* Exceptions */ ADD_EXC(m, GitError, NULL);