我正在尝试以编程方式将gitweb格式的查询字符串映射到cgit查询字符串,以完全过渡到cgit,而不会破坏指向我的存储库的旧的基于gitweb的urls,这些存储库分散在网络上。我见过一些基于正则表达式的URL重写规则,如下所示:
http://www.clearchain.com/blog/posts/cgit-upgrade-gitweb-retired
但我正在尝试理解查询字符串中的变量,以确保正确,并且我将使用一个很小的CGI程序,而不是mod_rewrite或任何对重新映射做的事情。特别是,我不理解h、hb和hp散列的语义,以及它们如何为不同类型的查询映射到cgit的id查询变量。
任何熟悉它们的人都可以给我补充或者给我推荐一个好的资源吗?
发布于 2012-10-23 05:28:59
基本上
如果gitweb使用
id,则hash.id2来自hashb,否则来自hashpbif the gitweb url useshashpb, otherwise fromhashp`.这是我现在使用的脚本(如果您的shell不糟糕,则不会调用外部命令):
#!/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"https://stackoverflow.com/questions/12605791
复制相似问题