水银版本库搭建












操作基本都是用root,除非特别说明。

1。首先安装apache2和mercurial

aptitude install apache2

aptitude install mercurial

2。配置hg给apache用的cgi文件

cd /app/allJavaSource

mkdir hg

//chown -R hgrepo:hgrepo hg

cd hg

cp /usr/share/doc/mercurial/examples/hgweb.cgi .

chmod a+x hgweb.cgi

vi hgweb.cgi

config = "/app/allJavaSource/hg/hgweb.config"

3。配置hg web

vi hgweb.config

[paths]
/hg= /app/allJavaSource/hg/repos/*
[web]
descend =True
collapse =True
baseurl =/hg

[collections]
/app/allJavaSource/hg =/app/allJavaSource/hg

4。配置apache

cd /etc/apache2/sites-available
vi default

在</VirtualHost>前面加入:

ScriptAlias /hg "/app/allJavaSource/hg/hgweb.cgi"

<Location /hg/repos>
                AuthType Basic
                AuthName "Mercurial repositories"
                AuthUserFile /app/allJavaSource/hg/repos/hgusers
                Require valid-user
</Location>

5。建立资源库集目录并设置访问权限

cd /app/allJavaSource/hg

mkdir repos

 chown -R www-data.www-data repos

cd repos

htpasswd -mc hgusers admin

这是给这个库集设定访问用户admin,回车后输入密码。除了添加第一个用户时使用-mc参数外,添加后续用户用-m(建htpasswd用法)

6。建立测试库

 su - www-data

cd /app/allJavaSource/hg/repos

mkdir test

cd test

hg init

7。允许http push

vi /etc/mercurial/hgrc

[web]
allow_push = *
push_ssl = false

8。重启apache2并测试

8.1、 Restart Apache 2 Server /重启apache服务

# /etc/init.d/apache2 restart
or
$ sudo /etc/init.d/apache2 restart

出现错

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

解决:

sudo gedit /etc/apache2/httpd.conf

默认的httpd.conf是个空文件,现在向里面加入如下内容:

ServerName localhost 
保存并退出。

sudo /etc/init.d/apache2 restart



http://localhost/hg/

应该就能看到我们刚建立的测试库repos/test。如有问题查看/var/log/apache2/error.log 

9。建立其它库集并设置不同权限

就是上面repos相关的翻版,上面建立的第一个库集repos,例如我www.linuxidc.com要再建立一个库集cmn:

在/etc/apache2/sites-available/default中加入:

<Location /hg/cmn>
                AuthType Basic
                AuthName "Mercurial repositories"
                AuthUserFile /var/hg/cmn/hgusers
                Require valid-user
</Location>

然后重复上面5,6,只是把repos改成cmn,重启apache。不同库集的权限由相应目录下面的hgusers文件决定。


补充:

 cd /app/allJavaSource/hg/repos

sudo htpasswd -D hgusers admin //删除用户

sudo htpasswd  hgusers zjj //添加用户

10。导入实际的代码

首先如上所示建立空的服务器存储路径并hg init,然后客户端本地实际代码所在目录也hg init,然后push到服务器地址即可。 

Note: 如果web中查看代码中文显示有问题,可以改一下hgweb的编码设置(改完别忘了重启apache):

To change the encoding of served content, you can either change the locale under which hgweb operates, or you can add the following to the hgweb.cgi scriptbefore lines which start with from mercurial import. For example:

import os

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


 
If you're running on apache2, the default user:group is www-data:www-data



sudo apt-get install python-dev python-virtualenv python-setuptools  //过一小会儿得

sudo apt-get install python-docutils //比上面的时间稍微断点

http://mercurial.selenic.com/downloads  解压



 $ make install    # do a system-wide install
 $ hg debuginstall # sanity-check setup

hg/contrib$ cp sample.hgrc ~/.hgrc
vim ~/.hgrc

                            username = Joe User <j.user@example.com>//去掉注释
                            verbose=True  //添加

 $ hg --version

完毕

或者直接

aptitude install apache2

aptitude install mercurial

 如果看不懂, 请用后面的步骤

接下来开始 HG 的使用

1.建立用户hgrepo

其它用户将用这个账户用hg服务器push代码。

useradd hgrepo -d /home/hgrepo # add user hgrepo
passwd hgrepo


groupadd  hg

gpasswd -a hgrepo hg   //注意是 短-  不是长--

2.建立hg代码仓库

如果代码仓库名称为project.hg,则可用如下命令。

cd /home/hgrepo
mkdir project.hg
cd project.hg
hg init # 初始化代码仓库
建立一个测试文件

echo "hello, mercurial" > sample.txt
hg add  # add
hg ci     # check in

3. 打开http

打开一个端口,让远程用户可以clone仓库中的代码.
在打开端口前请确定文件权限正确。

更改文件权限
chown hgrepo.hgrepo /home/hgrepo/project.hg -R
chmod og+rw /home/hgrepo/project.hg -R
打开端口

cd  /home/hgrepo/project.hg -R
hg serve -p 8002 &
可将上面两行加入/etc/rc.local这样就可以在开机的时候自动运行了。

4.使用hg

完成步骤3以后,我们就可以使用了。

clone到本地

例如你的服务器的名字为test.

hg clone http://test:8002
然后在本地目录就会出现一个project.hg的一个copy.

修改Client端的配置

更改.hg/hgrc,加上default-push和username

[paths]
default = http://test:8002
default-push = ssh://hgrepo@test//home/hgrepo/project.hg/
[ui]
username=shaohui.zheng
这样你就可用hg push 向服务器提交code了。这时服务器会问你passward,这个password就是用户hgrepo的password.

Good Luck.

官方网站

http://www.selenic.com/mercurial/







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值