Rewrite init_repository using cffi

This commit is contained in:
J. David Ibáñez
2014-06-02 18:50:55 +02:00
parent 9e91a390cc
commit 6cf06ba9fe
3 changed files with 12 additions and 35 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -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__},