summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-10 19:03:36 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-10 19:03:36 +0100
commit886207393a0966d674d04efe950e80fb13a2160b (patch)
treefd7b12cdfc63bf45961e3a30a8c63168df25c5b7
parent432f6c3121f8adfb89847eabbc6017c696b22892 (diff)
downloadgall-886207393a0966d674d04efe950e80fb13a2160b.tar.gz
TREE: Replacement parser if git2 available
-rw-r--r--lib/gall/tree.lua32
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