用hg server 来发布Mercurial repository
经常使用Mercurial的repo(比如:xen-unstable.hg),本文就如何搭建一个hg repository吧。
首先,需要建立一个repo,【安装mercurial软件包 自不必说的了】
$ hg init (project-directory)
$ cd (project-directory)
$ (add some files)
$ hg add
$ hg commit -m 'Initial commit'
然后,在repo的目录内,运行hg serve即可发布这个repo。(默认情况下使用TCP8000端口)
在另外一台机器上,运行如下hg clone命令即可将repo clone下来。
hg clone http://vt-repo:8000/ my-repo.hg #vt-repo为我的server name
如何支持push? 在server端配置
1. 使用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)
添加如下配置信息:
[web]
push_ssl = false
allow_push = *
(注意:一定需要保证你的repo目录对运行Web Server的用户具有可读可写的权限。hg push 默认使用https方式,需要ssl认证,allow_push是限制那些用户可以push,这里再内网,对这些权限方面的暂时不做限制。)
2. 使用ssh方式push:修改client端的.hg/hgrc文件制定push的
添加如下内容:
[paths]
default = http://vt-repo:8000/ #这一行是clone下来就有的
default-push = ssh://user@vt-repo/my-repo.hg
(client端hg push之时会让你输入user在vt-repo上ssh登录的密码)
在client端的配置,只需要添加一个用户自己的username即可,在.hg/hgrc文件中添加如下:
[ui]
username = your_name <your_email@xxx.com>
客户端将repo clone下来,然后修改,然后commit,最后push即可。
这里再添加一个我曾用过的一个脚本,它用来做hg serve的。
#!/bin/bash
#
# Startup script for mercurial server.
#
# Change following lines
APP_BIN=/usr/bin/hg
SRC=/home/repo/pub/xen-unstable.hg
SRCNAME="xen-unstable"
# Path to PID file of running mercurial process.
PID_FILE=/home/repo/hg-serve.pid
state=$1
case "$state" in
'start')
echo "Mecurial Server service starting."
(cd ${SRC}; ${APP_BIN} serve --name "${SRCNAME}" -d -p 8000 --pid-file ${PID_FILE})
;;
'stop')
if [ -f "${PID_FILE}" ]; then
PID=`cat "${PID_FILE}"`
if [ "${PID}" -gt 1 ]; then
kill -TERM ${PID}
echo "Stopping the Mercurial service PID=${PID}."
else
echo Bad PID for Mercurial -- \"${PID}\"
fi
else
echo No PID file recorded for mercurial
fi
;;
*)
echo "$0 {start|stop}"
exit 1
;;
esac
参考资料:
http://mercurial.selenic.com/wiki/hgserve
http://smilejay.com/2011/11/git_hg_basic_usage/