最近在搭Git Server,Git提供了一个简单但强大的网页端Gitweb供用户浏览项目 因为需要添加一项小功能,所以把Gitweb的代码研究了一下,下面和大家一起分享一下... 这里,我们有一点前置知识:
Gitweb里面最多的就是对Git输出的字符串的解析,所以看懂正则表达式是必需的,当然,如果我们只想添加功能其实还是很简单的。 Gitweb里面提供了一个全局的字符串函数映射表,这样我们就可以通过前端传入需要操作的函数进行相应操作
1 # we will also need to know the possible actions, for validation 2 our %actions = ( 3 "blame" => \&git_blame, 4 "blame_incremental" => \&git_blame_incremental, 5 "blame_data" => \&git_blame_data, 6 "blobdiff" => \&git_blobdiff, 7 "blobdiff_plain" => \&git_blobdiff_plain, 8 "blob" => \&git_blob, 9 "blob_plain" => \&git_blob_plain, 10 "commitdiff" => \&git_commitdiff, 11 "commitdiff_plain" => \&git_commitdiff_plain, 12 "commit" => \&git_commit, 13 "forks" => \&git_forks, 14 "heads" => \&git_heads, 15 "history" => \&git_history, 16 "log" => \&git_log, 17 #fei add 18 "dl_patch" => \&git_dl_patch, 19 "show_patch_xml" => \&git_write_xml_file, 20 #end fei add 21 "patch" => \&git_patch, 22 "patches" => \&git_patches, 23 "remotes" => \&git_remotes, 24 "rss" => \&git_rss, 25 "atom" => \&git_atom, 26 "search" => \&git_search, 27 "search_help" => \&git_search_help, 28 "shortlog" => \&git_shortlog, 29 "summary" => \&git_summary, 30 "tag" => \&git_tag, 31 "tags" => \&git_tags, 32 "tree" => \&git_tree, 33 "snapshot" => \&git_snapshot, 34 "object" => \&git_object, 35 # those below don't need $project 36 "opml" => \&git_opml, 37 "project_list" => \&git_project_list, 38 "project_index" => \&git_project_index, 39 );
这里的函数映射在Perl里面的实现比较简单,可以参考下这篇文章《perl函数映射》 接下来我们只需要实现我们添加的函数即可。