Ranlak Web Dev

Carving your ideas on to the Web!

Posted by admin on September - 22 - 2010 | 0 Comment

Its only lately that I stepped up to use Version Control for my Projects. The need was there, but being self taught, there are limitations to what one can formulate to search on Google. :-) I hope that made sense… :-)

So I was introduced to Subversion or SVN, as my friends call it. Its a Version Control package that is Open Source, but maintained and customized by several companies and clients. Its released for many platforms and more details are found at subversion.tigris.org

My main aim in writing this post is to iron out some confusing issues I encountered while installing Subversion on a Windows (XP SP3) box. Plus my intention and lateness of using “Version Control” is cheifly because I develop usually alone. Thus having no fancy LAN to share my projects with, all I was looking for is Version Control on my trustworthy Windows box.

I use Notepad++ all the time, because through experience I dislike Dreamweaver, and similar IDE’s. Notepad++, being open source, having similar features to many IDE’s, yet retaining the good ol’ windows notepad feeling, was my tool all this time. Yet, while at a Job interview recently, I was amazed at the features of Eclipse PDT, a Java IDE for PHP. So much for the interview I guess….

Eclipse supported SVN and CVS (the not so much used, kinda old Versioning System). So I set out to install Eclipse, SVN and TortoiseSVN (which is a cool windows interface for SVN). Later I found out that Notepad++ could also in conjunction with TortoiseSVN and another plugin deliver version control.

Let me explain what all these are for, as newbies out there must be getting swirly.

  • To install Subversion all you need is one package from the several mentioned in the windows section of subversion.apache.org. I prefer SilkSvn which is just plain Subversion. Other Packages have Apache servers built into them, with extra doodles. Subversion has its own server software called svnserve.exe, but as Apache is very extendable, SVN can work super well with Apache.
  • Eclipse PDT – PHP IDE needs a plugin called Subclipse to handle Subversion. Both open source.
  • TortoiseSVN – really cool Windows Client for SVN. Needed if you are going to use SVN with Notepad. Also open source.
  • If your using NotePad++ you will need this Notepad plugin, Notepad++ SVN to interface with TortoiseSVN

That’s all the software you need. Now installation. I’m assuming that you have either Eclipse or Notepad++ already installed. If not you should do so now. If you have Eclipse or are installing Eclipse, install Subclipse as well. If you have Notepad++ or installing it, install its SVN plugin too.

Installation of SilkSvn is pretty straight forward. It even adds its parent directory name to %PATH%, so that you can access it from anywhere. After installing SilkSVN install TortoiseSVN. After rebooting you will see, that Tortoise has neatly been integrated into the windows context menu (the one you get when you right click your mouse).

Now a little bit into using SVN. Subversion stores your project file in a file Repository. You can keep track of any individual file you commit to the repository. E.g. when you have modified a source file and “commit” the file to the repository, Subversion analysis the file with its latest copy (or “head” copy). If truly modified, SVN asks you for a comment, and saves both new file and comment in its repository with a new version number.

The beauty lies in the fact that you can recall back later any version of that source file you have committed! E.g. Current “head” version is 10, and there are versions 2, 6 and 8 of the same file. (Subversion sequentially numbers files, in the order they were committed. So this particular file was committed 4 times from the start.) You can retrieve version 2 and start off in a new direction of development. This is called “branching”. You can switch between branches, by changing files in your “Working Copy” with the relevant branches in your repository. You can even “merge” a branch into your main branch – the “trunk”. When you need to get a snapshot of a branch, you can “tag” the branch and explore the code.

The Subversion Manual & TortoiseSVN help file was great in both understanding the concepts of Subversion and TortoiseSVN.

So on with making a repository (repo):

  • if you have TortoiseSVN, just make a folder in your intended drive (better to not use network drives… more chance of data getting corrupted), right click on it and choose TortoiseSVN >> Create Repository here.
    create repository

    Create repository woth TortoiseSVN

  • Otherwise, just click “Run” in your start menu, type “cmd” and press enter. You will get the Windows command prompt. At the prompt type
svnadmin create drive:\folder\
E.g: C:\>svnadmin create c:\repo\

As you see, TortosieSVN is much easier….

Repo Contents

  • Either way, inside the folder sits the new repository, which consists of 4 folders and 2 files. This structure will not change even when you start adding files.
  • You should make sure nothing damages this folder structure. As good practice you should back this up ever so often and keep the backups separate from the working repo.
  • Its generally a good idea to not store the repo on the same drive that has the operating system, i.e Windows installed on. Obviously, if your operation system, or disk were to crash the boot drive has greater chances of being damaged. (I always partition my Hard drive into several drives, and install Windows  in one of them.)

Adding files to your Repo:

  • Ideally, create a new folder. Name it something like “new”, temporarily. Inside it create 3 folders called “trunk”, “branches” & “tags”.
  • Copy all the files of your project to the “trunk” folder.
  • Now, click on the folder “new” and right click mouse and click TortoiseSVN >> Import. A dialog pops up and asks for your repository URL, and a comment. Type in a comment. For URL we will use Subversion ‘file:///’ protocol.
    file:///drive:/repo folder/
    E.g: file:///C:/repo
  • Clicking ok, will start adding your files to the repository.

    TortoiseSVN Import Dialog

    TortoiseSVN Import Dialog

  • Once this is done, go to the drive where your repo is and right click the repo folder and choose TortoiseSVN >> Repo-Browser, to see the newly added contents.

    Repository Browser

    Repository Browser

  • Now your repo is made and filled with version 1 of your software. To easily make changes and update version, you have to make a “Checkout”. To do this click the specific drive you want and right click the mouse and choose SVN Checkout. A dialog pops up asking the repo URL and and Checkout folder destination, how many levels of subdirectory’s to output and what version. Usually, we can output the “HEAD” version which is the latest of all the files. Successful execution of this, creates a folder in the drive you chose.
  • Now you can make any new changes to files inside this folder, whenever you want. TortoiseSVN would detect any modifications and accordingly change the  icon of the corresponding file. You may right click on either individual files or the whole folder and choose SVN Commit, and the file(s_) would be updated to the repo, with incremental version. All this means is whichever files had modifications would now have a version number one higher than they did.
  • Best of all, you can retrieve all versions of each file. You can use any version of these files to branch of in other directions of your development plan.

This is a bare usage guide and an in depth usage tutorial is beyond this posts scope. Perhaps in a another post….

If you set up the SVN server [svnserve.exe], you can enjoy SVN services over the “svn://” protocol. The major benefits of the “svn://” protocol over the “file://” protocol are

  • you can limit access to specific usernames with password and other configurable rules.
  • Faster access to repo through LAN, provided you punch a hole for port: 3690 in your router / firewall

to start SVNserve, just visit the command prompt and type:

C:\>svnserve -d

Don’t close the window because it may seem like nothings happening and svnserve.exe got hung. Actually that is how it is and svnserve is ready to serve! Just open the repo browser and type in for repo url:

svn://localhost/repo folder name
E.g. svn://localhost/repo

And voila! I hope…

For those whom the open window becomes a nag just create a windows service like:

C:/>sc create svnserver binpath= "c:\svn\bin\svnserve.exe --service -r c:\svn\repository" displayname= "Subversion" depend= Tcpip start= auto

Then just this once you will have to start the service manually, by typing the following:

C:/>net start svnserve

Next reboot onwards svnserver will be automatically loaded and be available all the time without any nagging command prompt windows.

Happy Subversioning!