Gentoo - Subversion
- Install Subversion and Apache
- Setup directories, users and permissions
- Create a test repository
- Create a real repository
- Typical repository structure
- Place your project under version control
- Checkout your newly versioned project
- Explanation of Subversion communication protocols
- Configure Apache to support subversion at startup
- Create an Apache password file
- Create an SVN policy file
- Configure Apache to support serving up svn
- Place the default Subversion xsl and css files
- Restart Apache
- Gentoo ebuild notes
- TIP: howto create a tag
1. Install Subversion and Apache
Subversion is able to store it's repositories in two different formats:
- FSFS (Filesystem implementation that uses the OS filesystem to store data)
- BDB (Berkeley DB)
That being said, it's time to do the install of Subversion and Apache. If you already have Apache installed, you can skip over that one.
USE="apache2 postgres gd xml -X -gtk -gnome -qt -kde -alsa"
root# emerge -a subversion apache
2. Setup directories, users and permissions
# Create a group for ssh access to the repositories root# groupadd svnusers # Create the directory where all repositories are kept root# mkdir -p /var/svn/repos root# chmod -R 775 /var/svn/repos root# mkdir /var/svn/conf # Give Apache access to the repositories root# gpasswd -a apache svnusers # Give access to yourself and whoever else you want root# gpasswd -a your-username svnusers root# gpasswd -a your-friend svnusers
3. Create a test repository
I recommend checking this repository out and playing around with it a little. You can cleanly delete it later.
# Create the test repository root# svnadmin create /var/svn/repos/test # Set permissions! root# chown -R apache:svnusers /var/svn/repos/ root# chmod -R g-w /var/svn/repos/test root# chmod -R g+rw /var/svn/repos/test/db root# chmod -R g+rw /var/svn/repos/test/locks # Add a test directory, and validate that it's there root# svn mkdir file:///var/svn/repos/test/foo -m "Creat test directory" root# svn ls file:///var/svn/repos/test foo/
user# svn co file:///var/svn/repos/test ~/Desktop/test user# cd ~/Desktop/test user# echo "hello world" > some-file user# svn add some-file user# svn commit user# svn log
4. Create a real repository
root# svnadmin create /var/svn/repos/your-project # Set permissions! root# chown -R apache:svnusers /var/svn/repos/your-project root# chmod -R g-w /var/svn/repos/your-project root# chmod -R g+rw /var/svn/repos/your-project/db root# chmod -R g+rw /var/svn/repos/your-project/locks
5. Typical repository structure
project |--branches |--tags |--trunk
- branches hold copies of the source that are being actively worked on or maintained but require separation. For example the code for v4 might be inside a branch to allow people to work on future changes that won't be implemented for a while. This allows them to do their work without prematurely placing code in the trunk. These branches are often called "project branches".
- tags hold copies of the software at various milestones, like v1, v2, v3.
- trunk is used to hold the most up to date stable version of your software.
6. Place your project under version control
Look at the project you want to place under version control:
user # cd ~/projects/Bella user # tree # I recommend emerging tree if you don't have it . |-- Changelog |-- LICENSE |-- README `-- bella |-- __init__.py |-- lib `-- server.py 2 directories, 5 files
Since I want the contents of Bella to be in
trunk of the
/var/svn/repos/bella repository, I want to
import my project like this:
user# cd ~/projects user# svn import Bella file:///var/svn/repos/bella/trunk -m 'Initial import' Adding... Adding... Committed revision 1.
Validate that the files were added to the repository:
root# svn ls file:///var/svn/repos/bella/trunk Changelog LICENSE README bella/
7. Checkout your newly versioned project
First you need to move your existing project out of the way:
mv ~/projects/Bella ~/projects/Bella-B4-SVN
Now you can checkout your project from the repository exactly
where it was before:
svn co file:///var/svn/repos/bella/trunk ~/Projects/Bella
8. Explanation of Subversion communication protocols
|file://||This is the most basic protocol and though it works great, it means you can only work on the actual box that hosts the repositores. If this works for you, there's nothing else you need to do besides setup backups :)|
|svn://||This protocol uses a lightweight server that communicates with Subversion (in this howto we use Apache for this role). To use this protocol you would need to have /etc/init.d/svnserve running.|
|svn+ssh://||This protocol uses SSH to communicate with the server. This is actually now my preferred way to communicate with Subverison, especially when you have keychain properly configured.|
|http://||This protocol uses WEBDAV to allow communication over HTTP to the Subversion repositories. This protocol has several advantages, including a more friendly setup for clients like TortoiseSVN.|
|https://||Same as above only with SSL encryption|
TODO: Write down the permission tweaks...
9. Configure Apache to support subversion at startup
Mine looks like this for example:
-D SVN -D SVN_AUTHZ -D DAV -D DAV_FS -D SSL -D SSL_DEFAULT_VHOST
APACHE2_OPTS="-D PYTHON -D SSL -D SVN -D SVN_AUTHZ -D DAV -D DAV_FS"
10. Create an Apache password file
# Use -c to create the file while adding the first user root# htpasswd2 -c /var/svn/conf/svnusers foouser # Add another user, rinse and repeat root# htpasswd2 /var/svn/conf/svnusers baruser
11. Create an SVN policy file
root# nano -w /var/svn/conf/svnpolicy [your-project:/] * = r [another-project:/] foouser = rw baruser = r [yet-another:/trunk/protected] foouser = rw
12. Configure Apache to support serving up svn
<IfDefine SVN> <IfModule !mod_dav_svn.c> LoadModule dav_svn_module modules/mod_dav_svn.so </IfModule> <Location /svn/repos> DAV svn SVNParentPath /var/svn/repos #SSLRequireSSL AuthType Basic AuthName "Super Duper SVN Repository" AuthUserFile /var/svn/conf/svnusers AuthzSVNAccessFile /var/svn/conf/svnpolicy <LimitExcept GET PROPFIND OPTIONS REPORT> Require valid-user </LimitExcept> SVNIndexXSLT /svnindex.xsl </Location> <IfDefine SVN_AUTHZ> <IfModule !mod_authz_svn.c> LoadModule authz_svn_module modules/mod_authz_svn.so </IfModule> </IfDefine> </IfDefine>
13. Place the default Subversion xsl and css files
root# cp /usr/share/doc/subversion-1.5.1/svnindex.* /var/www/localhost/htdocs/ root# cd /var/www/localhost/htdocs root# gunzip svnindex.css.gz root# gunzip svnindex.xsl.gz
14. Restart Apache
Now you should be able to browse to your project by hitting:
root# /etc/init.d/apache2 restart
15. Gentoo ebuild notes
* Subversion Server Notes * ----------------------- * * If you intend to run a server, a repository needs to be created using * svnadmin (see man svnadmin) or the following command to create it in * /var/svn: * * ebuild /path/to/ebuild/subversion-1.5.1.ebuild config * * If you upgraded from an older version of berkely db and experience * problems with your repository then run the following commands as root: * db4_recover -h /var/svn/repos * chown -Rf apache:apache /var/svn/repos * * Subversion has multiple server types, take your pick: * * - svnserve daemon: * 1. edit /etc/conf.d/svnserve * 2. start daemon: /etc/init.d/svnserve start * 3. make persistent: rc-update add svnserve default * * - svnserve via xinetd: * 1. edit /etc/xinetd.d/svnserve (remove disable line) * 2. restart xinetd.d: /etc/init.d/xinetd restart * * - svn over ssh: * 1. Fix the repository permissions: * groupadd svnusers * chown -R root:svnusers /var/svn/repos/ * chmod -R g-w /var/svn/repos * chmod -R g+rw /var/svn/repos/db * chmod -R g+rw /var/svn/repos/locks * 2. create an svnserve wrapper in /usr/local/bin to set the umask you * want, for example: * #!/bin/bash * umask 002 * exec /usr/bin/svnserve "$@" *
16. TIP: howto create a tag
Here's how you then populate the tag, or copy the data from the trunk into the tag directory (notice you create the specific tag 0.1.0 and populate it in the same step):
user# svn mkdir http://your-server.com/svn/repos/your-project/tags -m "Initial creation"
user# svn cp \ > http://your-server.com/svn/repos/your-project/trunk \ > http://your-server.com/svn/repos/your-project/tags/0.1.0 \ > -m "Initial release, doesn't do much of anything really"
|02/09/2006 @ 10:00||Initial creation|
|10/03/2006 @ 17:30||Switch to dav over ssh for real imports|
|10/14/2006 @ 17:00||Typo: when using dav, it's /svn not /var/svn|
|11/19/2006 @ 22:13||Replaced http:// call with file:// for initial import as Apache isn't yet configured (credit: Adam)|
|01/15/2008 @ 22:14||Fixed typo (credit: Naginata)|
|06/28/2008 @ 23:59||Remove link to my svn repo|
|09/20/2008 @ 01:35||Cleaned up a few things and added in an svn co step(s) (credit: Sting-Ray)|
This document was originally created on 02/09/2006
This page is not endorsed by gentoo.org or any other cool cats. Any information provided in this document is to be used at your own risk.