Saturday, September 23, 2006

My First Experience with Subversion

For some time now I have wanted to play around with SubVersion. I have a college professor friend of mine who raved about it when it first came out some years ago. Finally, Scott Rosenbaum of the BIRT PMC convinced me to take a look at it a little more in depth.

The following instructions are centered around an Ubuntu 6.06 platform, so modify as you will for your platform of choice. First thing to do is to install Subversion. Using the Apt, it is a piece of cake. I drop to a root console and run “apt-get -f install subversion”, as indicated below:

root@digiassn-laptop:/usr/sbin# apt-get -f install subversion
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
libsvn0
Suggested packages:
subversion-tools db4.3-util
The following NEW packages will be installed:
libsvn0 subversion
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 716kB of archives.
After unpacking 4342kB of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1 http://us.archive.ubuntu.com dapper/main libsvn0 1.3.1-3ubuntu1 [513kB]
Get:2 http://us.archive.ubuntu.com dapper/main subversion 1.3.1-3ubuntu1 [203kB]Fetched 716kB in 2s (269kB/s)
Selecting previously deselected package libsvn0.
(Reading database ... 112788 files and directories currently installed.)
Unpacking libsvn0 (from .../libsvn0_1.3.1-3ubuntu1_i386.deb) ...
Selecting previously deselected package subversion.
Unpacking subversion (from .../subversion_1.3.1-3ubuntu1_i386.deb) ...
Setting up libsvn0 (1.3.1-3ubuntu1) ...

Setting up subversion (1.3.1-3ubuntu1) ...

One thing to note is I believe Apache 2 may be a pre-requisite or optional package. Since I already have Apache 2 and Tomcat installed for use with BIRT, these were not shown in the above transcript. Cool, now that it is setup, I noticed that there are not executables for it... strange. So I read the Subversion quick-start guide to get an idea of what I am doing. Aha, so there are command line tools and they are prefixed as svn... so we have an “Svn” to interact with Subversion, and an svnadmin to administer Subversion.

Here, I want to create a repository containing all my BIRT reports for a project I am working on. The first thing I do is create that repository using svnadmin. I want to call this repository “BirtReports” and store them under my home directory at /home/digiassn. Using my general account, I run the commands like so:

digiassn@digiassn-laptop:/etc/default$ svnadmin create /home/digiassn/BirtReports
digiassn@digiassn-laptop:/etc/default$ cd /
digiassn@digiassn-laptop:/$ cd home/digiassn/BirtReports/
digiassn@digiassn-laptop:~/BirtReports$ ls -alF
total 36
drwxr-xr-x 7 digiassn digiassn 4096 2006-09-23 18:21 ./
drwxr-xr-x 56 digiassn digiassn 4096 2006-09-23 18:21 ../
drwxr-xr-x 2 digiassn digiassn 4096 2006-09-23 18:21 conf/
drwxr-xr-x 2 digiassn digiassn 4096 2006-09-23 18:21 dav/
drwxr-sr-x 5 digiassn digiassn 4096 2006-09-23 18:21 db/
-r--r--r-- 1 digiassn digiassn 2 2006-09-23 18:21 format
drwxr-xr-x 2 digiassn digiassn 4096 2006-09-23 18:21 hooks/
drwxr-xr-x 2 digiassn digiassn 4096 2006-09-23 18:21 locks/
-rw-r--r-- 1 digiassn digiassn 229 2006-09-23 18:21 README.txt

OK, so I have a tool that creates a bunch of arbitrary directories. Well, not necessarily. It actually uses its own database to store your versioned files, so when I import them into Subversion, i wont get to see them. So, I want to check in my BIRT reports, which are stored at /home/digiassn/eclipse/workspace/OldReports. To check these files into Subversion, I can run the following command:

