stagit

static git page generator
git clone git://git.sgregoratto.me/stagit
Log | Files | Refs | README | LICENSE

README.md (3868B)


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