Skip to content

Commit 9baf405

Browse files
update Packbuilder to just use cffi
1 parent 9c1ea03 commit 9baf405

File tree

6 files changed

+36
-297
lines changed

6 files changed

+36
-297
lines changed

pygit2/decl/pack.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ typedef int (*git_packbuilder_progress)(
44
uint32_t total,
55
void *payload);
66

7-
87
int git_packbuilder_new(git_packbuilder **out, git_repository *repo);
8+
void git_packbuilder_free(git_packbuilder *pb);
9+
910
int git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, const char *name);
11+
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name);
12+
1013
size_t git_packbuilder_object_count(git_packbuilder *pb);
11-
unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);
14+
1215
int git_packbuilder_write(git_packbuilder *pb, const char *path, unsigned int mode, git_indexer_progress_cb progress_cb, void *progress_cb_payload);
13-
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name);
1416
uint32_t git_packbuilder_written(git_packbuilder *pb);
1517

16-
const git_oid * git_packbuilder_hash(git_packbuilder *pb);
18+
unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n);

pygit2/packbuilder.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,42 @@
2525

2626

2727
# Import from pygit2
28-
from ._pygit2 import PackBuilder as _PackBuilder
2928
from .errors import check_error
3029
from .ffi import ffi, C
3130
from .utils import to_bytes
3231

3332

34-
class PackBuilder(_PackBuilder):
33+
class PackBuilder:
3534

36-
def __init__(self, *args, **kwargs):
37-
self.repo = args[0]
38-
super().__init__(args[0])
39-
packbuilder_cptr = ffi.new('git_packbuilder **')
40-
ffi.buffer(packbuilder_cptr)[:] = self._pointer[:]
41-
self._packbuilder = packbuilder_cptr[0]
35+
def __init__(self, repo):
36+
37+
cpackbuilder = ffi.new('git_packbuilder **')
38+
err = C.git_packbuilder_new(cpackbuilder, repo._repo)
39+
check_error(err)
40+
41+
self._repo = repo
42+
self._packbuilder = cpackbuilder[0]
43+
self._cpackbuilder = cpackbuilder
44+
45+
46+
@classmethod
47+
def _from_c(cls, repo, ptr):
48+
packbuilder = cls.__new__(cls)
49+
packbuilder._repo = repo
50+
packbuilder._packbuilder = ptr[0]
51+
packbuilder._cpackbuilder = ptr
52+
53+
return packbuilder
54+
55+
@property
56+
def _pointer(self):
57+
return bytes(ffi.buffer(self._packbuilder)[:])
58+
59+
def __del__(self):
60+
C.git_packbuilder_free(self._packbuilder)
61+
62+
def __len__(self):
63+
return C.git_packbuilder_object_count(self._packbuilder)
4264

4365
@staticmethod
4466
def convert_object_to_oid(git_object):
@@ -56,9 +78,6 @@ def add_recursive(self, git_object):
5678
err = C.git_packbuilder_insert_recur(self._packbuilder, oid, ffi.NULL)
5779
check_error(err)
5880

59-
def object_count(self):
60-
return C.git_packbuilder_object_count(self._packbuilder)
61-
6281
def set_max_threads(self, n_threads):
6382
return C.git_packbuilder_set_threads(self._packbuilder, n_threads)
6483

@@ -69,12 +88,3 @@ def write(self, path):
6988
@property
7089
def written_objects_count(self):
7190
return C.git_packbuilder_written(self._packbuilder)
72-
73-
@classmethod
74-
def _from_c(cls, ptr, repo):
75-
cptr = ffi.new('git_packbuilder **')
76-
cptr[0] = ptr
77-
packbuilder = cls.__new__(cls)
78-
packbuilder.repo = repo
79-
super(cls, packbuilder)._from_c(bytes(ffi.buffer(cptr)[:]), repo)
80-
return packbuilder

src/packbuilder.c

Lines changed: 0 additions & 216 deletions
This file was deleted.

src/packbuilder.h

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/pygit2.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "types.h"
3434
#include "utils.h"
3535
#include "repository.h"
36-
#include "packbuilder.h"
3736
#include "oid.h"
3837
#include "options.h"
3938

@@ -42,7 +41,6 @@ PyObject *AlreadyExistsError;
4241
PyObject *InvalidSpecError;
4342

4443
extern PyTypeObject RepositoryType;
45-
extern PyTypeObject PackBuilderType;
4644
extern PyTypeObject OdbType;
4745
extern PyTypeObject OdbBackendType;
4846
extern PyTypeObject OdbBackendPackType;
@@ -337,10 +335,6 @@ PyInit__pygit2(void)
337335
INIT_TYPE(RepositoryType, NULL, PyType_GenericNew)
338336
ADD_TYPE(m, Repository)
339337

340-
/* PackBuilder */
341-
INIT_TYPE(PackBuilderType, NULL, PyType_GenericNew)
342-
ADD_TYPE(m, PackBuilder)
343-
344338
/* Odb */
345339
INIT_TYPE(OdbType, NULL, PyType_GenericNew)
346340
ADD_TYPE(m, Odb)

src/types.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ typedef struct {
5050
int owned; /* _from_c() sometimes means we don't own the C pointer */
5151
} Repository;
5252

53-
/* git_packbuilder */
54-
typedef struct {
55-
PyObject_HEAD
56-
git_packbuilder *packbuilder;
57-
int owned; /* _from_c() sometimes means we don't own the C pointer */
58-
Repository *repo;
59-
} PackBuilder;
60-
61-
6253
typedef struct {
6354
PyObject_HEAD
6455
git_oid oid;

0 commit comments

Comments
 (0)