首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将gitweb查询字符串转换为cgit查询

将gitweb查询字符串转换为cgit查询
EN

Stack Overflow用户
提问于 2012-09-26 23:59:14
回答 1查看 487关注 0票数 0

我正在尝试以编程方式将gitweb格式的查询字符串映射到cgit查询字符串,以完全过渡到cgit,而不会破坏指向我的存储库的旧的基于gitweb的urls,这些存储库分散在网络上。我见过一些基于正则表达式的URL重写规则,如下所示:

http://www.clearchain.com/blog/posts/cgit-upgrade-gitweb-retired

但我正在尝试理解查询字符串中的变量,以确保正确,并且我将使用一个很小的CGI程序,而不是mod_rewrite或任何对重新映射做的事情。特别是,我不理解hhbhp散列的语义,以及它们如何为不同类型的查询映射到cgit的id查询变量。

任何熟悉它们的人都可以给我补充或者给我推荐一个好的资源吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-23 05:28:59

基本上

如果gitweb使用

  • id,则hash.
  • id2来自hashb,否则来自hashpbif the gitweb url useshashpb, otherwise fromhashp`.
  • the的rest is pretty straightforward.

这是我现在使用的脚本(如果您的shell不糟糕,则不会调用外部命令):

代码语言:javascript
复制
#!/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"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12605791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档