refspec: borrow the C string
This commit is contained in:
@@ -105,15 +105,16 @@ PyDoc_STRVAR(Refspec_src_matches__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_src_matches(Refspec *self, PyObject *py_str)
|
Refspec_src_matches(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
char *str;
|
const char *str;
|
||||||
|
PyObject *tstr;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
str = py_str_to_c_str(py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
if (!str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = git_refspec_src_matches(self->refspec, str);
|
res = git_refspec_src_matches(self->refspec, str);
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@@ -129,15 +130,16 @@ PyDoc_STRVAR(Refspec_dst_matches__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_dst_matches(Refspec *self, PyObject *py_str)
|
Refspec_dst_matches(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
char *str;
|
const char *str;
|
||||||
|
PyObject *tstr;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
str = py_str_to_c_str(py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
if (!str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = git_refspec_dst_matches(self->refspec, str);
|
res = git_refspec_dst_matches(self->refspec, str);
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@@ -153,24 +155,25 @@ PyDoc_STRVAR(Refspec_transform__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_transform(Refspec *self, PyObject *py_str)
|
Refspec_transform(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
char *str, *trans;
|
const char *str;
|
||||||
|
char *trans;
|
||||||
int err, len, alen;
|
int err, len, alen;
|
||||||
PyObject *py_trans;
|
PyObject *py_trans, *tstr;
|
||||||
|
|
||||||
str = py_str_to_c_str(py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
alen = len = strlen(str);
|
alen = len = strlen(str);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
alen *= alen;
|
alen *= alen;
|
||||||
trans = malloc(alen);
|
trans = malloc(alen);
|
||||||
if (!trans) {
|
if (!trans) {
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = git_refspec_transform(trans, alen, self->refspec, str);
|
err = git_refspec_transform(trans, alen, self->refspec, str);
|
||||||
} while(err == GIT_EBUFS);
|
} while(err == GIT_EBUFS);
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
free(trans);
|
free(trans);
|
||||||
@@ -193,24 +196,25 @@ PyDoc_STRVAR(Refspec_rtransform__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Refspec_rtransform(Refspec *self, PyObject *py_str)
|
Refspec_rtransform(Refspec *self, PyObject *py_str)
|
||||||
{
|
{
|
||||||
char *str, *trans;
|
const char *str;
|
||||||
|
char *trans;
|
||||||
int err, len, alen;
|
int err, len, alen;
|
||||||
PyObject *py_trans;
|
PyObject *py_trans, *tstr;
|
||||||
|
|
||||||
str = py_str_to_c_str(py_str, NULL);
|
str = py_str_borrow_c_str(&tstr, py_str, NULL);
|
||||||
alen = len = strlen(str);
|
alen = len = strlen(str);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
alen *= alen;
|
alen *= alen;
|
||||||
trans = malloc(alen);
|
trans = malloc(alen);
|
||||||
if (!trans) {
|
if (!trans) {
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = git_refspec_rtransform(trans, alen, self->refspec, str);
|
err = git_refspec_rtransform(trans, alen, self->refspec, str);
|
||||||
} while(err == GIT_EBUFS);
|
} while(err == GIT_EBUFS);
|
||||||
free(str);
|
Py_DECREF(tstr);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
free(trans);
|
free(trans);
|
||||||
|
Reference in New Issue
Block a user