8000 Introduce Refdb type by ddevault · Pull Request #982 · libgit2/pygit2 · GitHub
[go: up one dir, main page]

Skip to content

Introduce Refdb type #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Repository: add zero-arg constructor
This creates a git_repository with no odb and no refdb.
  • Loading branch information
ddevault committed Mar 30, 2020
commit c0f9ae50aa699b0013cb70510fdb265b7def284e
25 changes: 14 additions & 11 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
8000 Expand Up @@ -50,8 +50,8 @@


class BaseRepository(_Repository):
def __init__(self, backend, *args, **kwargs):
super().__init__(backend, *args, **kwargs)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._common_init()

def _common_init(self):
Expand Down Expand Up @@ -1279,15 +1279,18 @@ def compress(self):


class Repository(BaseRepository):
def __init__(self, path, *args, **kwargs):
if hasattr(path, "__fspath__"):
path = path.__fspath__()

if not isinstance(path, str):
path = path.decode('utf-8')

path_backend = init_file_backend(path)
super().__init__(backend=path_backend, *args, **kwargs)
def __init__(self, *args, **kwargs):
if len(args) != 0:
path = args[0]
args = args[1:]
if hasattr(path, "__fspath__"):
path = path.__fspath__()
if not isinstance(path, str):
path = path.decode('utf-8')
path_backend = init_file_backend(path)
super().__init__(path_backend, *args, **kwargs)
else:
super().__init__(*args, **kwargs)

@classmethod
def _from_c(cls, ptr, owned):
Expand Down
24 changes: 21 additions & 3 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,31 @@ wrap_repository(git_repository *c_repo)
int
Repository_init(Repository *self, PyObject *args, PyObject *kwds)
{
PyObject *backend;
PyObject *backend = NULL;

if (kwds && PyDict_Size(kwds) > 0) {
PyErr_SetString(PyExc_TypeError,
"Repository takes no keyword arguments");
return -1;
}

if (!PyArg_ParseTuple(args, "O", &backend)) {
if (!PyArg_ParseTuple(args, "|O", &backend)) {
return -1;
}

if (backend == NULL) {
/* Create repository without odb/refdb */
int err = git_repository_new(&self->repo);
if (err != 0) {
Error_set(err);
return -1;
}
self->owned = 1;
self->config = NULL;
self->index = NULL;
return 0;
}

self->repo = PyCapsule_GetPointer(backend, "backend");
if (self->repo == NULL) {
PyErr_SetString(PyExc_TypeError,
Expand Down Expand Up @@ -357,10 +370,15 @@ PyDoc_STRVAR(Repository_path__doc__,
PyObject *
Repository_path__get__(Repository *self, void *closure)
{
const char *c_path;
if (self->repo == NULL)
Py_RETURN_NONE;

return to_path(git_repository_path(self->repo));
c_path = git_repository_path(self->repo);
if (c_path == NULL)
Py_RETURN_NONE;

return to_path(c_path);
}


Expand Down
0