diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-21 10:29:25 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-21 10:29:25 +0100 |
commit | 8cd22bf8eeee615093f26726ccca4619ebd158d3 (patch) | |
tree | addc94d68734b87d7bacc023d0c31f8fd8ded6c4 /bin | |
parent | 3277160047b257cb1110edca0ceb086b91138f8d (diff) | |
download | gitano-8cd22bf8eeee615093f26726ccca4619ebd158d3.tar.gz |
BIN: gitano-update-hook: Defer generation of trees and treedeltas
Diffstat (limited to 'bin')
-rw-r--r-- | bin/gitano-update-hook | 180 |
1 files changed, 104 insertions, 76 deletions
diff --git a/bin/gitano-update-hook b/bin/gitano-update-hook index 7a5a66f..42588c5 100644 --- a/bin/gitano-update-hook +++ b/bin/gitano-update-hook @@ -102,98 +102,126 @@ end -- Populate the trees -local oldtree, newtree +local function do_expensive_populate_context(context) -if oldsha == nullsha then - oldtree = repo.git:get(gitano.git.tree.empty_sha).content -else - local thing = repo.git:get(oldsha) - if thing.type == "tag" then - thing = thing.content.object - end - if thing.type == "commit" then - oldtree = thing.content.tree.content - else + local oldtree, newtree + + if oldsha == nullsha then oldtree = repo.git:get(gitano.git.tree.empty_sha).content - gitano.log.warn("Odd, old object", oldsha, "is not a commit or tag") + else + local thing = repo.git:get(oldsha) + if thing.type == "tag" then + thing = thing.content.object + end + if thing.type == "commit" then + oldtree = thing.content.tree.content + else + oldtree = repo.git:get(gitano.git.tree.empty_sha).content + gitano.log.warn("Odd, old object", oldsha, "is not a commit or tag") + end end -end -if newsha == nullsha then - newtree = repo.git:get(gitano.git.tree.empty_sha).content -else - local thing = repo.git:get(newsha) - if thing.type == "tag" then - thing = thing.content.object - end - if thing.type == "commit" then - newtree = thing.content.tree.content - else + if newsha == nullsha then newtree = repo.git:get(gitano.git.tree.empty_sha).content - gitano.log.warn("Odd, new object", oldsha, "is not a commit or tag") + else + local thing = repo.git:get(newsha) + if thing.type == "tag" then + thing = thing.content.object + end + if thing.type == "commit" then + newtree = thing.content.tree.content + else + newtree = repo.git:get(gitano.git.tree.empty_sha).content + gitano.log.warn("Odd, new object", oldsha, "is not a commit or tag") + end end -end --- First, populate gitano/starttree and gitano/targettree + -- First, populate gitano/starttree and gitano/targettree -local function set_list(tag, entries) - -- Make the set for direct string tests - for i = 1, #entries do - entries[entries[i]] = true + local function set_list(tag, entries) + -- Make the set for direct string tests + for i = 1, #entries do + entries[entries[i]] = true + end + context[tag] = entries end - context[tag] = entries -end -local function populate_tree(tag, tree) - local flat_tree = gitano.git.tree.flatten(tree) - local names = {} - for fn in pairs(flat_tree) do - names[#names+1] = fn + local function populate_tree(tag, tree) + local flat_tree = gitano.git.tree.flatten(tree) + local names = {} + for fn in pairs(flat_tree) do + names[#names+1] = fn + end + set_list(tag, names) end - set_list(tag, names) -end - -populate_tree("start_tree", oldtree) -populate_tree("target_tree", newtree) --- Now gitano/treedelta -local delta = oldtree:diff_to(newtree) -local targets, added, deleted, modified, renamed, renamedto = - {}, {}, {}, {}, {}, {} - -for i = 1, #delta do - local details = delta[i] - local fname = details.filename - targets[#targets+1] = fname - if details.action == "A" then - added[#added+1] = fname - end - if details.action == "C" and details.score == "100" then - added[#added+1] = fname - end - if details.action == "D" then - deleted[#deleted+1] = fname - end - if details.action == "M" or - ((details.action == "R" or details.action == "C") and - (tonumber(details.score) < 100)) then - modified[#modified+1] = fname - end - if details.action == "R" then - renamed[#renamed+1] = details.src_name - renamedto[#renamedto+1] = fname + populate_tree("start_tree", oldtree) + populate_tree("target_tree", newtree) + + -- Now gitano/treedelta + local delta = oldtree:diff_to(newtree) + local targets, added, deleted, modified, renamed, renamedto = + {}, {}, {}, {}, {}, {} + + for i = 1, #delta do + local details = delta[i] + local fname = details.filename + targets[#targets+1] = fname + if details.action == "A" then + added[#added+1] = fname + end + if details.action == "C" and details.score == "100" then + added[#added+1] = fname + end + if details.action == "D" then + deleted[#deleted+1] = fname + end + if details.action == "M" or + ((details.action == "R" or details.action == "C") and + (tonumber(details.score) < 100)) then + modified[#modified+1] = fname + end + if details.action == "R" then + renamed[#renamed+1] = details.src_name + renamedto[#renamedto+1] = fname + end + + context["treediff/kind/" .. fname] = details.endkind + context["treediff/oldkind/" .. fname] = details.startkind end - context["treediff/kind/" .. fname] = details.endkind - context["treediff/oldkind/" .. fname] = details.startkind + set_list("treediff/targets", targets) + set_list("treediff/added", added) + set_list("treediff/deleted", deleted) + set_list("treediff/modified", modified) + set_list("treediff/renamed", renamed) + set_list("treediff/renamedto", renamedto) +end + +local function defer_generation(key) + context[key] = function(ctx) + -- This populates quite a bit, so we do this + -- test in case someone else got hold of this + -- beforehand and manages to cross the streams + if type(ctx[key]) == "function" then + gitano.log.chat("Treedeltas generating because of:", + key, " Please hold.") + do_expensive_populate_context(ctx) + gitano.log.chat("Treedeltas built, continuing") + end + -- And return what we were meant to be + return ctx[key] + end end -set_list("treediff/targets", targets) -set_list("treediff/added", added) -set_list("treediff/deleted", deleted) -set_list("treediff/modified", modified) -set_list("treediff/renamed", renamed) -set_list("treediff/renamedto", renamedto) +defer_generation "start_tree" +defer_generation "target_tree" +defer_generation "treediff/targets" +defer_generation "treediff/added" +defer_generation "treediff/deleted" +defer_generation "treediff/modified" +defer_generation "treediff/renamed" +defer_generation "treediff/renamedto" -- Run the ruleset given the contextet |