1 # stagit 2 3 Fork of [stagit](https://git.codemadness.org/stagit/) a static git page 4 generator, it generates static HTML pages for a git repository. 5 6 ## Changes with the original upstream 7 8 - Add css ids selectors to common elements 9 - Entire row of tables clickable 10 - Shows a preview of the README (if available) (see dependencies) 11 - Show folders instead of tree view (and show them first) 12 13 14 ## Usage 15 16 Make files per repository: 17 18 $ mkdir -p htmlroot/htmlrepo1 && cd htmlroot/htmlrepo1 19 $ stagit path/to/gitrepo1 20 repeat for other repositories 21 $ ... 22 23 Make index file for repositories: 24 25 $ cd htmlroot 26 $ stagit-index path/to/gitrepo1 \ 27 path/to/gitrepo2 \ 28 path/to/gitrepo3 > index.html 29 30 31 ## Build and install 32 33 $ make 34 # make install 35 36 37 ## Dependencies 38 39 - C compiler (C99). 40 - libc (tested with OpenBSD, FreeBSD, NetBSD, Linux: glibc and musl). 41 - libgit2 (v0.22+). 42 - [md4c](https://github.com/mity/md4c) (README preview) 43 - POSIX make (optional). 44 45 46 ## Documentation 47 48 See man pages: stagit(1) and stagit-index(1). 49 50 51 ## Building a static binary 52 53 It may be useful to build static binaries, for example to run in a chroot. 54 55 It can be done like this at the time of writing (v0.24): 56 57 cd libgit2-src 58 59 # change the options in the CMake file: CMakeLists.txt 60 BUILD_SHARED_LIBS to OFF (static) 61 CURL to OFF (not needed) 62 USE_SSH OFF (not needed) 63 THREADSAFE OFF (not needed) 64 USE_OPENSSL OFF (not needed, use builtin) 65 66 mkdir -p build && cd build 67 cmake ../ 68 make 69 make install 70 71 72 ## Extract owner field from git config 73 74 A way to extract the gitweb owner for example in the format: 75 76 [gitweb] 77 owner = Name here 78 79 Script: 80 81 #!/bin/sh 82 awk '/^[ ]*owner[ ]=/ { 83 sub(/^[^=]*=[ ]*/, ""); 84 print $0; 85 }' 86 87 88 ## Set clone URL for a directory of repos 89 90 #!/bin/sh 91 cd "$dir" 92 for i in *; do 93 test -d "$i" && echo "git://git.codemadness.org/$i" > "$i/url" 94 done 95 96 97 ## Update files on git push 98 99 Using a post-receive hook the static files can be automatically updated. 100 Keep in mind git push -f can change the history and the commits may need 101 to be recreated. This is because stagit checks if a commit file already 102 exists. It also has a cache (-c) option which can conflict with the new 103 history. See stagit(1). 104 105 git post-receive hook (repo/.git/hooks/post-receive): 106 107 #!/bin/sh 108 # detect git push -f 109 force=0 110 while read -r old new ref; do 111 hasrevs=$(git rev-list "$old" "^$new" | sed 1q) 112 if test -n "$hasrevs"; then 113 force=1 114 break 115 fi 116 done 117 118 # remove commits and .cache on git push -f 119 #if test "$force" = "1"; then 120 # ... 121 #fi 122 123 # see example_create.sh for normal creation of the files. 124 125 126 ## Create .tar.gz archives by tag 127 128 #!/bin/sh 129 name="stagit" 130 mkdir -p archives 131 git tag -l | while read -r t; do 132 f="archives/${name}-$(echo "${t}" | tr '/' '_').tar.gz" 133 test -f "${f}" && continue 134 git archive \ 135 --format tar.gz \ 136 --prefix "${t}/" \ 137 -o "${f}" \ 138 -- \ 139 "${t}" 140 done 141 142 143 ## Features 144 145 - Log of all commits from HEAD. 146 - Log and diffstat per commit. 147 - Show file tree with linkable line numbers. 148 - Show references: local branches and tags. 149 - Detect README and LICENSE file from HEAD and link it as a webpage. 150 - Detect submodules (.gitmodules file) from HEAD and link it as a webpage. 151 - Atom feed of the commit log (atom.xml). 152 - Atom feed of the tags/refs (tags.xml). 153 - Make index page for multiple repositories with stagit-index. 154 - After generating the pages (relatively slow) serving the files is very fast, 155 simple and requires little resources (because the content is static), only 156 a HTTP file server is required. 157 - Usable with text-browsers such as dillo, links, lynx and w3m. 158 159 160 ## Cons 161 162 - Not suitable for large repositories (2000+ commits), because diffstats are 163 an expensive operation, the cache (-c flag) is a workaround for this in 164 some cases. 165 - Not suitable for large repositories with many files, because all files are 166 written for each execution of stagit. This is because stagit shows the lines 167 of textfiles and there is no "cache" for file metadata (this would add more 168 complexity to the code). 169 - Not suitable for repositories with many branches, a quite linear history is 170 assumed (from HEAD). 171 172 In these cases it is better to just use cgit or possibly change stagit to 173 run as a CGI program. 174 175 - Relatively slow to run the first time (about 3 seconds for sbase, 176 1500+ commits), incremental updates are faster. 177 - Does not support some of the dynamic features cgit has, like: 178 - Snapshot tarballs per commit. 179 - File tree per commit. 180 - History log of branches diverged from HEAD. 181 - Stats (git shortlog -s). 182 183 This is by design, just use git locally.