# vim: set ft=nginx: root /var/www/git.gentoo.org/htdocs/; expires modified 15m; # The below is from https://gist.github.com/mricon/345d28f6b68872ec1bd6 # With modifications for Gentoo, and we have cgit at /, vs /cgit # ------- set $_ $scheme://gitweb.gentoo.org; if ($args = "") { rewrite ^/gitweb/?$ $_/? permanent; rewrite ^/$ $_/? permanent; rewrite ^$ $_/? permanent; } if ($args !~ "p=") { break; } if ($args ~ "p=([^;]*)") { set $projectpath /$1; } if ($args !~ "a=") { rewrite ^ $_$projectpath? permanent; } if ($args ~ "a=summary") { rewrite ^ $_$projectpath? permanent; } set $id ""; if ($args ~ "h=([^;]*)") { set $id id=$1; set $h $1; } if ($args ~ "a=commit;") { rewrite ^ $_$projectpath/commit/?$id? permanent; } if ($args ~ "a=tag") { # tags don't map directly rewrite ^ $_$projectpath/commit/?$id? permanent; } # shortlog and log go to the same place if ($args ~ "a=shortlog") { rewrite ^ $_$projectpath/log/?$id? permanent; } if ($args ~ "a=log") { rewrite ^ $_$projectpath/log/?$id? permanent; } # We don't support snapshots, so just redirect to viewing that commit if ($args ~ "a=snapshot") { rewrite ^ $_$projectpath/commit/?$id? permanent; } set $rssref "h=master"; if ($args ~ "h=refs/heads/([^;]+)") { set $rssref "h=$1"; } if ($args ~ "a=atom") { rewrite ^ $_$projectpath/atom/?$rssref? permanent; } if ($args ~ "a=rss") { rewrite ^ $_$projectpath/atom/?$rssref? permanent; } # Generics below if ($args ~ "hb=([^;]*)") { set $hb $1; } if ($args ~ "hp=([^;]*)") { set $hp $1; } if ($args ~ "hpb=([^;]*)") { set $hpb $1; } if ($args ~ "f=([^;]*)") { set $filepath $1; } # # Nginx notoriously doesn't support nested IF/ELSE expressions. # So, don't blame me if what you see below is incomprehensible. # # common combinations of "f=, h=, hb=" set $test ""; if ($args ~ "f=") { set $test "${test}:f"; } if ($args ~ "h=") { set $test "${test}:h"; } if ($args ~ "hp=") { set $test "${test}:hp"; } if ($args ~ "hb=") { set $test "${test}:hb"; } if ($args ~ "hpb=") { set $test "${test}:hpb"; } set $component "tree"; if ($args ~ "a=blob_plain") { set $component "plain"; } if ($args ~ "a=history") { set $component "log"; } if ($args ~ "a=commitdiff") { set $component "commit"; } if ($args ~ "a=commitdiff_plain") { set $component "patch"; } if ($args ~ "a=patch") { set $component "patch"; } if ($args ~ "a=blobdiff") { set $component "diff"; } if ($test = "") { rewrite ^ $_$projectpath/$component/? permanent; } if ($test = ":f") { rewrite ^ $_$projectpath/$component/$filepath? permanent; } if ($test = ":h") { rewrite ^ $_$projectpath/$component/?id=$h? permanent; } if ($test = ":hb") { rewrite ^ $_$projectpath/$component/?id=$hb? permanent; } if ($test = ":h:hb") { rewrite ^ $_$projectpath/$component/?id=$hb? permanent; } if ($test = ":f:h") { rewrite ^ $_$projectpath/$component/$filepath?id=$h? permanent; } if ($test = ":f:hb") { rewrite ^ $_$projectpath/$component/$filepath?id=$hb? permanent; } if ($test = ":f:h:hb") { rewrite ^ $_$projectpath/$component/$filepath?id=$hb? permanent; } # diff-specific if ($test ~ ":f.*:hb:hpb") { rewrite ^ $_$projectpath/$component/$filepath?id=$hb&id2=$hpb? permanent; } if ($test ~ ":f:h:hp") { rewrite ^ $_$projectpath/$component/$filepath?id=$h&id2=$hp? permanent; } if ($test ~ ":hb:hpb") { rewrite ^ $_$projectpath/$component/?id=$hb&id2=$hpb? permanent; } if ($test ~ ":h:hp") { rewrite ^ $_$projectpath/$component/?id=$h&id2=$hp? permanent; } # -------