digiassn@digiassn-laptop:~/BirtReports$ svn import /home/digiassn/eclipse/workspace/OldReports file:///home/digiassn/BirtReports -m "BirtProject Initial Import"
Adding /home/digiassn/eclipse/workspace/OldReports/EventsSummaryByIP.rptconfig
Adding /home/digiassn/eclipse/workspace/OldReports/GetIPSummary.rptconfig
Adding /home/digiassn/eclipse/workspace/OldReports/sguilLibrary.rptlibrary
Adding /home/digiassn/eclipse/workspace/OldReports/eventsByStatus.rptdesign
Adding /home/digiassn/eclipse/workspace/OldReports/GetStatus.rptdesign
Adding /home/digiassn/eclipse/workspace/OldReports/.project
Adding /home/digiassn/eclipse/workspace/OldReports/DemoForBook
Adding /home/digiassn/eclipse/workspace/OldReports/IpEventDetail.rptconfig
Adding (bin) /home/digiassn/eclipse/workspace/OldReports/sguil_logo2.png
Adding /home/digiassn/eclipse/workspace/OldReports/GetStatusInfo.rptconfig
Adding /home/digiassn/eclipse/workspace/OldReports/EventSummary.rptdesign
Adding /home/digiassn/eclipse/workspace/OldReports/eventsByStatus.rptconfig
Adding /home/digiassn/eclipse/workspace/OldReports/GetStatus.rptconfig

Committed revision 1.

Sweet, now I've stored my old reports into Subversion. So lets say I want to check these files out now. I can run the command below:

digiassn@digiassn-laptop:/$ cd /tmp
digiassn@digiassn-laptop:/tmp$ svn checkout file:///home/digiassn/BirtReports/
A BirtReports/EventsSummaryByIP.rptconfig
A BirtReports/GetIPSummary.rptconfig
A BirtReports/GetStatus.rptdesign
A BirtReports/eventsByStatus.rptdesign
A BirtReports/sguilLibrary.rptlibrary
A BirtReports/.project
A BirtReports/DemoForBook
A BirtReports/IpEventDetail.rptconfig
A BirtReports/sguil_logo2.png
A BirtReports/GetStatusInfo.rptconfig
A BirtReports/EventSummary.rptdesign
A BirtReports/GetStatus.rptconfig
A BirtReports/eventsByStatus.rptconfig
Checked out revision 1.
digiassn@digiassn-laptop:/tmp$ cd BirtReports/
digiassn@digiassn-laptop:/tmp/BirtReports$ ls
DemoForBook EventsSummaryByIP.rptconfig GetStatusInfo.rptconfig IpEventDetail.rptconfig
eventsByStatus.rptconfig EventSummary.rptdesign GetStatus.rptconfig sguilLibrary.rptlibrary
eventsByStatus.rptdesign GetIPSummary.rptconfig GetStatus.rptdesign sguil_logo2.png

What was easy enough. So, back to the problem that triggered this. I wanted to checkout the files that Scott had on his super secret server so I can view a project he was working on. This was put online using a web server for viewing, so below is the transcript of how I pulled the project in question.

digiassn@digiassn-laptop:/tmp$ cd /tmp
digiassn@digiassn-laptop:/tmp$ mkdir gwt
digiassn@digiassn-laptop:/tmp$ cd gwt
digiassn@digiassn-laptop:/tmp/gwt$ svn checkout http://scotts_super_secret_server/gwt
A gwt/DynaTable
A gwt/DynaTable/.classpath
A gwt/DynaTable/.project
A gwt/DynaTable/src
A gwt/DynaTable/src/com
...remaining files removed for brevity.
Checked out revision 28.

Pretty neat. I have seen CVS systems that can do the same thing, however. By looking in the documentation, there are tons of options for how to run Subversion. You can run a daemon to allow multiple repositories, add user authentication, and integrate authentication with SSH, plus a whole slew of other features.

1 comment:

Scott Rosenbaum said...

http://scotts_super_secret_server??

Next thing, you will release the TOP SECRET user and pass :)

Subversion is really a nice upgrade over CVS. The Eclipse tools for integration are good, but with two projects focused on full integration of Subversion into CVS, it looks like the plugins will become even better and more wide-spread in use.

scott (super secret server guy)