parent
7ee851273a
commit
b81810e9cb
18
src/pygit2.c
18
src/pygit2.c
|
@ -151,29 +151,35 @@ PyDoc_STRVAR(init_file_backend__doc__,
|
||||||
PyObject *
|
PyObject *
|
||||||
init_file_backend(PyObject *self, PyObject *args)
|
init_file_backend(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
const char* path;
|
const char* path = NULL;
|
||||||
int err = GIT_OK;
|
int err = GIT_OK;
|
||||||
git_repository *repository = NULL;
|
git_repository *repository = NULL;
|
||||||
if (!PyArg_ParseTuple(args, "s", &path)) {
|
if (!PyArg_ParseTuple(args, "s", &path)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
}
|
||||||
|
|
||||||
err = git_repository_open(&repository, path);
|
err = git_repository_open(&repository, path);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
Error_set_str(err, path);
|
Error_set_str(err, path);
|
||||||
err = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyCapsule_New(repository, "backend", NULL);
|
return PyCapsule_New(repository, "backend", NULL);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (repository)
|
if (repository) {
|
||||||
git_repository_free(repository);
|
git_repository_free(repository);
|
||||||
|
}
|
||||||
|
|
||||||
PyErr_Format(PyExc_Exception,
|
if (err == GIT_ENOTFOUND) {
|
||||||
"Git error %d during construction of git repo", err);
|
PyErr_Format(PyExc_Exception,
|
||||||
|
"Repository not found at %s", path);
|
||||||
|
} else {
|
||||||
|
PyErr_Format(PyExc_Exception,
|
||||||
|
"Git error %d while opening repo at %s", err, path);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue