Saturday, August 14, 2010

Setting up Subversion (SVN) Revision Control System

Apache Subversion (formerly called Subversion, command name svn) is a revision control system initiated in 2000 by CollabNet Inc. Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).
Installing SVN Server:
Subversion packages comes by default with the Cent OS or Red Hat Enterprise Linux base os.  You can install it either from SVN or from the Cent OS or RHEL 5 CD.
[root@Astalavista ~]# yum install subversion
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Package subversion.i386 0:1.4.2-4.el5_3.1 set to be updated
–> Running transaction check
Dependencies Resolved
Package                 Arch       Version          Repository        Size
subversion              i386       1.4.2-4.el5_3.1  base              2.3 M
Transaction Summary
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 2.3 M
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: subversion                   ######################### [1/1]
Installed: subversion.i386 0:1.4.2-4.el5_3.1
[root@Astalavista ~]#
Creating a new SVN Repository
  • Change to the directory/folder where you want to create SVN Repository.
  • Create a new SVN Repository using svnadmin create NewApp (Replace NewApp with your application/folder repository name)
[root@Astalavista ~]# cd /SVNRepo/
[root@Astalavista SVNRepo]# svnadmin create NewApps
[root@Astalavista SVNRepo]# ls
[root@Astalavista SVNRepo]#
Configuring SVN
Subversion keeps the configuration files in conf folder.  The conf folder would be available at the root folder for the repository.
In the above example, we created the repository @ /SVNRepo/NewApps so the configuration files resides under /SVNRepo/NewApps/conf folder for NewApps SVN Repository.
There are three configuration files,
  1. svnserve.conf – Main Configuration File for SVN.
  2. passwd – User/Password database for SVN Users.
  3. authz – Rules for path based access control.
To configure a simple SVN Repository, we just need to update svnserve.conf and passwd file.
Follow the below steps to configure SVN Repository:
  • Edit svnserve.conf file and uncomment line “password-db = passwd”.  This line specifies the location of password database.  If you do not want to keep the password database at the default location, keep the file at some location and provide the complete path of the file to password-db directive.
  • If you want to provide read access to all users (anonymous) then uncomment line “anon-access =” and provide the value as  read or write depending upon your requirement.
  • If you have multiple SVN Repositories and you want to use the same password database for all the repositories, the uncomment line “realm=” and provide name to the realm.  To use the same password database for all the repositories, the realm name must be the same for all the repositories.  The default realm would be always the repository’s uuid.
  • Edit passwd file and add users for the repository after [users] line.  The syntax is username=password.
The  Configuration files would look as given below.
svnserve.conf file
[root@Astalavista conf]# cat svnserve.conf
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit for more information.
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are “write”, “read”,
### and “none”.  The sample settings below are the defaults.
anon-access = read
#auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file’s location is relative to the conf directory.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file’s location is relative to the conf
### directory.  If you don’t specify an authz-db, no path-based access
### control is done.
### Uncomment the line below to use the default authorization file.
#authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository’s uuid.
[root@Astalavista conf]#
passwd file
[root@Astalavista conf]# cat passwd
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
harry = harryssecret
sally = sallyssecret
[root@Astalavista conf]#
Starting SVN as Daemon
To start SVN as daemon, execute command “/usr/bin/svnserve -d”
To automatically start SVN at system boot up, add this command to rc.local file.
Accessing SVN  from Unix or Windows Machine
SVN is platform independent and the files can be accessed from both Windows as well as Unix system.
Accessing SVN from Unix System,
1.  Download and Install SVN client rpm
2.  Use the following command to checkout files in the SVN Repository as below.
[root@Astalavista /]# svn update /NewAppCheckOut/NewApps/
At revision 1.
[root@Astalavista /]#
3.  Use the following command to update SVN to the latest revision
[root@Astalavista NewApps]# svn update /NewAppCheckOut/NewApps/
At revision 3.
[root@Astalavista NewApps]#
4.  To delete a file from SVN repository, execute the following command
[root@Astalavista NewApps]# svn delete
[root@Astalavista NewApps]#
5.  To save the local changes @ SVN Repository (Server), execute the following command.
[root@Astalavista NewApps]# svn commit –username vaibhav
–This line, and those below, will be ignored–  // this message you would see in VI Editor – Just Close the VI Editor
D // this message you would see in VI Editor – just close the VI Editor
Log message unchanged or not specified
a)bort, c)ontinue, e)dit
Committed revision 3.
[root@Astalavista NewApps]#
6.  To get the syntax for any SVN Command execute the following command.
[root@Astalavista NewApps]# svn help
usage: svn [options] [args]
Subversion command-line client, version 1.4.2.
Type ‘svn help ’ for help on a specific subcommand.
Type ‘svn –version’ to see the program version and RA modules
or ‘svn –version –quiet’ to see just the version number.
Most subcommands take file and/or directory arguments, recursing
on the directories.  If no arguments are supplied to such a
command, it recurses on the current directory (inclusive) by default.
Available subcommands:
blame (praise, annotate, ann)
checkout (co)
commit (ci)
copy (cp)
delete (del, remove, rm)
diff (di)
help (?, h)
list (ls)
move (mv, rename, ren)
propdel (pdel, pd)
propedit (pedit, pe)
propget (pget, pg)
proplist (plist, pl)
propset (pset, ps)
status (stat, st)
switch (sw)
update (up)
Subversion is a tool for version control.
For additional information, see
[root@Astalavista NewApps]# svn help commit
commit (ci): Send changes from your working copy to the repository.
usage: commit [PATH...]
A log message must be provided, but it can be empty.  If it is not
given by a –message or –file option, an editor will be started.
If any targets are (or contain) locked items, those will be
unlocked after a successful commit.
Valid options:
-q [--quiet]             : print as little as possible
-N [--non-recursive]     : operate on single directory only
–targets arg            : pass contents of file ARG as additional args
–no-unlock              : don’t unlock the targets
-m [--message] arg       : specify log message ARG
-F [--file] arg          : read log message from file ARG
–force-log              : force validity of log message source
–editor-cmd arg         : use ARG as external editor
–encoding arg           : treat value as being in charset encoding ARG
–username arg           : specify a username ARG
–password arg           : specify a password ARG
–no-auth-cache          : do not cache authentication tokens
–non-interactive        : do no interactive prompting
–config-dir arg         : read user configuration files from directory ARG
[root@Astalavista NewApps]#