在Windows使用apache搭建Mercurial版本控制服务

最近工作需要,建立一个本地版本控制服务,用来共享代码。搭建简单的SVN服务可以使用VisualSVN,但Mercurial有没有类似的工具呢?

权限控制可以看这篇文章 Mercurial(HG)版本控制服务用户名验证

使用Serve

如果你需要简单的共享代码,可以直接使用TortoiseHG的Serve,可以push,pull,clone,不过没有什么验证。安全性不高,当然在内部网络这就可以了,但是同时只能提供一个项目的使用。
使用serve时push默认是不启用的,需要把Push require SSL设为False和Allow Push设为*

使用Apache搭建

如果你英文不错,可以到官方wiki这里看看~ 俺英文太菜了。。http://mercurial.selenic.com/wiki/PublishingRepositories

搜索了一下,再找到一篇文章,跟着这里做 http://makinggames.ca/dev/version-control-mercurial-apache-tortoisehg/(依然是英文)

1.准备工作

下载TortoiseHGMercurial v1.6Python v2.6(建议使用此版本),XAMPP v1.7.3(比较简单的apache服务),把上面的软件都安装了。

2.注意事项

  • 最好是使用没有空格的路径!例如c:\Program Files这样的路径最好不要用,不然可能出现乱七八糟的错误。
  • 在配置文件中路径使用“/” 或者使用”\\”,例如 “D:\\xampp\\htdocs”

3.创建repositories

使用TortoiseHG在某个目录创建repositorie,我的目录是F:\workspace\hg

4.配置

从Mercurial中找到library.zip(注意是Mercurial里的,不是TortoiseHG的library.zip,不然会出错!!),解压到一个目录,我这里是解压到D:\\xampplite\\mlib目录,把Mercurial中templates目录同样复制到此目录下。

在xampp安装目录htdocs下,建立一个hg文件夹
<xampp install>\htdocs\hg
在hg目录下,建立一个hgwebdir.cgi文件,把下面的内容拷贝进去

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!C:/Python26/python.exe
#
# An example CGI script to export multiple hgweb repos, edit as necessary
# 配置为你的library.zip解压的目录:
import sys
sys.path.insert(0, "D:\\xampplite\\mlib")
 
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('hgweb.config')
wsgicgi.launch(application)

注意第一行中的#!C:/Python26/python.exe改为你python.exe所在的路径
sys.path.insert(0, “D:\\xampplite\\mlib”)这句中的D:\\xampplite\\mlib是上面把library.zip解压的目录
再建立一个hgweb.config文件

1
2
3
4
5
6
7
[collections]
F:/workspace/hg = F:/workspace/hg
 
[web]
allow_push =*
push_ssl = false
style = gitweb

上面的F:/workspace/hg请换为你自己的项目的存放目录

最后一步

打开ampp/apache/conf/httpd.conf文件,在最末尾加入

1
2
3
4
5
6
7
# 版本管理
ScriptAliasMatch ^/hg(.*) D:/xampplite/htdocs/hg/hgwebdir.cgi$1
<Directory "D:/xampplite/htdocs/hg">
  Options ExecCGI FollowSymLinks
#去掉SSLRequireSSL的#号就强迫使用ssl来访问
 #SSLRequireSSL
</Directory>

现在试试重启你的apache服务吧,重启后,通过https://localhost/hg/访问

错误处理

Premature end of script headers: hgwebdir.cgi

如果遇到这个问题,建议把它改为hgwebdir.py,用python运行检查一下出现什么错误,注意路径中有空格要用双引号括起来,路径用”/”来隔开。最终会有个SCRIPT的错误,没关系,把它改回hgwebdir.cgi就可以从网页上浏览了。


13 Responses to “ 在Windows使用apache搭建Mercurial版本控制服务 ”

  1. 这个对咱来说可是个高难度的东西啊

    • fatkun says:

      术业有专精而已~~

  2. 爬行至此,留记号

  3. cnlinkin says:

    cool,& thx 4 sharing~

    • fatkun says:

      能帮到你就好。

  4. zhongfq says:

    Traceback (most recent call last):
    File “C:/xampp/htdocs/hg/hgwebdir.cgi”, line 17, in
    application = hgwebdir(‘hgweb.config’)
    File “mercurial\hgweb\hgwebdir_mod.pyc”, line 61, in __init__
    �i|�SWq�tj
    File “mercurial\hgweb\hgwebdir_mod.pyc”, line 70, in refresh
    |ipd�SXWdd}XdS(Nt PATH_INFOR[RtmimetypeRsstatic/tstaticiit REPO_NAMEtnotfoundRYR( R6RdR]RRRt stringifyRQtformRSR ReR t makeindexRJR(Rt
    File “mercurial\ui.pyc”, line 35, in __init__
    |
    File “mercurial\demandimport.pyc”, line 75, in __getattribute__
    File “mercurial\demandimport.pyc”, line 47, in _load
    _demandimportQs:”
    File “mercurial\util.pyc”, line 576, in
    File “mercurial\demandimport.pyc”, line 85, in _demandimport
    File “mercurial\windows.pyc”, line 21, in
    o?}|itijo�n|i�ttid��nXdS(Ns Broken pipe(R
    File “mercurial\demandimport.pyc”, line 75, in __getattribute__
    File “mercurial\demandimport.pyc”, line 47, in _load
    _demandimportQs:”
    File “mercurial\osutil.pyc”, line 12, in
    File “mercurial\osutil.pyc”, line 10, in __load
    ImportError: DLL load failed: 找不到指定的模块。

  5. zhongfq says:

    不知道是什么错误。。。

    • fatkun says:

      我也不知道呢,,

  6. lsm says:

    按以上步骤设置出现错误:Premature end of script headers: hgwebdir.cgi,
    检测:
    C:\xampp\htdocs\hg>python hgwebdir.py
    File “hgwebdir.py”, line 4
    SyntaxError: Non-ASCII character ‘\xc5′ in file hgwebdir.py on line 4, but
    coding declared; see http://www.python.org/peps/pep-0263.html for details

    解决hgwebdir.cgi配置文件中的中文(# 配置为你的library.zip解压的目录:)需要注释就好。

  7. zhongfq says:

    现在已经没有问题了,但是就是读取不到列表啊,好奇怪

    • fatkun says:

      什么列表,初始的repositories是空的,需要commit东西上去。。

  8. zhongfq says:

    mercurial 1.7.1 + python 2.6 + xampp 1.73就完全可以

  9. stone says:

    新手为什么是这样的啊?
    Access forbidden!

    You don’t have permission to access the requested directory. There is either no index document or the directory is read-protected.

    If you think this is a server error, please contact the webmaster.

    Error 403

发表评论

电子邮件地址不会被公开。

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">