From 6cf06ba9fe89e0673c0d8c96d1fc8cbae738e852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Mon, 2 Jun 2014 18:50:55 +0200 Subject: [PATCH] Rewrite init_repository using cffi --- pygit2/__init__.py | 6 ++++-- pygit2/decl.h | 9 ++++++++- src/pygit2.c | 32 -------------------------------- 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/pygit2/__init__.py b/pygit2/__init__.py index 9aa0c42..a067a3b 100644 --- a/pygit2/__init__.py +++ b/pygit2/__init__.py @@ -29,7 +29,6 @@ from __future__ import absolute_import # Low level API -import _pygit2 from _pygit2 import * # High level API @@ -49,7 +48,10 @@ def init_repository(path, bare=False): If *bare* is True the repository will be bare, i.e. it will not have a working copy. """ - _pygit2.init_repository(path, bare) + crepository = ffi.new('git_repository **') + err = C.git_repository_init(crepository, to_str(path), bare) + check_error(err) + return Repository(path) diff --git a/pygit2/decl.h b/pygit2/decl.h index 9f82b1c..1fb28e7 100644 --- a/pygit2/decl.h +++ b/pygit2/decl.h @@ -254,7 +254,10 @@ int git_config_iterator_new(git_config_iterator **out, const git_config *cfg); int git_config_next(git_config_entry **entry, git_config_iterator *iter); void git_config_iterator_free(git_config_iterator *iter); -int git_config_multivar_iterator_new(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); +int git_config_multivar_iterator_new(git_config_iterator **out, + const git_config *cfg, const char *name, + const char *regexp); + int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value); int git_config_new(git_config **out); @@ -262,3 +265,7 @@ int git_config_open_ondisk(git_config **out, const char *path); int git_config_find_system(char *out, size_t length); int git_config_find_global(char *out, size_t length); int git_config_find_xdg(char *out, size_t length); + + +int git_repository_init(git_repository **out, const char *path, + unsigned is_bare); diff --git a/src/pygit2.c b/src/pygit2.c index 2ed0808..4808f74 100644 --- a/src/pygit2.c +++ b/src/pygit2.c @@ -82,37 +82,6 @@ extern PyTypeObject MergeResultType; -PyDoc_STRVAR(init_repository__doc__, - "init_repository(path, bare)\n" - "\n" - "Creates a new Git repository in the given path.\n" - "\n" - "Arguments:\n" - "\n" - "path\n" - " Path where to create the repository.\n" - "\n" - "bare\n" - " Whether the repository will be bare or not.\n"); - -PyObject * -init_repository(PyObject *self, PyObject *args) { - git_repository *repo; - const char *path; - unsigned int bare; - int err; - - if (!PyArg_ParseTuple(args, "sI", &path, &bare)) - return NULL; - - err = git_repository_init(&repo, path, bare); - if (err < 0) - return Error_set_str(err, path); - - git_repository_free(repo); - Py_RETURN_NONE; -}; - PyDoc_STRVAR(discover_repository__doc__, "discover_repository(path[, across_fs[, ceiling_dirs]]) -> str\n" "\n" @@ -186,7 +155,6 @@ hash(PyObject *self, PyObject *args) PyMethodDef module_methods[] = { - {"init_repository", init_repository, METH_VARARGS, init_repository__doc__}, {"discover_repository", discover_repository, METH_VARARGS, discover_repository__doc__}, {"hashfile", hashfile, METH_VARARGS, hashfile__doc__},