8.5. Subversion

As an initial idea subversion serves to manage a set of files (repository) and its different versions. It is relevant to note that we do not care how the files are saved, but rather how we can access them, for which it is common to use a database. The idea of a repository is like a directory from which we want to recover a file of one week or 10 months ago based on the database status, to recover the latest versions and add new ones. Unlike cvs, subversion makes global revisions of the repository, which means that a change in a file does not generate a leap in version of that file only, but also of the entire repository, which adds one to the revision. In addition to the book we have mentioned (http://svnbook.red-bean.com/nightly/es/index.html), consult the documentation at http://subversion.tigris.org/servlets/ProjectDocumentList.

In Debian, we will have to type apt-get install subversion, if we wish to publish the repositories in Apache2 apt-get install Apache2-common and the specific module apt-get install libApache2-subversion.

If we add another line file1.txt with echo 'date'>>file1.txt, then we will be able to upload the changes with: svn commit -m"New line".

It is possible to compare the local file with the repository file, for example we add a third line to file1.txt with echo 'date'>>file1.txt, but we do not upload it and if we want to see the differences we can run: svn diff.

This command will highlight what the differences are between the local file and those of the repository. If we load it with svn commit -m"New line2" (which will generate another version) then the svn diff will not give us any differences.

We can also use the command svn update within the directory to update the local copy. If there are two or more users working at the same time and each one has made a local copy of the repository and modifies it (by doing commit), when the second user goes to commit their copy with their modifications, they will receive a conflict error, since the copy in the repository has a more recent modification date than this user's original copy (in other words, there have been changes in between), meaning that if the second user runs commit, we could lose the modifications of the first one. To do this, we must run svn update which will tell us the file that creates a conflict with a C and will show us the files where the parts in conflict have been placed. The user must decide what version to keep and whether they can run commit.

An interesting command is the svn log file1.txt, which will show all the changes that have been made to the file and its corresponding versions.

An interesting feature is that subversion can run in conjunction with Apache2 (and also over SSL) to be accessed from another machine (consult the clients in http://svnbook.red-bean.com/) or simply look at the repository. In Debian Administration they explain how to configure Apache2 and SSL for Sarge, or as we already indicated in the part on servers. For this, we need to activate the WebDAV modules (see http://www.debian-administration.org/articles/285 or in their absence http://www.debian-administration.org/articles/208.

As root user we type:
mkdir /subversión chmod www-data:www-data

So that Apache can access the directory
svnadmin create /subversion

we create the repository
ls -s /subversion

-rw-r--r-- 1 www-data www-data 376 May 11 20:27 README.txt drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 conf drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 dav drwxr-xr-x 2 www-data www-data 4096 May 11 20:28 db -rw-r--r-- 1 www-data www-data 2 May 11 20:27 format drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 hooks drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 locks

For authentication we use htpasswd (for example with htpasswd2 -c -m /subversion/.dav_svn.passwd user created as www-data. We only have to type the -c the first time that we execute the command to create the file. This tells us that in order to access this directory we need a password (which is the one we have entered for user).

Then we will need to change the httpd.conf so that it is something like:

<location /svn>     DAV svn     SVNPath /subversion     AuthType Basic     AuthName "Subversion Repository"      AuthUserFile /subversion/.dav_svn.passwd     Require valid-user </location>

We reinitiate Apache and now we are ready to import some files, such as:

svn import file1.txt http://url-server.org/svn \ -m "Import Initial"

We will be asked for authentication (user/password) and told that the file file1.txt has been added to the repository.