Converting gitweb query strings to cgit queries
-
04-07-2021 - |
Pergunta
I'm trying to programmatically map gitweb-format query strings to cgit query strings to transition fully to cgit without breaking old gitweb-based urls pointing to my repositories which are scattered here and there around the web. I've seen some regex-based URL rewriting rules such as the following:
http://www.clearchain.com/blog/posts/cgit-upgrade-gitweb-retired
but I'm trying to actually understand the variables in the query string to make sure I get it right, and I'll be using a tiny CGI program rather than mod_rewrite or whatever do to the remapping. In particular, I don't understand the semantics of the h
, hb
, and hp
hashes and how they map to cgit's id
query variables for different types of queries.
Can anyone familiar with them fill me in or point me to a good resource?
Solução
Basically
id
comes fromhashb
if the gitweb url useshashb
, otherwise fromhash
.id2
comes from hashpbif the gitweb url uses
hashpb, otherwise from
hashp`.- the rest is pretty straightforward.
Here's the script I'm using now (no external commands invoked if your shell doesn't suck):
#!/bin/sh
q=$QUERY_STRING
repo=
action=
hash=
hashp=
file=
while test "$q" ; do
x=${q%%;*}
case "$x" in
p=*) repo=${x#p=} ;;
a=*commit*) action=commit ;;
a=*plain*) action=plain ;;
a=*summary*) action= ;;
a=*log*) action=log ;;
a=*) action=${x#a=} ;;
h=*) hash=${x#h=} ;;
hb=*) hashb=${x#hb=} ;;
hp=*) hashp=${x#hp=} ;;
hpb=*) hashpb=${x#hpb=} ;;
f=*) file=${x#f=} ;;
esac
t=${q#*;}
test "$t" = "$q" && break
q=$t
done
test "$hashb" && hash=$hashb
test "$hashpb" && hashp=$hashpb
loc=/cgit
if test "$repo" ; then
loc=$loc/$repo
if test "$action" ; then
loc=$loc/$action
if test "$file" ; then
loc=$loc/$file
fi
fi
if test "$hash" ; then
loc=$loc/\?id=$hash
if test "$hashp" ; then
loc=$loc\&id2=$hashp
fi
fi
fi
printf 'Status: 301 Moved Permanently\nLocation: %s\n\n' "$loc"