fixed api changes for index.c

11d9f6b304 in libgit2 changed api for git_index_find()
This commit is contained in:
Nico von Geyso
2013-02-01 13:37:53 +01:00
parent 8cdb8c06be
commit ea8b076b70
2 changed files with 21 additions and 15 deletions

View File

@@ -51,6 +51,7 @@
#if PY_MAJOR_VERSION == 2 #if PY_MAJOR_VERSION == 2
#define to_path(x) to_bytes(x) #define to_path(x) to_bytes(x)
#define to_encoding(x) to_bytes(x) #define to_encoding(x) to_bytes(x)
#define PyLong_FromSize_t PyInt_FromSize_t
#else #else
#define to_path(x) to_unicode(x, Py_FileSystemDefaultEncoding, "strict") #define to_path(x) to_unicode(x, Py_FileSystemDefaultEncoding, "strict")
#define to_encoding(x) PyUnicode_DecodeASCII(x, strlen(x), "strict") #define to_encoding(x) PyUnicode_DecodeASCII(x, strlen(x), "strict")

View File

@@ -169,17 +169,18 @@ PyObject *
Index_find(Index *self, PyObject *py_path) Index_find(Index *self, PyObject *py_path)
{ {
char *path; char *path;
long idx; size_t idx;
int err;
path = PyString_AsString(py_path); path = PyString_AsString(py_path);
if (!path) if (!path)
return NULL; return NULL;
idx = (long)git_index_find(self->index, path); err = git_index_find(&idx, self->index, path);
if (idx < 0) if (err < 0)
return Error_set_str(idx, path); 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 */ /* This is an internal function, used by Index_getitem and Index_setitem */
int size_t
Index_get_position(Index *self, PyObject *value) Index_get_position(Index *self, PyObject *value)
{ {
char *path; char *path;
int idx; size_t idx;
int err;
/* Case 1: integer */ /* Case 1: integer */
if (PyInt_Check(value)) { if (PyInt_Check(value)) {
idx = (int)PyInt_AsLong(value); err = (int)PyInt_AsLong(value);
if (idx == -1 && PyErr_Occurred()) if (err == -1 && PyErr_Occurred())
return -1; return -1;
if (idx < 0) { if (err < 0) {
PyErr_SetObject(PyExc_ValueError, value); PyErr_SetObject(PyExc_ValueError, value);
return -1; return -1;
} }
return idx; return err;
} }
/* Case 2: byte or text string */ /* Case 2: byte or text string */
path = py_path_to_c_str(value); path = py_path_to_c_str(value);
if (!path) if (!path)
return -1; return -1;
idx = git_index_find(self->index, path);
if (idx < 0) { err = git_index_find(&idx, self->index, path);
Error_set_str(idx, path); if (err < 0) {
Error_set_str(err, path);
free(path); free(path);
return -1; return -1;
} }
free(path); free(path);
return idx; return idx;
} }
@@ -260,7 +265,7 @@ Index_contains(Index *self, PyObject *value)
path = py_path_to_c_str(value); path = py_path_to_c_str(value);
if (!path) if (!path)
return -1; return -1;
idx = git_index_find(self->index, path); idx = git_index_find(NULL, self->index, path);
if (idx == GIT_ENOTFOUND) { if (idx == GIT_ENOTFOUND) {
free(path); free(path);
return 0; return 0;