static VALUE rb_git_tree_entry_attributes_GET(VALUE self) { rugged_tree_entry *tree_entry; Data_Get_Struct(self, rugged_tree_entry, tree_entry); return INT2FIX(git_tree_entry_attributes(tree_entry->entry)); }
void add_tree_to_index(git_tree * tree, const char * prefix) { for (size_t i = 0; i < git_tree_entrycount(tree); i++) { /* Get the tree entry */ const git_tree_entry *tree_entry; tree_entry = git_tree_entry_byindex(tree,(unsigned int)i); if (tree_entry == NULL) { printf("Tree entry not found"); libgit_error(); } /* Get the oid of a tree entry */ const git_oid *entry_oid = git_tree_entry_id (tree_entry); /* is a sub directory ? */ git_tree * subtree; if (git_tree_lookup(&subtree, repo, entry_oid) == 0) { char * subprefix = xmalloc(sizeof(char)*1024); const char * dirname = git_tree_entry_name (tree_entry); git2__joinpath(subprefix, prefix, dirname); add_tree_to_index(subtree, subprefix); continue; } char * completename = xmalloc(sizeof(char)*1024); git2__joinpath(completename, prefix, git_tree_entry_name (tree_entry)); git_index_entry source_entry = { {0,0},//git_index_time ctime {0,0},//git_index_time mtime 0,//unsigned int dev 0,//unsigned int ino git_tree_entry_attributes(tree_entry),//unsigned int mode 0,//unsigned int uid 0,//unsigned int gid 0,//git_off_t file_size *entry_oid, 0, 0,//unsigned short flags_extended completename }; git_index_append2(index_cur, &source_entry); } }
static int lookup_object_by_name(request_rec *r, git_repository *repo, const git_oid *tree_oid, const char *name, const git_oid **oid) { const git_tree_entry *entry; int ret; git_tree *tree; char *extname; int type = WIKI_NOTFOUND; ret = git_tree_lookup(&tree, repo, tree_oid); extname = apr_pstrcat(r->pool, name, ".md", NULL); entry = git_tree_entry_byname(tree, extname); //printf("extname: %s\n", extname); if (entry) { type = WIKI_MARKDOWN; }else{ entry = git_tree_entry_byname(tree, name); if (entry) { int attr = git_tree_entry_attributes(entry); if(S_ISDIR(attr)){ type = WIKI_DIR; }else{ type = WIKI_FOUND; } } } git_tree_free(tree); if (entry == NULL) { return WIKI_NOTFOUND; } *oid = git_tree_entry_id(entry); // is this safe? return type; }
int ReadTreeRecursive(git_repository &repo, git_tree * tree, CStringA base, int (*CallBack) (const unsigned char *, const char *, int, const char *, unsigned int, int, void *),void *data) { size_t count = git_tree_entrycount(tree); for (int i = 0; i < count; i++) { const git_tree_entry *entry = git_tree_entry_byindex(tree, i); if (entry == NULL) continue; int mode = git_tree_entry_attributes(entry); if( CallBack(git_tree_entry_id(entry)->id, base, base.GetLength(), git_tree_entry_name(entry), mode, 0, data) == READ_TREE_RECURSIVE ) { if(mode&S_IFDIR) { git_object *object = NULL; git_tree_entry_2object(&object, &repo, entry); if (object == NULL) continue; CStringA parent = base; parent += git_tree_entry_name(entry); parent += "/"; ReadTreeRecursive(repo, (git_tree*)object, parent, CallBack, data); git_object_free(object); } } } return 0; }