samueladam.net

from belgium import beer

Howto migrate a subversion repository to mercurial

written by samuel, on 2008-03-05 11:32.

Migrating an svn repo to hg is pretty straightforward with hgsvn.

Install and migrate with hgsvn

hgsvn

sudo easy_install hgsvn
sudo su www-data
hgimportsvn file:///var/lib/svn/my-svn-repo
cd my-svn-repo
hgpullsvn
hg update
exit

You can also do some cleanup and remove .svn and .hgignore folders

Configure Apache with hgwebdir.cgi

This is bonus, here is my config.

First, we will create the document root for our hg.domain.ext.

We need to locate and copy some files from the mercurial folder.

sudo find / -name hgwebdir.cgi

Change the next script depending on your result.

sudo mkdir -p /var/lib/hg/domain.ext
cd /var/lib/hg/domain.ext
sudo cp /home/samuel/download/mercurial-0.9.5/hgwebdir.cgi ./
sudo cp -r /home/samuel/download/mercurial-0.9.5/templates/static ./
sudo cat > hgweb.config << EOF
[paths]
my-svn-repo = /var/lib/hg/repos/my-svn-repo
[web]
style = gitweb
EOF
sudo chown -R www-data:www-data .

On to the Apache web server configuration. Here the setup enforces the https connection and uses an htaccess file.

Create and edit /etc/apache2/sites-available/hg.domain.ext

# File : /etc/apache2/sites-available/hg.domain.ext
<VirtualHost *:80>
ServerName hg.domain.ext
RewriteEngine On
RewriteRule ^/(.*)$ https://hg.domain.ext/$1 [R]
</virtualhost>

<virtualhost>

SSLEngine on
# Replace with your certificate
SSLCertificateFile /etc/apache2/ssl/new.cert.cert
SSLCertificateKeyFile /etc/apache2/ssl/new.cert.key

ServerName hg.domain.ext
DocumentRoot /var/lib/hg/domain.ext
ErrorLog /var/log/apache2/hg.domain.ext_ssl_error.log
CustomLog /var/log/apache2/hg.domain.ext_ssl_access.log combined

RewriteEngine On
RewriteRule ^/(.*) /hgwebdir.cgi/$1

<directory>
DirectoryIndex hgwebdir.cgi
AddHandler cgi-script .cgi
Options ExecCGI
AllowOverride None
AuthUserFile /var/lib/hg/domain.ext/project.htpasswd
AuthType Basic
AuthName "hg.domain.ext"
Require valid-user
Order allow,deny
allow from all
</directory>

</virtualhost>

Then activate the website.

sudo htpasswd -c /var/lib/hg/domain.ext/project.htpasswd your-username
sudo a2ensite hg.domain.ext
sudo /etc/init.d/apache2 force-reload

If you want to push thourgh https, remember to add this to your hgrc file.

# /var/lib/hg/repos/my-svn-repo/.hg/hgrc
[web]
allow_push = your-username

Leave a Reply