| 943 | "Create a new blob from an IOBase object."); |
| 944 | |
| 945 | PyObject * |
| 946 | Repository_create_blob_fromiobase(Repository *self, PyObject *py_file) |
| 947 | { |
| 948 | git_writestream *stream; |
| 949 | git_oid oid; |
| 950 | PyObject *py_is_readable; |
| 951 | int is_readable; |
| 952 | int err; |
| 953 | |
| 954 | py_is_readable = PyObject_CallMethod(py_file, "readable", NULL); |
| 955 | if (!py_is_readable) { |
| 956 | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 957 | PyErr_SetObject(PyExc_TypeError, py_file); |
| 958 | return NULL; |
| 959 | } |
| 960 | |
| 961 | is_readable = PyObject_IsTrue(py_is_readable); |
| 962 | Py_DECREF(py_is_readable); |
| 963 | |
| 964 | if (!is_readable) { |
| 965 | Py_DECREF(py_file); |
| 966 | PyErr_SetString(PyExc_TypeError, "expected readable IO type"); |
| 967 | return NULL; |
| 968 | } |
| 969 | |
| 970 | err = git_blob_create_fromstream(&stream, self->repo, NULL); |
| 971 | if (err < 0) |
| 972 | return Error_set(err); |
| 973 | |
| 974 | for (;;) { |
| 975 | PyObject *py_bytes; |
| 976 | char *bytes; |
| 977 | Py_ssize_t size; |
| 978 | |
| 979 | py_bytes = PyObject_CallMethod(py_file, "read", "i", 4096); |
| 980 | if (!py_bytes) |
| 981 | return NULL; |
| 982 | |
| 983 | if (py_bytes == Py_None) { |
| 984 | Py_DECREF(py_bytes); |
| 985 | goto cleanup; |
| 986 | } |
| 987 | |
| 988 | if (PyBytes_AsStringAndSize(py_bytes, &bytes, &size)) { |
| 989 | Py_DECREF(py_bytes); |
| 990 | return NULL; |
| 991 | } |
| 992 | |
| 993 | if (size == 0) { |
| 994 | Py_DECREF(py_bytes); |
| 995 | break; |
| 996 | } |
| 997 | |
| 998 | err = stream->write(stream, bytes, size); |
| 999 | Py_DECREF(py_bytes); |
| 1000 | if (err < 0) |
| 1001 | goto cleanup; |
| 1002 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…