-- resty-gitweb@pages/log.lua -- Log page builder -- Copyright (c) 2020 Joshua 'joshuas3' Stockin -- -- This software is licensed under the MIT License. local utils = require("utils/utils") local git = require("git/git") local builder = require("utils/builder") local tabulate = require("utils/tabulate") local nav = require("utils/nav") local _M = function(repo, repo_dir, branch, n, skip) n = tonumber(n or 20) skip = tonumber(skip or 0) local build = builder:new() -- Breadcrumb navigation and repository description local breadcrumb_nav = { {string.format("/%s", repo.name), repo.name}, {string.format("/%s/tree/%s", repo.name, branch.name), branch.name}, {string.format("/%s/log/%s", repo.name, branch.name), "log"} } build:add("

"..nav(breadcrumb_nav, " / ").."

") build:add("

"..repo.description.."

") -- Navigation links local navlinks = { {string.format("/%s/download", repo.name), "Download"}, {string.format("/%s/refs", repo.name), "Refs"}, {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} } for _, special in pairs(repo.specialfiles) do -- create nav items for special files local split = string.split(special, " ") table.insert(navlinks, { string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), split[1] }) end build:add([[") -- Commits table build:add("

Commits

") local commits_head = git.log(repo_dir, branch.name, path, n, skip, true) local this_page = string.format("/%s/log/%s", repo.name, branch.name) -- Build controls local controls = [[
]] local prev = false if skip ~= 0 then -- previous page? local params = "" if skip - n > 0 then params = params.."?skip="..tostring(tonumber(skip) - tonumber(n)) end if n ~= 20 then if params ~= "" then params = params.."&" else params = params.."?" end params = params.."n="..tostring(n) end controls = controls..[[<< Previous Page]] prev = true end if git.count(repo_dir, commits_head[#commits_head].hash) ~= 1 then -- check if last commit in this list is actually the last -- it's not the last, create a "next page" button local params = "" params = params.."?skip="..tostring(skip+n) if n ~= 20 then params = params.."&n="..tostring(n) end if prev then controls = controls..[[|]] end controls = controls..[[Next Page >>]] end controls = controls..[[
]] controls = controls.."
" build:add(controls) -- Build commit table local commits_table_data = {} commits_table_data.class = "log" commits_table_data.headers = { {"count", [[{#}]]}, {"timestamp", "Time"}, {"shorthash", "Hash"}, {"subject", "Subject"}, {"author", "Author"}, {"changed_files", [[#]]}, {"changed_plus", [[(+)]]}, {"changed_minus", [[(-)]]}, {"gpggood", [[GPG?]]} } commits_table_data.rows = {} for i, commit in pairs(commits_head) do table.insert(commits_table_data.rows, { git.count(repo_dir, commit.hash), utils.iso8601(commit.timestamp), string.format([[%s]], repo.name, commit.hash, commit.shorthash), utils.html_sanitize(commit.subject), string.format([[%s]], commit.email, utils.html_sanitize(commit.author)), commit.diff.num, commit.diff.plus, commit.diff.minus, commit.gpggood }) end -- Add build:add(tabulate(commits_table_data)) build:add(controls) return build end return _M