RewriteEngine On # Unescape any slashes in the branch portion of the query string so # that we don't have to worry about whether or not they are encoded # later. This is a recursive rule to handle multiple slashes. RewriteCond %{QUERY_STRING} "^(.*)h=([^&]+)%2F([^&]+)(.*)$" RewriteRule "^/(.*)$" "/$1?%1h=%2/%3%4" [N] # Map whitelabeled project git sites with repository prefixes RewriteCond %{HTTP_HOST} ^git\.airshipit\.org$ [NC] RewriteRule "^/(cgit/|)airship-(.*)$" "/$1airship/$2" RewriteCond %{HTTP_HOST} ^git\.starlingx\.io$ [NC] RewriteRule "^/(cgit/|)stx-(.*)$" "/$1starlingx/$2" RewriteCond %{HTTP_HOST} ^git\.zuul-ci\.org$ [NC] RewriteRule "^/(cgit/|)((nodepool|zuul).*)$" "/$1zuul/$2" ################################### # summary # ignore all args RewriteRule "^/cgit/([^/]+)/([^/]+)/?$" "https://opendev.org/$1/$2/" [L,QSD] ################################### # refs tab -> branches tab # ignore all args # The cgit refs tab shows tags+branches, the branches tab in gitea is # the closest linkable url RewriteRule "^/cgit/([^/]+)/([^/]+)/refs/?" "https://opendev.org/$1/$2/branches" [L,QSD] ################################### # log tab (with file) -> commits tab # h= RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/([^/]+)/([^/]+)/log/?(.*)" "https://opendev.org/$1/$2/commits/branch/%1/$3" [L,QSD] # no args RewriteRule "^/cgit/([^/]+)/([^/]+)/log/?(.*)" "https://opendev.org/$1/$2/commits/branch/master/$3" [L,QSD] ##################################################### # tree tab (with file) -> tree tab # id= # h=&id= (id) # if there's a commit, it takes precedence RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/tree/?(.*)" "https://opendev.org/$1/$2/src/commit/%1/$3" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/tree/?(.*)" "https://opendev.org/$1/$2/src/commit/%1/$3" [L,QSD] # h= # if there's no commit, but a branch: RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/tree/?(.*)" "https://opendev.org/$1/$2/src/branch/%1/$3" [L,QSD] # if there's no args: RewriteRule "^/cgit/(.*?)/(.*?)/tree/?(.*)" "https://opendev.org/$1/$2/src/branch/master/$3" [L,QSD] ##################################################### # plain link without file -> tree tab # id= # h=&id= (id) # if there's a commit, it takes precedence RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?$" "https://opendev.org/$1/$2/src/commit/%1/$3" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?$" "https://opendev.org/$1/$2/src/commit/%1/$3" [L,QSD] # h= # if there's no commit, but a branch: RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?$" "https://opendev.org/$1/$2/src/branch/%1/$3" [L,QSD] # if there's no args: RewriteRule "^/cgit/(.*?)/(.*?)/plain/?$" "https://opendev.org/$1/$2/src/branch/master/$3" [L,QSD] ##################################################### # plain link (with file) -> raw # same as tree # id= # h=&id= (id) # if there's a commit, it takes precedence RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?(.*)" "https://opendev.org/$1/$2/raw/commit/%1/$3" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?(.*)$" "https://opendev.org/$1/$2/raw/commit/%1/$3" [L,QSD] # h= # if there's no commit, but a branch: RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/plain/?(.*)" "https://opendev.org/$1/$2/raw/branch/%1/$3" [L,QSD] # if there's no args: RewriteRule "^/cgit/(.*?)/(.*?)/plain/?(.*)" "https://opendev.org/$1/$2/raw/branch/master/$3" [L,QSD] ###################### # commit tab (with file) -> commit screen (without file) # id= # id=&h= RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/commit/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/commit/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= # The commit tab in cgit will show the branch-tip commit in this case. # There is not a comprable page in gitea, so we redirect to the branch # log (which has the branch-tip commit at the top of the list). We # include the file if it's there to further restrict the list of # commits RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/commit/?(.*)" "https://opendev.org/$1/$2/commits/branch/%1/$3" [L,QSD] # no args # Same, but with master branch RewriteRule "^/cgit/(.*?)/(.*?)/commit/?(.*)" "https://opendev.org/$1/$2/commits/branch/master/$3" [L,QSD] ###################### # diff (with file) -> commit screen (without file) # Gitea doesn't handle arbitrary diffs, so just show the commit page for id. # We do the same thing as for the commit tab. # id=&id2= # id= # id=&h= RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/diff/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/diff/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/diff/?(.*)" "https://opendev.org/$1/$2/commits/branch/%1/$3" [L,QSD] # no args RewriteRule "^/cgit/(.*?)/(.*?)/diff/?(.*)" "https://opendev.org/$1/$2/commits/branch/master/$3" [L,QSD] ###################### # patch (with file) # Gitea doesn't handle generating patch files, so just show the commit page. # We do the same thing as for the commit tab. # id= # id=&h= RewriteCond %{QUERY_STRING} id=([\w]+) RewriteRule "^/cgit/(.*?)/(.*?)/patch/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= # we have a commit pointed for a head RewriteCond %{QUERY_STRING} h=([0-9a-f]{40}) RewriteRule "^/cgit/(.*?)/(.*?)/patch/?(.*)" "https://opendev.org/$1/$2/commit/%1" [L,QSD] # h= RewriteCond %{QUERY_STRING} h=([\w/]+) RewriteRule "^/cgit/(.*?)/(.*?)/patch/?(.*)" "https://opendev.org/$1/$2/commits/branch/%1/$3" [L,QSD] # no args RewriteRule "^/cgit/(.*?)/(.*?)/patch/?(.*)" "https://opendev.org/$1/$2/commits/branch/master/$3" [L,QSD] ##################### # tag # Gitea doesn't have a dedicated tag page, but if you click a tag in # gitea, it takes you to the source tree view for that tag, which has # the tagged commit at the top of the table. RewriteCond %{QUERY_STRING} h=([\w/\.]+) RewriteRule "^/cgit/(.*?)/(.*?)/tag/?" "https://opendev.org/$1/$2/src/tag/%1" [L,QSD] ##################### # Any other unknown cgit url, redirect to / RewriteRule "^/cgit" "https://opendev.org/" [L,QSD] ##################### # Non cgit URLs RewriteRule "^/(.*)$" "https://opendev.org/$1" [L]