Skip to content

Commit 949b1c6

Browse files
committed
Review options
1 parent e19ea4d commit 949b1c6

File tree

1 file changed

+26
-101
lines changed

1 file changed

+26
-101
lines changed

src/options.c

Lines changed: 26 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -73,117 +73,46 @@ option(PyObject *self, PyObject *args)
7373

7474
switch (option) {
7575

76+
case GIT_OPT_GET_MWINDOW_FILE_LIMIT:
77+
case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT:
7678
case GIT_OPT_GET_MWINDOW_SIZE:
7779
{
78-
size_t size;
80+
size_t value;
7981

80-
error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &size);
82+
error = git_libgit2_opts(option, &value);
8183
if (error < 0)
8284
return Error_set(error);
8385

84-
return PyLong_FromSize_t(size);
86+
return PyLong_FromSize_t(value);
8587
}
8688

89+
case GIT_OPT_SET_MWINDOW_FILE_LIMIT:
90+
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT:
8791
case GIT_OPT_SET_MWINDOW_SIZE:
8892
{
89-
size_t size;
90-
PyObject *py_size;
91-
92-
py_size = PyTuple_GetItem(args, 1);
93-
if (!py_size)
93+
PyObject *py_value = PyTuple_GetItem(args, 1);
94+
if (!py_value)
9495
return NULL;
9596

96-
if (!PyLong_Check(py_size))
97-
return Error_type_error(
98-
"size should be an integer, got %.200s", py_size);
97+
if (!PyLong_Check(py_value))
98+
return Error_type_error("expected integer, got %.200s", py_value);
9999

100-
size = PyLong_AsSize_t(py_size);
101-
error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, size);
100+
size_t value = PyLong_AsSize_t(py_value);
101+
error = git_libgit2_opts(option, value);
102102
if (error < 0)
103103
return Error_set(error);
104104

105105
Py_RETURN_NONE;
106106
}
107107

108-
case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT:
109-
{
110-
size_t limit;
111-
112-
error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &limit);
113-
if (error < 0)
114-
return Error_set(error);
115-
116-
return PyLong_FromSize_t(limit);
117-
}
118-
119-
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT:
120-
{
121-
size_t limit;
122-
PyObject *py_limit;
123-
124-
py_limit = PyTuple_GetItem(args, 1);
125-
if (!py_limit)
126-
return NULL;
127-
128-
if (PyLong_Check(py_limit)) {
129-
limit = PyLong_AsSize_t(py_limit);
130-
} else if (PyLong_Check(py_limit)) {
131-
limit = PyLong_AsSize_t(py_limit);
132-
} else {
133-
return Error_type_error(
134-
"limit should be an integer, got %.200s", py_limit);
135-
}
136-
137-
error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, limit);
138-
if (error < 0)
139-
return Error_set(error);
140-
141-
Py_RETURN_NONE;
142-
}
143-
144-
case GIT_OPT_GET_MWINDOW_FILE_LIMIT:
145-
{
146-
size_t limit;
147-
148-
error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_FILE_LIMIT, &limit);
149-
if (error < 0)
150-
return Error_set(error);
151-
152-
return PyLong_FromSize_t(limit);
153-
}
154-
155-
case GIT_OPT_SET_MWINDOW_FILE_LIMIT:
156-
{
157-
size_t limit;
158-
PyObject *py_limit;
159-
160-
py_limit = PyTuple_GetItem(args, 1);
161-
if (!py_limit)
162-
return NULL;
163-
164-
if (!PyLong_Check(py_limit))
165-
return Error_type_error(
166-
"size should be an integer, got %.200s", py_limit);
167-
168-
limit = PyLong_AsSize_t(py_limit);
169-
error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, limit);
170-
if (error < 0)
171-
return Error_set(error);
172-
173-
Py_RETURN_NONE;
174-
}
175-
176108
case GIT_OPT_GET_SEARCH_PATH:
177109
{
178-
PyObject *py_level;
179-
180-
py_level = PyTuple_GetItem(args, 1);
110+
PyObject *py_level = PyTuple_GetItem(args, 1);
181111
if (!py_level)
182112
return NULL;
183113

184114
if (!PyLong_Check(py_level))
185-
return Error_type_error(
186-
"level should be an integer, got %.200s", py_level);
115+
return Error_type_error("level should be an integer, got %.200s", py_level);
187116

188117
return get_search_path(PyLong_AsLong(py_level));
189118
}
@@ -205,7 +134,7 @@ option(PyObject *self, PyObject *args)
205134
if (!path)
206135
return NULL;
207136

208-
int err = git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, PyLong_AsLong(py_level), path);
137+
int err = git_libgit2_opts(option, PyLong_AsLong(py_level), path);
209138
if (err < 0)
210139
return Error_set(err);
211140

@@ -232,8 +161,7 @@ option(PyObject *self, PyObject *args)
232161

233162
object_type = PyLong_AsLong(py_object_type);
234163
limit = PyLong_AsSize_t(py_limit);
235-
error = git_libgit2_opts(
236-
GIT_OPT_SET_CACHE_OBJECT_LIMIT, object_type, limit);
164+
error = git_libgit2_opts(option, object_type, limit);
237165

238166
if (error < 0)
239167
return Error_set(error);
@@ -255,7 +183,7 @@ option(PyObject *self, PyObject *args)
255183
"max_size should be an integer, got %.200s", py_max_size);
256184

257185
max_size = PyLong_AsSize_t(py_max_size);
258-
error = git_libgit2_opts(GIT_OPT_SET_CACHE_MAX_SIZE, max_size);
186+
error = git_libgit2_opts(option, max_size);
259187
if (error < 0)
260188
return Error_set(error);
261189

@@ -268,7 +196,7 @@ option(PyObject *self, PyObject *args)
268196
size_t allowed;
269197
PyObject* tup = PyTuple_New(2);
270198

271-
error = git_libgit2_opts(GIT_OPT_GET_CACHED_MEMORY, &current, &allowed);
199+
error = git_libgit2_opts(option, &current, &allowed);
272200
if (error < 0)
273201
return Error_set(error);
274202

@@ -307,7 +235,7 @@ option(PyObject *self, PyObject *args)
307235
if (PyUnicode_Check(py_dir) || PyBytes_Check(py_dir))
308236
dir_path = pgit_borrow_fsdefault(py_dir, &tvalue_dir);
309237

310-
err = git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, file_path, dir_path);
238+
err = git_libgit2_opts(option, file_path, dir_path);
311239
Py_XDECREF(tvalue_file);
312240
Py_XDECREF(tvalue_dir);
313241

@@ -334,18 +262,15 @@ option(PyObject *self, PyObject *args)
334262
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
335263
case GIT_OPT_SET_OWNER_VALIDATION:
336264
{
337-
PyObject *py_enabled;
338-
int enabled;
339-
340-
py_enabled = PyTuple_GetItem(args, 1);
341-
if (!py_enabled)
265+
PyObject *py_value = PyTuple_GetItem(args, 1);
266+
if (!py_value)
342267
return NULL;
343268

344-
if (!PyLong_Check(py_enabled))
345-
return Error_type_error("expected integer, got %.200s", py_enabled);
269+
if (!PyLong_Check(py_value))
270+
return Error_type_error("expected integer, got %.200s", py_value);
346271

347-
enabled = PyLong_AsSize_t(py_enabled);
348-
error = git_libgit2_opts(option, enabled);
272+
int value = PyLong_AsSize_t(py_value);
273+
error = git_libgit2_opts(option, value);
349274
if (error < 0)
350275
return Error_set(error);
351276

0 commit comments

Comments
 (0)