Quantcast
Channel: 软件应用 –笑遍世界
Viewing all articles
Browse latest Browse all 51

用hgweb来发布Mercurial repository

$
0
0

hg repository 有多种的发布方式,前面我讲到过hg serve,这次主要写一下hgweb,它可以做到像http://xenbits.xen.org/hg/ 这样的效果。
新版的hgweb.cgi支持多个repository的发布了(我目前就是使用的hgweb.cgi),如果是比较老的Mercurial,就需要使用hgwebdir.cgi才能支持多个repository。我刚好使用过Mercurial的1.6.4和较老的1.4.3版本(是RHEL6.2自带的,我使用hgwebdir.cgi)。新老两种方法都分别介绍一下吧。
Mercurial可以从这里下载:http://mercurial.selenic.com/release/?M=D

新的Mercurial使用hgweb.cgi
1. 安装Mercurial: (略)
找到source code中的hgweb.cgi这个文件,将其copy到/var/www/hgweb/下。
2. 配置Web Server:以Apache为例
vim /etc/httpd/conf/httpd.conf 添加如下一行
ScriptAlias /hg “/var/www/hgweb/hgweb.cgi”
在/var/www/hgweb目录下,配置rewrite规则,vim .htaccess 做如下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
# Taken from http://www.pmwiki.org/wiki/Cookbook/CleanUrls#samedir
# Used at http://ggap.sf.net/hg/
Options +ExecCGI
RewriteEngine On
#write base depending on where the base url lives
RewriteBase /hg
RewriteRule ^$ hgweb.cgi  [L]
# Send requests for files that exist to those files.
RewriteCond %{REQUEST_FILENAME} !-f
# Send requests for directories that exist to those directories.
RewriteCond %{REQUEST_FILENAME} !-d
# Send requests to hgweb.cgi, appending the rest of url.
RewriteRule (.*) hgweb.cgi/$1  [QSA,L]

3. 配置hgweb.cgi及其配置文件:
vim /var/www/hgweb/hgweb.cgi 做如下配置:

View Code PYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python
#
# An example hgweb CGI script, edit as necessary
# See also http://mercurial.selenic.com/wiki/PublishingRepositories
 
# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/etc/hgweb.config"
 
# Uncomment and adjust if Mercurial is not installed system-wide:
#import sys; sys.path.insert(0, "/path/to/python/lib")
 
# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb; cgitb.enable()
 
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb(config)
wsgicgi.launch(application)

vim /etc/hgweb.config 做如下配置:

1
2
3
	[paths]
        xen-unstable.hg = /home/repo/pub/xen-unstable.hg
        xen-unstable-staging.hg = /home/repo/pub/xen-unstable-staging.hg

4. 重启Web Server 即可
5. 使用repository:浏览器访问:http://vt-repo/hg/
client端执行命令:hg clone http://vt-repo/hg/xen-unstable.hg xen-unstable.hg

老的Mercurial使用hgwebdir.cgi
其使用方法和上面新的hgweb.cgi是类似的了。
1. vim httpd.conf
ScriptAlias /hg “/var/www/hgweb/hgwebdir.cgi”

vim /var/www/hgweb/.htaccess

1
2
3
4
5
6
7
8
9
10
11
12
13
# Taken from http://www.pmwiki.org/wiki/Cookbook/CleanUrls#samedir
# Used at http://ggap.sf.net/hg/
Options +ExecCGI
RewriteEngine On
#write base depending on where the base url lives
RewriteBase /hg
RewriteRule ^$ hgwebdir.cgi  [L]
# Send requests for files that exist to those files.
RewriteCond %{REQUEST_FILENAME} !-f
# Send requests for directories that exist to those directories.
RewriteCond %{REQUEST_FILENAME} !-d
# Send requests to hgwebdir.cgi, appending the rest of url.
RewriteRule (.*) hgwebdir.cgi/$1  [QSA,L]

2. vim hgwebdir.cgi 配置

View Code PYTHON
1
2
application = hgwebdir('/etc/hgweb.config')
wsgicgi.launch(application)

vim /etc/hgweb.config 配置
[paths]
xen-unstable.hg = /home/repo/pub/xen-unstable.hg
xen-unstable-staging.hg = /home/repo/pub/xen-unstable-staging.hg
3. 重启Web Server
4. 使用方法就是一样的了

repository支持hg push的配置:
使用http/web方式push:在server端的repo中修改.hg/hgrc文件。
(或者修改your Web server user’s .hgrc file, such as /home/www-data/.hgrc, or a system-wide hgrc file like /etc/mercurial/hgrc)
添加如下配置信息:

1
2
3
[web]
push_ssl = false
allow_push = *

注意:以上配置皆为我在测试环境中的配置,请自己根据实际情况略作修改。运行Web Server的user一定要对repository有可读的权限(如果要push,则需要有读写权限)。

参考资料:

http://mercurial.selenic.com/wiki/PublishingRepositories#hgweb

Original article: 用hgweb来发布Mercurial repository

©2015 笑遍世界. All Rights Reserved.


Viewing all articles
Browse latest Browse all 51

Trending Articles