Index

resty-gitweb / 72a1883

A git web interface for Lua/OpenResty (you're on it right now!)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1123 Jan 2021 10:52113602dMore code updatesJosh Stockin15022G

Blob @ resty-gitweb / init.lua

text/plain2630 bytesdownload raw
1-- resty-gitweb@init.lua
2-- Preloads scripts and config for OpenResty workers. MUST be called by init_by_lua_file.
3
4-- Copyright (c) 2020 Joshua 'joshuas3' Stockin
5-- <https://git.joshstock.in/resty-gitweb>
6-- This software is licensed under the MIT License.
7
8
9-- Check for RESTY_GITWEB_ENABLE in environment variables
10if os.getenv("RESTY_GITWEB_ENABLE") == nil then
11 ngx.log(ngx.ERR, "RESTY_GITWEB_ENABLE not found in environment variables; are you missing an `env` directive?")
12 os.exit(1)
13end
14
15-- In production mode?
16PRODUCTION = os.getenv("RESTY_GITWEB_ENV") == "PROD"
17
18-- Get config path
19local resty_gitweb_config = os.getenv("RESTY_GITWEB_CONFIG")
20if resty_gitweb_config == nil then
21 ngx.log(ngx.ERR, "RESTY_GITWEB_CONFIG not found in environment variables; are you missing an `env` directive?")
22 os.exit(1)
23elseif resty_gitweb_config == "" then
24 ngx.log(ngx.ERR, "RESTY_GITWEB_CONFIG is empty")
25 os.exit(1)
26end
27
28-- Require external modules
29local ffi = require "ffi"
30local lyaml = require "lyaml"
31local puremagic = require "puremagic"
32
33-- Load YAML configuration
34local yaml_config_file = io.open(resty_gitweb_config)
35CONFIG = lyaml.load(yaml_config_file:read("*a"))
36yaml_config_file:close()
37
38-- Load libgit2 into FFI and initialize
39ffi.include = function(header)
40 local p = io.popen("echo '#include <"..header..">' | gcc -E -")
41 local c = {}
42 while true do
43 local line = p:read()
44 if line then
45 if not line:match("^#") then
46 table.insert(c, line)
47 end
48 else
49 break
50 end
51 end
52 p:close()
53 ffi.cdef(table.concat(c, "\n"))
54end
55
56ffi.include("git2.h")
57git2 = ffi.load("git2")
58git2.git_libgit2_init()
59
60-- Require internal modules
61local git = require "git/git"
62local git_git2_error = require "git/git2_error"
63local git_find_rev = require "git/find_rev"
64local git_read_blob = require "git/read_blob"
65local git_repo = require "git/repo"
66
67--local pages = require "pages/pages"
68local pages_blob = require "pages/blob"
69local pages_commit = require "pages/commit"
70local pages_download = require "pages/download"
71local pages_index = require "pages/index"
72local pages_log = require "pages/log"
73local pages_row = require "pages/raw"
74local pages_refs = require "pages/refs"
75local pages_tree = require "pages/tree"
76
77--local utils = require "utils/utils"
78local builder = require "utils/builder"
79local nav = require "utils/nav"
80local parse_uri = require "utils/parse_uri"
81local tabulate = require "utils/tabulate"
82local utils = require "utils/utils"
83