@@ -109,6 +109,7 @@ discover_repository(PyObject *self, PyObject *args)
109
109
const char * ceiling_dirs = NULL ;
110
110
PyObject * py_repo_path = NULL ;
111
111
int err ;
112
+ PyObject * result = NULL ;
112
113
113
114
if (!PyArg_ParseTuple (args , "O&|IO&" , PyUnicode_FSConverter , & py_path , & across_fs ,
114
115
PyUnicode_FSConverter , & py_ceiling_dirs ))
@@ -122,18 +123,20 @@ discover_repository(PyObject *self, PyObject *args)
122
123
memset (& repo_path , 0 , sizeof (git_buf ));
123
124
err = git_repository_discover (& repo_path , path , across_fs , ceiling_dirs );
124
125
125
- Py_XDECREF (py_path );
126
- Py_XDECREF (py_ceiling_dirs );
127
-
128
- if (err == GIT_ENOTFOUND )
129
- Py_RETURN_NONE ;
130
- if (err < 0 )
131
- return Error_set_str (err , path );
126
+ if (err == GIT_OK ) {
127
+ py_repo_path = PyUnicode_DecodeFSDefault (repo_path .ptr );
128
+ git_buf_dispose (& repo_path );
129
+ result = py_repo_path ;
130
+ } else if (err == GIT_ENOTFOUND ) {
131
+ result = Py_None ;
132
+ } else {
133
+ result = Error_set_str (err , path );
134
+ }
132
135
133
- py_repo_path = PyUnicode_DecodeFSDefault ( repo_path . ptr );
134
- git_buf_dispose ( & repo_path );
136
+ Py_XDECREF ( py_ceiling_dirs );
137
+ Py_XDECREF ( py_path );
135
138
136
- return py_repo_path ;
139
+ return result ;
137
140
};
138
141
139
142
PyDoc_STRVAR (hashfile__doc__ ,
@@ -200,6 +203,7 @@ init_file_backend(PyObject *self, PyObject *args)
200
203
unsigned int flags = 0 ;
201
204
int err = GIT_OK ;
202
205
git_repository * repository = NULL ;
206
+ PyObject * result = NULL ;
203
207
204
208
if (!PyArg_ParseTuple (args , "O&|I" , PyUnicode_FSConverter , & py_path , & flags ))
205
209
return NULL ;
@@ -208,25 +212,23 @@ init_file_backend(PyObject *self, PyObject *args)
208
212
209
213
err = git_repository_open_ext (& repository , path , flags , NULL );
210
214
211
- Py_XDECREF (py_path );
212
-
213
- if (err < 0 ) {
215
+ if (err == GIT_OK ) {
216
+ result = PyCapsule_New (repository , "backend" , NULL );
217
+ } else {
218
+ result = NULL ;
214
219
Error_set_str (err , path );
215
- goto cleanup ;
216
- }
217
-
218
- return PyCapsule_New (repository , "backend" , NULL );
219
220
220
- cleanup :
221
- if (repository ) {
222
- git_repository_free (repository );
223
- }
221
+ if (repository ) {
222
+ git_repository_free (repository );
223
+ }
224
224
225
- if (err == GIT_ENOTFOUND ) {
226
- PyErr_Format (GitError , "Repository not found at %s" , path );
225
+ if (err == GIT_ENOTFOUND ) {
226
+ PyErr_Format (GitError , "Repository not found at %s" , path );
227
+ }
227
228
}
228
229
229
- return NULL ;
230
+ Py_XDECREF (py_path );
231
+ return result ;
230
232
}
231
233
232
234
0 commit comments