Topics
1.1 Subversion
1.2 Install subversion on a linux machine
1.2.1 Download the svn source code
1.2.2 Determine the dependencies
1.2.3 To install apr and apr-utils
1.2.3.1 Build and install apr
1.2.3.2 Build and install apr-utils
1.2.4 Build and install subversion
1.3 Subversion server
1.3.1 Apache server
1.3.2 Svnserve server
1.3.2.1 Invoking the server
1.4 Create a repository
1.5 Add / Import files to repository
1.5.1 To list all the files in the repository
1.5.2 Check the log of a file in the repository
1.6 Importing a project with bunch of files in a specific directory structure
1.7 Checking out a project
1.8 Editing and adding files
1.9 Committing the changes into the repository
2. Versioning in svn
3. References
1.1 Subversion
Subversion is a free/open source version control system. That is, Subversion manages files and directories, and the changes made to them, over time. This allows you to recover older versions of your data or examine the history of how your data changed. In this regard, many people think of a version control system as a sort of “time machine.”Subversion can operate across networks, which allows it to be used by people on different computers. At some level, the ability for various people to modify and manage the same set of data from their respective locations fosters collaboration. Progress can occur more quickly without a single conduit through which all modifications must occur. And because the work is versioned, you need not fear that quality is the trade-off for losing that conduit—if some incorrect change is made to the data, just undo that change.
Some version control systems are also software configuration management (SCM) systems. These systems are specifically tailored to manage trees of source code and have many features that are specific to software development—such as natively understanding programming languages, or supplying tools for building software. Subversion, however, is not one of these systems. It is a general system that can be used to manage any collection of files. For you, those files might be source code—for others, anything from grocery shopping lists to digital video mix downs and beyond.
1.2 Install subversion on a linux machine
Installing subversion is a pretty easy task. This section covers installing subversion from a source tarball, for client-type uses. This document is based on an install of Subversion-1.6.15.tar.gz, but the install procedure should be similar for other versions as well.
For its functionality, subversion makes use of (depends on) a number or other pieces of software, all of which are also available for free. You must install these pieces of software before installing subversion. In many cases, some or all of the required software will already be installed on your system.
First determine the properties of the linux machine on which subversion has to be installed with the help of uname command.
$ uname –a
Linux machine_name 2.6.23.1-42.fc8 #1 SMP Tue Oct 30 13:55:12 EDT 2007 i686 i686 i386 GNU/Linux
NOTE:
uname (shortname for unix name) is a software program in unix that prints the name, version and other details about the current machine and the operating system running on it.
1.2.1 Download the subversion source code:
Click on Source Code link in the above line it would take you to below link:
Select the latest version of subversion software tar balls i.e 1.6.15 .tar.gz (or) .tar.bz2 files for linux operating system.
$ wget "http://subversion.tigris.org/downloads/subversion-1.6.15.tar.bz2"
--16:08:34-- http://subversion.tigris.org/downloads/subversion-1.6.15.tar.bz2
=> `subversion-1.6.15.tar.bz2'
Resolving subversion.tigris.org... 204.16.104.146
Connecting to subversion.tigris.org|204.16.104.146|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5,515,056 (5.3M) [application/x-bzip2]
100%[====================================>] 5,515,056 121.96K/s ETA 00:00
16:09:33 (92.00 KB/s) - `subversion-1.6.15.tar.bz2' saved [5515056/5515056]
$ ls
-rw-r--r-- 1 root root 5515056 2010-11-24 21:38 subversion-1.6.15.tar.bz2
% tar –jxvf subversion-1.6.15.tar.bz2 (Untars the tar.bz2 file and creates all the files under the directory subversion-1.6.15
$ tar -jxvf subversion-1.6.15.tar.bz2
$ ls
-rw-r--r-- 1 root root 5515056 2010-11-24 21:38 subversion-1.6.15.tar.bz2
drwxr-xr-x 10 1000 1000 4096 2011-02-15 16:26 subversion-1.6.15
$ cd subversion-1.6.15
$ ls (lists a no. of files)
$ \vi INSTALL
(This file has the instructions to build and install svn and you will end up with a 'svn' binary in the subversion/svn/subdirectory (or installed in /usr/local/bin/, if you ran 'make install'.)
1.2.2 Determine the dependencies:
For its functionality, subversion makes use of (depends on) a number or other pieces of software, all of which are also available for free. You must install these pieces of software before installing subversion. In many cases, some or all of the required software will already be installed on your system.
On Unix systems, the './configure' script will tell you if you are missing the correct version of any of the required libraries or tools, so if you are in a real hurry to get building, you can skip straight to section II. If you want to gather the pieces you will need before starting out, however, you should execute the following.
$ ./configure
OUTPUT:
===================================================================================
configure: Configuring Subversion 1.6.15
configure: creating config.nice
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking whether ln -s works... yes
checking for a BSD-compatible install... /usr/bin/install -c
configure: Apache Portable Runtime (APR) library configuration
checking for APR... no
configure: WARNING: APR not found
The Apache Portable Runtime (APR) library cannot be found.
Please install APR on this system and supply the appropriate
--with-apr option to 'configure'
or
get it with SVN and put it in a subdirectory of this source:
svn co \
http://svn.apache.org/repos/asf/apr/apr/branches/1.2.x \
apr
Run that right here in the top level of the Subversion tree.
Afterwards, run apr/buildconf in that subdirectory and
then run configure again here.
Whichever of the above you do, you probably need to do
something similar for apr-util, either providing both
--with-apr and --with-apr-util to 'configure', or
getting both from SVN with:
svn co \
http://svn.apache.org/repos/asf/apr/apr-util/branches/1.2.x \
apr-util
configure: error: no suitable apr found
1.2.3 Install apr and apr-utils
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behavior regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.
1.2.3.1 Build and install apr
$ cd /usr/local/src
--16:45:47-- http://www.eng.lsu.edu/mirrors/apache//apr/apr-1.4.2.tar.bz2
=> `apr-1.4.2.tar.bz2'
Resolving www.eng.lsu.edu... 130.39.24.178
Connecting to www.eng.lsu.edu|130.39.24.178|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 766,793 (749K) [application/x-tar]
100%[=================================================================================================================>] 766,793 92.95K/s ETA 00:00
16:45:58 (79.70 KB/s) - `apr-1.4.2.tar.bz2' saved [766793/766793]% tar -jxvf apr-1.4.2.tar.bz2
$ cd apr-1.4.2
$ ./configure
$ make
$ make install
$ cd /usr/local/bin
$ ln -sf /usr/local/apr/bin/apr-1-config apr
1.2.3.2 Build and install the apr-util
$ ls
apr-util-1.3.10.tar.bz2
$ tar -jxvf apr-util-1.3.10.tar.bz2
$ cd apr-util-1.3.10
$ ./configure --with-apr=/usr/local/apr --with-berkeley-db=/usr/bin
$ make
$ make install
$ cd /usr/local/bin
$ ln -sf /usr/local/apr/bin/apu-1-config .
$ mv apu-1-config apu-1-config-v.1.3.10
$ ln -sf apu-1-config-v.1.3.10 apr-util
1.2.4 Build and install svn
$ cd subversion-1.6.15
$ ./configure --with-apr=/usr/bin/local/apr --with-apr-util=/usr/bin/local/apr-util
(You need to pass the path of apr and apr-util libraries if it is not able to detect by default and it can be verified with the help of./configure tool)
$ make
$ make install
$ which svn
/usr/local/bin/svn
$ svn --version
svn, version 1.6.15 (r1038135)
compiled Feb 16 2011, 12:12:40
Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.apache.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).
The following repository access (RA) modules are available:
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme
1.3 Subversion Server:
Subversion has two servers you can choose from: svnserve and Apache. svnserve is a small, lightweight server program that is automatically compiled when you build Subversion's source. Apache is a more heavyweight HTTP server, but tends to have more features.
1.3.1 Apache Server:
1.3.2 Svnserve server:
An alternative network layer is libsvn_ra_svn (on the client side) and the 'svnserve' process on the server. This is a simple network layer that speaks a custom protocol over plain TCP (documented in libsvn_ra_svn/protocol). Clients contact an svnserve server by using URLs that begin with the
svn://
or svn+ssh://
scheme.The easiest option is to run svnserve as a standalone “daemon” process. Use the –d option for this:
$ svnserve -d # becomes a background daemon
When running svnserve in daemon mode, you can use the
--listen-port
and --listen-host
options to customize the exact port and hostname to “bind” to.Once we successfully start svnserve as explained previously, it makes every repository on your system available to the network. A client needs to specify an absolutepath in the repository URL. For example, if a repository is located at
/var/svn/project1
, a client would reach it via svn://host.example.com/var/svn/project1
. To increase security, you can pass the -r
option to svnserve, which restricts it to exporting only repositories below that path. For example: $ svnserve -d -r ~/SVN/depot/projects
$ svn checkout svn://localhost/usr/local/svn/repository
You can use the "-r" option to svnserve to set a logical root for repositories, and the "-R" option to restrict connections to read-only access. ("Read-only" is a logical term here; svnserve still needs write access to the database in this mode, but will not allow commits or revprop changes.)
1.3.2.1 Invoking the server:
$ svnserve -d -r ~/SVN/depot/projects
$ ps -ef | grep svn
root 32223 1 0 13:15 ? 00:00:00 svnserve -d -r /root/sarala/SVN/depot/projects
1.4 Create a repository
$ svnadmin create ~/sarala/SVN/depot/projects/repo1
$ cd ~/sarala/SVN/depot/projects/repo1
$ ls -lrt
-rw-r--r-- 1 root root 229 2011-02-16 13:39 README.txt
drwxr-xr-x 2 root root 4096 2011-02-16 13:39 locks
drwxr-xr-x 2 root root 4096 2011-02-16 13:39 hooks
-r--r--r-- 1 root root 2 2011-02-16 13:39 format
drwxr-sr-x 6 root root 4096 2011-02-16 13:39 db
drwxr-xr-x 2 root root 4096 2011-02-16 13:39 conf
1.5 Add / Import files to repository
$ svn import ~/sarala/depot_files/project1 --username root --password svn123 svn://localhost/svn-repo
Adding /root/sarala/depot_files/project1/a.c
Adding /root/sarala/depot_files/project1/b.c
Committed revision 1.
$ svn import ~/sarala/depot_files/project2 --username root --password svn123 svn://localhost/svn-repo
Adding /root/sarala/depot_files/project2/b.txt
Adding /root/sarala/depot_files/project2/a.txt
Committed revision 2.
1.5.1 To list all the files in the repository
$ svn list svn://localhost/svn-repo
a.c
a.txt
b.c
b.txt
(OR)
$ svn ls svn://localhost/svn-repo
a.c
a.txt
b.c
b.txt
For the moment, look at the command we have typed. We have used the standard ls command but we have used it as a svn command. This is an important aspect of svn: it allows you to manipulate files and directory (i.e. create, delete, move) with commands similar to the standard ones. So you really have the feeling you are just working with files but this is just the way svn presents them to you. Internally those files are managed with a database that is stored in the files you saw when listing the /home/user/svn/ directory. This virtual directory structure can be anywhere : on the local filesystem, on a remote machine, or even on a web server. For that reason, instead of talking of "filepath" for these virtual directories, svn uses the terminology URL. The URL must be prefixed to indicate how the repository should be accessed. That's why we have the file:// prefix. We will see other examples later. For the moment let's play with the virtual directory structure.
Some other examples are:
$ svn mkdir svn://localhost/svn-repo/dir1 -m “Creating a directory inside the repository”
$ svn rm svn://localhost/svn-repo/dir1 -m “Deleting a directory inside the repository”
1.5.2 Check the log of a file in the repository
$ svn log svn://localhost/svn-repo/a.c
------------------------------------------------------------------------
r1 | root | 2011-02-17 12:11:51 +0530 (Thu, 17 Feb 2011) | 3 lines
Hii
--------------------------------------------------------------------------------
1.6 Importing a project with bunch of files in a specific directory structure
Suppose you have a directory structure with a bunch of files and you need to add them to the repository retaining their relative paths and can be done using the below command.
$ svn import ~/sarala/depot_files/ --username root --password svn123 svn://localhost/svn-repo/dir1 –m “Commiting code with directory structure into the repository”
Adding /root/sarala/depot_files/project1
Adding /root/sarala/depot_files/project1/a.c
Adding /root/sarala/depot_files/project1/b.c
Adding /root/sarala/depot_files/project2
Adding /root/sarala/depot_files/project2/b.txt
Adding /root/sarala/depot_files/project2/a.txt
Committed revision 4.
The -m flag is used to give a log message for the action. Log messages are enforced by svn. If you do not want to use the -m flag on the command line, setup the SVN_EDITOR environment variable, for example to vi, and svn will prompt you with that editor anytime it needs a log message.
1.7 Checking out a project
$ mkdir /path/directory_to_checkout_the_code
$ cd /path/directory_to_checkout_the_code
$ Svn checkout svn://localhost/svn-repo
A svn-repo/b.txt
A svn-repo/dir1
A svn-repo/dir1/project1
A svn-repo/dir1/project1/a.c
A svn-repo/dir1/project1/b.c
A svn-repo/dir1/project2
A svn-repo/dir1/project2/b.txt
A svn-repo/dir1/project2/a.txt
A svn-repo/a.c
A svn-repo/b.c
A svn-repo/a.txt
Checked out revision 4.
After the above command you will find a local copy of the repository under the directory /path/directory_to_checkout_the_code/svn-repo. This can also be verified by the presence of a “.svn” directory.
$ cd /path/directory_to_checkout_the_code/svn-repo
$ ls -lrt
total 20
drwxr-xr-x 5 root root 4096 2011-02-17 13:09 dir1
-rw-r--r-- 1 root root 60 2011-02-17 13:09 b.txt
-rw-r--r-- 1 root root 247 2011-02-17 13:09 b.c
-rw-r--r-- 1 root root 43 2011-02-17 13:09 a.txt
-rw-r--r-- 1 root root 82 2011-02-17 13:09 a.c
This can also be checked by the command “svn info”.
$ cd /path/directory_to_checkout_the_code/svn-repo
$ svn info
Path: .
URL: svn://localhost/svn-repo
Repository Root: svn://localhost
Repository UUID: d949aa33-3bf6-4f25-98b7-906b7cb10941
Revision: 4
Node Kind: directory
Schedule: normal
Last Changed Author: root
Last Changed Rev: 4
Last Changed Date: 2011-02-17 12:53:48 +0530 (Thu, 17 Feb 2011)
1.8 Editing and adding files:
Now that our project is safely under version controlled system, we can start making it evolve. First lets add another file new.c and then change a.txt file. After that we can check the status of our project as below:
$ cd /path/directory_to_checkout_the_code/svn-repo
$ \vi new.cc (Create a new.c file using any editor of your choice and save it)
$ \vi a.txt (Modify the a.txt file i.e add, delete or modify the contents of the file a.txt)
$ svn status
? new.c
M a.txt
The output of “svn status” command is very readable, it states there is one unknown file (?) new.c and one modified file (M).
Lets add the above two files to the repository:
$ svn add new.c
$ svn status
A new.c
M a.txt
Now the status of new.c is being changes to “A” i.e added to the repository.
1.9 Committing the changes into the repository:
$ svn commit -m "Commiting the changes to the repository"
Sending a.txt
Adding new.c
Transmitting file data ..
Committed revision 5.
2. Versioning in svn:
When you committed your changes, svn indicated that it was version 5. Where that number comes from? Indeed, it is the very first commit so you would expect the revision to be 2, or 1.1 or something of that taste. Well, svn has a very different way of numbering files than CVS and it is one of its most pleasant feature. Everytime you change something (create a directory, remove a directory, commit modified or added files), svn attributes a new version number to all files. Everything happens as if the whole repository was copied everytime you do an svn command and svn enforces thinking that way. Of course, this is not what happens and svn saves only the relative changes in order to minimize the size of the database.
$ cd /tmp
$ svn checkout -r 5 svn://localhost/svn-repo
A svn-repo/b.txt
A svn-repo/dir1
A svn-repo/dir1/project1
A svn-repo/dir1/project1/a.c
A svn-repo/dir1/project1/b.c
A svn-repo/dir1/project2
A svn-repo/dir1/project2/b.txt
A svn-repo/dir1/project2/a.txt
A svn-repo/a.c
A svn-repo/b.c
A svn-repo/new.c
A svn-repo/a.txt
Checked out revision 5.
The meaning of “-r 5” should be self-explanatory. Look at the output. As you can see, this retrieved all files of your project. In other words, the version number is just a shortcut to the date at which the project is stamped.
Let's now get a copy of the previous version :
$ cd /tmp
$ svn checkout -r 4 svn://localhost/svn-repo
D svn-repo/new.c
U svn-repo/a.txt
Checked out revision 4.
Have a closer look at the output. It shows how clever svn is. We asked for version 4 but because of our previous command, the version 5 is already in /tmp. No problem, svn does all the necessary things and indicate them: the a.txt is updated and the new.c file is deleted.
$ cd /path/directory_to_checkout_the_code/svn-repo
$ svn info a.c
svn info a.c
Path: a.c
Name: a.c
URL: svn://localhost/svn-repo/a.c
Repository Root: svn://localhost
Repository UUID: d949aa33-3bf6-4f25-98b7-906b7cb10941
Revision: 4
Node Kind: file
Schedule: normal
Last Changed Author: root
Last Changed Rev: 1
Last Changed Date: 2011-02-17 12:11:51 +0530 (Thu, 17 Feb 2011)
Text Last Updated: 2011-02-17 13:09:23 +0530 (Thu, 17 Feb 2011)
Checksum: 2bb675411b289a4937db4c60e0f96126
3. References:
Subversion Web site: http://subversion.apache.org
No comments:
Post a Comment