mercurial(Hg) Server 搭建 过程记录

mercurial(Hg) Server 搭建 过程记录

1、  环境说明

只是测试搭建,环境为本机开发环境:win 8.1 + IIS8.5

 

软件准备:

 

2、  软件安装

先安装Python2.7, 然后安装Mercurial的Python package, 然后安装TortoiseHg, 最后安装url rewrite组件。

3、 在D盘建一个数据仓库总目录, 例如D:\Mercurial\ hgweb, 所有的repositories都将位于这个目录之下。

 

(Repositories是仓库文件夹,下面存放多个代码仓库。这里为了方便放入D:\Mercurial\ hgweb路径下,其实也可放在别的路径,只要在配置文件中配置对就行了)

4、  IIS下建立网站hg

 

双击Handlers Mappings, 右侧会出现一个actions列表, 点击Add Managed Handler, 会弹出一个新建窗口, 按如下图所示填写这个新建窗口:

 

 

 

5、 在D:\Mercurial\ hgweb路径下建立hgweb.cgi文件,内容如下:

#!D:/Python27/python.exe

#

# An example FastCGI script for use with flup, edit as necessary

# Path to repo or hgweb config to serve (see 'hg help hgweb')

config = "D:/Mercurial/hgweb/hgweb.config"

 

# Uncomment and adjust if Mercurial is not installed system-wide

# (consult "installed modules" path from 'hg debuginstall'):

import sys; sys.path.insert(0, "D:\\Python27\\Lib\\site-packages\\mercurial")

 

# Uncomment to send python tracebacks to the browser if an error occurs:

from mercurial import demandimport;

demandimport.enable()

import cgitb

cgitb.enable()

#import os

#os.environ["HGENCODING"] = "UTF-8"

from mercurial.hgweb.hgwebdir_mod import hgwebdir

import mercurial.hgweb.wsgicgi as wsgicgi

application = hgwebdir(config) 

wsgicgi.launch(application)

其中D:/Python27/python.exe为python安装路径,

config = "D:/Mercurial/hgweb/hgweb.config" (下一步将建立的文件)

D:\\Python27\\Lib\\site-packages\\mercurial 为安装Mercurial的Python package路径。

6、 再在D:\Mercurial\ hgweb下新建一个文本文件, 重命名为hgweb.config,内容为:

[paths]

/Repositories/ = D:/Mercurial/hgweb/Repositories/*

[web]

encoding = UTF-8

push_ssl = false

allow_read = *

allow_push = *

baseurl = /

 即可尝试浏览http://localhost/hgweb.cgi . 应该能看到如下界面:

(由于80端口有其他网站,此处用的83端口,内部使用,所以安全问题不大关注 设置push_ssl = false)

 

 

7、 创建网站时会自动生成个web.config文件,用任意文本编辑器打开此文件, 在System.webServer节下的handlers节下面增加一个rewrite节

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <configuration>
 4 
 5     <system.webServer>
 6 
 7        <handlers>
 8 
 9             <add name="CGIHandler" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="D:\Python27\python.exe -u &quot;%s&quot;" resourceType="Unspecified" requireAccess="Script" />
10 
11        </handlers>
12 
13       <rewrite>
14 
15         <rules>
16 
17           <clear />
18 
19           <rule name="hgweb.cgi" enabled="true" patternSyntax="Wildcard">
20 
21             <match url="*" />
22 
23             <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
24 
25               <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
26 
27             </conditions>
28 
29             <action type="Rewrite" url="hgweb.cgi/{R:1}" />
30 
31           </rule>
32 
33         </rules>
34 
35       </rewrite>
36 
37         <security>
38 
39             <authorization>
40 
41                 <remove users="*" roles="" verbs="" />
42 
43                 <add accessType="Allow" users="?" />
44 
45             </authorization>
46 
47         </security>
48 
49     </system.webServer>
50 
51 </configuration>

 

这样直接用http://localhost/ 就可访问和http://localhost/hgweb.cgi一样的效果。

8、 用Hg在Repositories中创建仓库

 

然后就可以在客户端clone仓库、以及push到服务器了。

 

在push时可能会遇到权限问题,解决方法:

1)         确定IIS_IUSERS有读写D:/Mercurial/hgweb文件夹的权限;

2)         修改仓库中的.hg/hgrc文件

添加如下内容

[web]

allow_read = *

allow_push = *

push_ssl = false

(也没太弄明白为什么,hgweb.config中也有这些配置,和这里有啥区别?但是在这里添加后确实可以PUSH了)

 

参考网址:

http://www.cnblogs.com/Moosdau/archive/2012/03/06/2382769.html

http://blog.csdn.net/delphinew/article/details/5440723

http://bz.selenic.com/show_bug.cgi?id=2954

posted @ 2015-06-08 13:50  clarlespeng  阅读(884)  评论(0编辑  收藏  举报