fixed api changes for index.c
11d9f6b304 in libgit2 changed api for git_index_find()
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
#define to_path(x) to_bytes(x)
|
||||
#define to_encoding(x) to_bytes(x)
|
||||
#define PyLong_FromSize_t PyInt_FromSize_t
|
||||
#else
|
||||
#define to_path(x) to_unicode(x, Py_FileSystemDefaultEncoding, "strict")
|
||||
#define to_encoding(x) PyUnicode_DecodeASCII(x, strlen(x), "strict")
|
||||
|
@@ -169,17 +169,18 @@ PyObject *
|
||||
Index_find(Index *self, PyObject *py_path)
|
||||
{
|
||||
char *path;
|
||||
long idx;
|
||||
size_t idx;
|
||||
int err;
|
||||
|
||||
path = PyString_AsString(py_path);
|
||||
if (!path)
|
||||
return NULL;
|
||||
|
||||
idx = (long)git_index_find(self->index, path);
|
||||
if (idx < 0)
|
||||
return Error_set_str(idx, path);
|
||||
err = git_index_find(&idx, self->index, path);
|
||||
if (err < 0)
|
||||
return Error_set_str(err, path);
|
||||
|
||||
return PyInt_FromLong(idx);
|
||||
return PyLong_FromSize_t(idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,35 +220,39 @@ Index_write(Index *self)
|
||||
}
|
||||
|
||||
/* This is an internal function, used by Index_getitem and Index_setitem */
|
||||
int
|
||||
size_t
|
||||
Index_get_position(Index *self, PyObject *value)
|
||||
{
|
||||
char *path;
|
||||
int idx;
|
||||
size_t idx;
|
||||
int err;
|
||||
|
||||
/* Case 1: integer */
|
||||
if (PyInt_Check(value)) {
|
||||
idx = (int)PyInt_AsLong(value);
|
||||
if (idx == -1 && PyErr_Occurred())
|
||||
err = (int)PyInt_AsLong(value);
|
||||
if (err == -1 && PyErr_Occurred())
|
||||
return -1;
|
||||
if (idx < 0) {
|
||||
if (err < 0) {
|
||||
PyErr_SetObject(PyExc_ValueError, value);
|
||||
return -1;
|
||||
}
|
||||
return idx;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Case 2: byte or text string */
|
||||
path = py_path_to_c_str(value);
|
||||
if (!path)
|
||||
return -1;
|
||||
idx = git_index_find(self->index, path);
|
||||
if (idx < 0) {
|
||||
Error_set_str(idx, path);
|
||||
|
||||
err = git_index_find(&idx, self->index, path);
|
||||
if (err < 0) {
|
||||
Error_set_str(err, path);
|
||||
free(path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(path);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
@@ -260,7 +265,7 @@ Index_contains(Index *self, PyObject *value)
|
||||
path = py_path_to_c_str(value);
|
||||
if (!path)
|
||||
return -1;
|
||||
idx = git_index_find(self->index, path);
|
||||
idx = git_index_find(NULL, self->index, path);
|
||||
if (idx == GIT_ENOTFOUND) {
|
||||
free(path);
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user