Sunday, May 22, 2011

Subversion Quickstart

This short tutorial is intended for new users to grasp subversion quickly.
Subversion is a open source version control system based on Copy-Modify-Merge model rather than lock-Modify-Unlock model.
It is primarily used for software development, which allows developers to modify files and directories concurrently (no locking) and switch between versions easily. In system administration world, it could be used to track system changes and roll back changes. Fundamental Concepts(don't skip):- The Repository
Repository is a central store for all versions of data, subversion server configuration files are also located in the repository.
Once repository is created, you are NOT supposed to visit the repository directory other than changing subversion server configuration
You should modify versions of data in a “working copy” of the repository data.
The repository can be accessed in a number ways:

file:/// Direct repository access (on local disk)
http:// Access via WebDAV protocol to Subversion-aware Apache server
https:// Same as http://, but with SSL encryption.
svn:// Access via custom protocol to an svnserve server
svn+ssh:// Same as svn://, but through an SSH tunnel

To setup svnserv server to offer svn:// access over network, you need to enable authentication and authorization by modifying repository-path/conf/{svnserve.conf,passwd,authz} then start “svnserve -d -r repository-path”- The Working copy directory
A working copy is a subset of repository data. To creating a working copy, use “svn checkout” to checkout the root or sub directory of repository.
You modify data in “working copy” NOT in repository directoryInstall subversion
Most Linux distros include subversion by default. to Install in Centos: $yum install subversion

$rpm -qa | grep subv
subversion-1.6.11-7.el5_6.3

Create a subversion repository

#It is where all data are saved, you should have enough space

$svnadmin create /var/svn

#svnadmin populated the directory with following structure

#conf is the location of server configuration files

#db is the location of your versions of data

$ls /var/svn

conf db format hooks locks README.txt

#It is ideal to create individual directory for different project.

#-m is to give a description of this operation, later, it can be view with “svn log”

#This transaction is recorded as revision 1

#the command is svn not svnadmin

#svnadmin and svnlook are server side commands, They always action on a PATH NOT a URL like file:///”

$svn mkdir file:///var/svn/proj_1 -m "test mkdir"

Committed revision 1.

#Verify the sub dir is created

$svn list -v file:///var/svn

3 root May 22 11:33 ./

3 root May 22 11:33 proj_1/

Import data into the repository

#let's import /etc/sysconfig into the repository

#import is used to to populate repository for the first time

#adding new files later need “svn add” command in a “working copy”

$ svn import /etc/sysconfig/ file:///var/svn/proj_1 -m "test import"

Adding /etc/sysconfig/irda

Adding /etc/sysconfig/kernel

Adding /etc/sysconfig/syslog

..

Adding /etc/sysconfig/snmpd.options

Committed revision 2.

#let's view the imported files in repository

#something wrong? Where are those files? even dir “proj_1” doesn't exist

#let me repeat, you are supposed to modify data in repository directly, Do this in a “working copy”

$ls /var/svn

conf db format hooks locks README.txt

# if you are curious about where the data is stored, all data are “packed” in a binary file

$ strings /var/svn/db/revs/0/2 | grep $(hostname)

HOSTNAME=filer.example.com

# or view “svn ls” and “svn cat”

svn cat file:///var/svn/proj_1/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=filer.example.com

Create a working copy

#create a working copy by checkout proj_1, The target dir proj_1 will be automatically created, of course, you can name it differently