blob_fromiobase: addresses review comments.
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
#include "signature.h"
|
#include "signature.h"
|
||||||
#include <git2/odb_backend.h>
|
#include <git2/odb_backend.h>
|
||||||
|
|
||||||
|
extern PyTypeObject PyIOBase_Type;
|
||||||
|
|
||||||
extern PyObject *GitError;
|
extern PyObject *GitError;
|
||||||
|
|
||||||
extern PyTypeObject IndexType;
|
extern PyTypeObject IndexType;
|
||||||
@@ -751,13 +753,15 @@ int read_chunk(char *content, size_t max_length, void *payload)
|
|||||||
|
|
||||||
py_file = (PyObject *)payload;
|
py_file = (PyObject *)payload;
|
||||||
py_bytes = PyObject_CallMethod(py_file, "read", "i", max_length);
|
py_bytes = PyObject_CallMethod(py_file, "read", "i", max_length);
|
||||||
if (!py_bytes) {
|
if (!py_bytes)
|
||||||
return 0;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
if (py_bytes != Py_None) {
|
||||||
bytes = PyBytes_AsString(py_bytes);
|
bytes = PyBytes_AsString(py_bytes);
|
||||||
size = PyBytes_Size(py_bytes);
|
size = PyBytes_Size(py_bytes);
|
||||||
memcpy(content, bytes, size);
|
memcpy(content, bytes, size);
|
||||||
|
}
|
||||||
|
|
||||||
Py_DECREF(py_bytes);
|
Py_DECREF(py_bytes);
|
||||||
return size;
|
return size;
|
||||||
@@ -768,20 +772,28 @@ Repository_create_blob_fromiobase(Repository *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
PyObject *py_is_readable;
|
PyObject *py_is_readable;
|
||||||
|
int is_readable;
|
||||||
PyObject *py_file;
|
PyObject *py_file;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O", &py_file))
|
if (!PyArg_ParseTuple(args, "O!", &PyIOBase_Type, &py_file))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
py_is_readable = PyObject_CallMethod(py_file, "readable", NULL);
|
py_is_readable = PyObject_CallMethod(py_file, "readable", NULL);
|
||||||
if (!py_is_readable || !PyObject_IsTrue(py_is_readable)) {
|
if (!py_is_readable) {
|
||||||
PyErr_SetString(PyExc_TypeError, "expected readable IO type");
|
Py_DECREF(py_file);
|
||||||
Py_DECREF(py_is_readable);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_readable = PyObject_IsTrue(py_is_readable);
|
||||||
Py_DECREF(py_is_readable);
|
Py_DECREF(py_is_readable);
|
||||||
|
|
||||||
|
if (!is_readable) {
|
||||||
|
Py_DECREF(py_file);
|
||||||
|
PyErr_SetString(PyExc_TypeError, "expected readable IO type");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
err = git_blob_create_fromchunks(&oid,
|
err = git_blob_create_fromchunks(&oid,
|
||||||
self->repo,
|
self->repo,
|
||||||
NULL,
|
NULL,
|
||||||
|
Reference in New Issue
Block a user