diff options
Diffstat (limited to 'lib/gall/tree.lua')
-rw-r--r-- | lib/gall/tree.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gall/tree.lua b/lib/gall/tree.lua index 43f76f1..14d75ba 100644 --- a/lib/gall/tree.lua +++ b/lib/gall/tree.lua @@ -100,6 +100,38 @@ local function treeindex(tree, field) return rawget(tree, field) end +if ll.git2 then + function treeindex(tree, field) + if tree_method[field] then + return tree_method[field] + end + + if not parsed[tree] then + local repo = repos[tree] + local oid = ll.git2.OID.hex(objs[tree].sha) + local treeobj = ll.git2.Tree.lookup(repo.git2.repo, oid) + for i = 0, treeobj:entrycount() - 1 do + local entry = treeobj:entry_byindex(i) + local perm = string.format('0x%08X', entry:filemode()) + local sha = tostring(entry:id()) + local name = entry:name() + local obj = repos[tree]:get(sha) + local type = obj.type + local t = { + permissions = perm, + name = name, + type = type, + obj = obj, + } + rawset(tree, name, t) + end + parsed[tree] = true + end + + return rawget(tree, field) + end +end + local function treetostring(tree) return "<GitTree(" .. tostring(objs[tree].sha) .. ") in " .. tostring(repos[tree]) .. ">" end |