static int builder_filter( const git_tree_entry *entry, void *payload ) { struct filter_payload *fp = (struct filter_payload *) payload; if( entry == NULL ) { luaL_error( fp->L, "no input entry" ); return -1; } lua_pushvalue( fp->L, fp->function ); git_tree_entry** e = (git_tree_entry**) lua_newuserdata( fp->L, sizeof( git_tree_entry* ) ); if( git_tree_entry_dup( e, entry )) { luaL_error( fp->L, "dup failed" ); return -1; } ltk_setmetatable( fp->L, LUAGI_TREE_ENTRY_FUNCS ); if(lua_pcall( fp->L, 1, 1, 0) ) { luaL_error( fp->L, "failure calling function" ); return -1; } int ret = lua_toboolean( fp->L, -1 ); lua_pop( fp->L, 1 ); return ret; }
int luagi_tree_builder_insert( lua_State *L ) { git_treebuilder** builder = checktreebuilder( L ); const char* filename = luaL_checkstring( L, 2 ); git_oid oid; int ret = luagi_check_oid( &oid, L, 3 ); if( ret != 0 ) { lua_pushnil( L ); lua_pushstring( L, "invalid ref" ); return 2; } const char* filemode = luaL_checkstring( L, 4 ); git_filemode_t mode = 0; if( strncmp( filemode, TREE, strlen( TREE ) ) == 0 ) { mode = GIT_FILEMODE_TREE; } else if( strncmp( filemode, BLOB, strlen( BLOB ) ) == 0 ) { mode = GIT_FILEMODE_BLOB; } else if( strncmp( filemode, BLOB_EXECUTABLE, strlen( BLOB_EXECUTABLE ) ) == 0 ) { mode = GIT_FILEMODE_BLOB_EXECUTABLE; } else if( strncmp( filemode, LINK, strlen( LINK ) ) == 0 ) { mode = GIT_FILEMODE_LINK; } else if( strncmp( filemode, COMMIT, strlen( COMMIT ) ) == 0 ) { mode = GIT_FILEMODE_COMMIT; } if( mode == 0 ) { lua_pushnil( L ); lua_pushstring( L, "invalid filemode" ); return 2; } git_tree_entry** entry = (git_tree_entry**) lua_newuserdata( L, sizeof( git_tree_entry* ) ); const git_tree_entry *e; ret = git_treebuilder_insert( &e, *builder, filename, &oid, mode ); if( ret != 0 ) { return ltk_push_git_error( L ); } ret = git_tree_entry_dup( entry, e ); if( ret != 0 ) { return ltk_push_git_error( L ); } ltk_setmetatable( L, LUAGI_TREE_ENTRY_FUNCS ); return 1; }
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); }
static int walk_callback_wrapper (const char *root, const git_tree_entry *entry, gpointer payload) { gint ret; GgitTreeEntry *wentry; WalkInfo *info = (WalkInfo *)payload; wentry = _ggit_tree_entry_wrap (git_tree_entry_dup(entry), TRUE); ret = info->callback(root, wentry, info->user_data); ggit_tree_entry_unref (wentry); return ret; }
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); }
int luagi_tree_builder_get( lua_State *L ) { git_treebuilder** builder = checktreebuilder( L ); const char* filename = luaL_checkstring( L, 2 ); const git_tree_entry* entry = git_treebuilder_get( *builder, filename ); if( entry == NULL ) { lua_pushnil( L ); lua_pushstring( L, "no result found" ); return 2; } git_tree_entry** e = (git_tree_entry**) lua_newuserdata( L, sizeof( git_tree_entry*) ); int ret = git_tree_entry_dup( e, entry ); if( ret != 0 ) { lua_pushnil( L ); lua_pushfstring( L, "git_tree_entry_dup failed %d", ret ); return 2; } ltk_setmetatable( L, LUAGI_TREE_ENTRY_FUNCS ); return 1; }
static int walk_callback_wrapper (const char *root, const git_tree_entry *entry, gpointer payload) { gint ret; GgitTreeEntry *wentry; WalkInfo *info = (WalkInfo *)payload; git_tree_entry *dest; ret = git_tree_entry_dup (&dest, entry); if (ret == GIT_OK) { wentry = _ggit_tree_entry_wrap (dest, TRUE); ret = info->callback(root, wentry, info->user_data); ggit_tree_entry_unref (wentry); } return ret; }
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); }