summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2013-04-24 21:24:02 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2013-04-24 21:24:02 +0100
commit8056c2524b478575b2a46a724c79f2b18d59a806 (patch)
tree1bf43d87feff3cc5558953305ab43e6e8229675b
parent7234439d6f458ba86ffbf687373886c7683bc3d3 (diff)
downloadgitano-8056c2524b478575b2a46a724c79f2b18d59a806.tar.gz
REPO: Add a mechanism to update the info/web/last-modified file
-rw-r--r--lib/gitano/repository.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/gitano/repository.lua b/lib/gitano/repository.lua
index a96dbc2..1634182 100644
--- a/lib/gitano/repository.lua
+++ b/lib/gitano/repository.lua
@@ -504,6 +504,55 @@ function repo_method:rename_to(somename)
return true
end
+function repo_method:update_modified_date(shas)
+ -- Update the info/web/last-modified
+ local dirpath = self:fs_path() .. "/info/web"
+ local modfile = dirpath .. "/last-modified"
+
+ if not util.mkdir_p(dirpath) then
+ return false, "Cannot prepare path leading to info file."
+ end
+
+ local last_mod_mtime = 0
+ local last_mod_offset = "+0000"
+ local function update_based_on(mtime, offset)
+ mtime = tonumber(mtime)
+ if mtime > last_mod_mtime then
+ last_mod_mtime = mtime
+ last_mod_offset = offset
+ end
+ end
+ local f = io.open(modfile, "r")
+ if f then
+ local s = f:read("*l")
+ if s then
+ local cur_mod_time, cur_mod_offset = s:find("^([0-9]+) ([+-][0-9]+)$")
+ if cur_mod_time then
+ update_based_on(cur_mod_time, cur_mod_offset)
+ end
+ end
+ f:close()
+ end
+ for _, sha in pairs(shas) do
+ local obj = self.git:get(sha)
+ if obj.type == "tag" then
+ local tagger = obj.content.tagger
+ update_based_on(tagger.unixtime, tagger.timezone)
+ elseif obj.type == "commit" then
+ local committer, author = obj.content.committer, obj.content.author
+ update_based_on(committer.unixtime, committer.timezone)
+ update_based_on(author.unixtime, author.timezone)
+ end
+ end
+ f = io.open(modfile, "w")
+ if not f then
+ return false, "Could not open info/web/last-modified for writing"
+ end
+ f:write(("%d %s\n"):format(last_mod_mtime, last_mod_offset))
+ f:close()
+ return true
+end
+
function repo_method:save_admin(reason, username)
local cursha = self.git:get_ref(adminrefname)
local curcommit = self.git:get(cursha)