TreeEntry * Tree_getitem(Tree *self, PyObject *value) { char *path; git_tree_entry *entry; int err; /* Case 1: integer */ if (PyLong_Check(value)) return Tree_getitem_by_index(self, value); /* Case 2: byte or text string */ path = py_path_to_c_str(value); if (path == NULL) return NULL; err = git_tree_entry_bypath(&entry, self->tree, path); free(path); if (err == GIT_ENOTFOUND) { PyErr_SetObject(PyExc_KeyError, value); return NULL; } if (err < 0) return (TreeEntry*)Error_set(err); /* git_tree_entry_dup is already done in git_tree_entry_bypath */ return wrap_tree_entry(entry); }
TreeEntry * TreeIter_iternext(TreeIter *self) { const git_tree_entry *tree_entry; tree_entry = git_tree_entry_byindex(self->owner->tree, self->i); if (!tree_entry) return NULL; self->i += 1; return (TreeEntry*)wrap_tree_entry(git_tree_entry_dup(tree_entry), self->owner); }
TreeEntry * Tree_getitem_by_index(Tree *self, PyObject *py_index) { int index; const git_tree_entry *entry; index = Tree_fix_index(self, py_index); if (PyErr_Occurred()) return NULL; entry = git_tree_entry_byindex(self->tree, index); if (!entry) { PyErr_SetObject(PyExc_IndexError, py_index); return NULL; } return wrap_tree_entry(git_tree_entry_dup(entry), self); }
TreeEntry * TreeIter_iternext(TreeIter *self) { const git_tree_entry *entry_src; git_tree_entry *entry; entry_src = git_tree_entry_byindex(self->owner->tree, self->i); if (!entry_src) return NULL; self->i += 1; if (git_tree_entry_dup(&entry, entry_src) < 0) { PyErr_SetNone(PyExc_MemoryError); return NULL; } return wrap_tree_entry(entry); }
PyObject * TreeBuilder_get(TreeBuilder *self, PyObject *py_filename) { char *filename; const git_tree_entry *entry_src; git_tree_entry *entry; filename = py_path_to_c_str(py_filename); if (filename == NULL) return NULL; entry_src = git_treebuilder_get(self->bld, filename); free(filename); if (entry_src == NULL) Py_RETURN_NONE; if (git_tree_entry_dup(&entry, entry_src) < 0) { PyErr_SetNone(PyExc_MemoryError); return NULL; } return (PyObject*)wrap_tree_entry(entry); }
TreeEntry * Tree_getitem_by_index(Tree *self, PyObject *py_index) { int index; const git_tree_entry *entry_src; git_tree_entry *entry; index = Tree_fix_index(self, py_index); if (PyErr_Occurred()) return NULL; entry_src = git_tree_entry_byindex(self->tree, index); if (!entry_src) { PyErr_SetObject(PyExc_IndexError, py_index); return NULL; } if (git_tree_entry_dup(&entry, entry_src) < 0) { PyErr_SetNone(PyExc_MemoryError); return NULL; } return wrap_tree_entry(entry); }