Saturday, March 20

Subversion , TortoiseSVN and configuring it with XAMPP.

What is subversion ?
As quoted by wikipedia
In software development, Subversion (SVN) (from February 2010 also named Apache Subversion ) is a version-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).
Well above is a formal definition of subversion. But why subversion?
OK, some days back even I did not know what exactly is subversion and why we need it. Read an article on it that said, subversion was extremely useful for keeping a track on and maintaining a project.

BEFORE SUBVERSION (The problem).
I have worked with some web development projects. Have designed some sites from scratch. It was not done in a day. So to keep a track of my everyday changes, either I would write it down on a book, or create a backup copy of the project and rename the folder with the date. For example Project_18thmarch. I know this is LAME but we had to have some kind of record for that. This is very very tedious, eats up lots of your storage, creates multiple copies of your project and also, does not serve the purpose. Instead of making it simple, this makes keeping a track on your project worse.

What subversion does for you?
Well this open source software, keeps a track of your project for you. Not only does it keep track of files, but also watches the file data for you. Any changes in any line of any file is being tracked for you. This software is widely used all over, and also, it helps many developers work on the same project at the same time. It was widely used by open source community for projects for example in projects such as Apache Software Foundation, Free Pascal, FreeBSD, GCC, Django, Ruby, Mono, SourceForge, ExtJS, Tigris.org, PHP and MediaWiki.

Before you read further, a point to note. 
I will be writing here about subversion as an individuals POV. Subversion is widely used when a team is concerned. But here, i have installed it on my local system so that i alone can keep track of it.

GETTING STARTED
Requirements :
1) XAMPP (I am using XAMPP windows version 1.7.1)
(apache version : 2.2.11 ,  php version 5.2.9 , Mysql version : 5.1.33)
2) Subversion
3) TortoiseSVN

Now that I already had installed XAMPP on my windows machine and did not want to disturb its working, I had to search for some tutorials which would allow me to configure subversion with already installed XAMPP.

You can get the latest version of subversion from here. Since we are using Apache 2.2.x, we need subversion which is configurable to apache. A word of advice here , please make sure your subversion is compatible to apache. This will save a lot of time.
I used subversion version 1.6.5 stable i.e (svn-win32-1.6.5.zip : Subversion Win32 binaries for Apache 2.2.x (2.2.11 or higher is required within the 2.2.x series))

TortoiseSVN : It is a subversion client for windows. It has a GUI and helps dealing with subversion repositeries. The latest TortoiseSVN version available is 1.6.7 and you can get it from here.

Procedure :
1) First step is to Turn off your apache , mysql services from your xampp control panel

2) Unzip subversion in your hard disk. My location was C:/Program Files/Subversion

3) Install tortoiseSVN. It is a simple to follow installer. My installation was in C:/Program Files/TortoiseSVN. Once you install it, you can see it in your context menu (Right click on desktop).



4) Now add the subversion bin directory to environment variable. Here is Microsoft’s definition to environment variable

Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.

Right click My computer -> properties -> Advance -> environment variable -> Double click on Path and then add this string. For me it is C:/Program Files/subversion/bin.


5) Next step is to include the mod files, into apache modules. Go to C:/Program Files/subversion/bin and copy the following two files.
mod_authz_svn.so 
mod_dav_svn.so

6) Now Copy the following files from subversion bin directory i.e C:/Program Files/subversion/bin 
intl3_svn.dll
libdb44.dll
Paste the above files into apache bin directory i.e C:/xampp/apache/bin

7) Now you need to change the httpd.conf file from apache.
Go to C:/xampp/apache/conf and open httpd.conf in your editor. Search and Uncomment the following lines

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so


8) Next is to add the location of subversion repositories in your httpd.conf file so that apache knows where to look for them
Add the following lines of code at the bottom in your httpd.conf file.
<location /svn>
   DAV svn
   SVNParentPath c:/svn
   AuthType Basic
   AuthName "All my repositories"
   AuthUserFile c:/svn/passwords
   Require valid-user
</location>
I got this configured from here. You can visit this article; it explains each line of code. I have created a directory called svn in C: drive so that I can keep track of multiple subversion repositories. For this I have used the svnParentPath directive.
We can provide a username and password so that only intended user can get to browse the repositories.
The AuthUserFile directive can be used to provide the password file. You can create this password file through apache’s htpasswd utility for managing the list of acceptable usernames and passwords, those to whom you wish to grant special access to your Subversion repository.
In this example I have created the password file in svn directory.

Go to command prompt (start -> Run -> cmd) and get down to your C: drive.
Browse in to your apache directory in command prompt.
C:/xampp/apache/bin>htpasswd.exe –c C:/svn/passwords admin and then hit enter. You will be prompted to enter a password. This password will be converted to md5 and saved along with your username.
 10) Now Turn On your xampp control panel. And start your apache and mysql services. Sometimes the apache service may not start. It happened to me many times. And the xampp control panel would not give any error. The best step here would be to start apache manually through your command prompt. Go to C:/xampp/apache/bin/apache. The figure below will give a better idea.


What I did was to shut down and restart my system. Also I had first installed a lower version of subversion i.e SVN 1.5.6 and I intended to using it with the latest version of TortoiseSVN 1.6.7. However a lot of google search and some questions over stackoverflow made me realize that I had to use proper versions of both the softwares.

Now create your project folder in svn directory. Name it "test". Now if you point your browser to http://localhost/svn/test then you will be asked for username and password. Enter the required fields and then you get the following error.

I haven’t done any research on this, but my guess is that since we do not have any repositories created yet , we get this error. So let us now create repositories.

What is a repository?
The repository stored information in the form of a file system tree – typical hierarchies of files and directories. Repository is kind of a file server, but what makes the subversion repository special is that it resembles every change ever written, and even changes to the directory tree itself, such as the addition, deletion and rearrangement of files and directives.
Our next step is to create a repository. Go to the test folder and right click on it. Select tortoise svn and then select create repository.


Now you can point your browser to http://localhost/svn/test
Enter the username and password.
It shows revision 0. This is the default revision, and since we do not have any files in the repository , it is empty.
Let us create our first project and import some files in the repository.

1) We create a test folder in our root folder. i.e in htdocs folder. Next we create a php file and enter some text in it. Now we need to import this project in our repository.


2) Now import this Project in your repository.Right Click on the project folder, i.e test in my case, then select Tortoise SVN and then select Import. After clicking on import you will have to select the repository directory. In my case it is file:///C:/svn/test
You can add a message to your import. Try to be descriptive in your message so that it helps in future.


After you click OK, the import will take place.
3) Now that I have created a repository, Next step is to start working on the project. For that we do a svn checkout. Svn checkout will help you get the latest working copy of your project from the repository. Go to your htdocs folder in C:/xampp/htdocs and right click. Click on SVN Checkout.



After SVN checkout is finished, it will show the revision number which is revision 1. And then you will have a working copy of your project.
The working copy has a green tick mark. Even the files inside the folder get a tick mark.

4) Now you can start working with your project. But first thing to note here is. Every time your work on your project, make sure you update the working copy. This is useful when there are many developers working on the same project simultaneously.
Right click on your working project, i.e Test folder and then SVN Update.


5) You can now start creating new files, or edit your old files. The new files added, edited will then be shown with a red image. This tell us that, these new files are added and yet to be committed in the repository.

6) After making changes you can then commit with SVN.

PS: I am no expert in SVN and in a pursuit to learn more about it. I had a very difficult time configuring SVN with XAMPP. The reason being.
a) I had installed a lower version of SVN and a higher version of Tortoise SVN. They were not compatible with each other. I learned about it, when I spent some time reading the documentation. So it is worth noting here, that whenever you install any software, check for its version and check for its compatibility.
b) On my machine XAMPP starts automatically on windows. I did not take much care about xampp, but when copying the mod files in module, it gave errors. So it is better to stop all the xampp services, configure your subversion and TortoiseSVN  and then restart your XAMPP.
c) Sometimes some changes do not affect immediately. It is a good practice to restart your system.


I hope this article helps anyone who wants to get started with subversion. This is a beginner lever tutorial. I have tried to avoid any mistakes, but if you find any, please point it out.

References and credits.
http://timepoorprogrammer.blogspot.com/2008/05/pretty-up-your-svn-repositories-via-web.html
http://summersoft.fay.ar.us/pub/subversion/Book/ch06s04.html
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-intro-features.html
http://serk01.wordpress.com/2008/09/21/how-to-create-your-own-home-svn-repository-with-xamppapache/

I had also posted a question on stackoverflow.com. This is a very good site and you get a lot of help from people with similar interests in programming.

Thursday, March 11

Facebook and 2 reasons why it sucks.

Facebook is a place to hangout. It is suppose to be a fun place. Take a survey and you will not be surprised to find that majority of the people log in to facebook first thing in the morning. Now that facebook is super fast and that there are so many things you can do on this No.1  social networking site, here are two points which users should not do.
P.S : This is my opinion.

1) STOP LIKING YOUR OWN POSTS.
First things first. why the hell you have to like your own posts. Does it not make sense that you would have not posted, if you had not liked it in the very first place. OK, before we go any further, you can read a blog post by facebook on the "I like this" feature. This post tells us what was the actual reason for this feature to get implemented. This helps your friends to express their views in just one click. YOU DO NOT HAVE TO LIKE YOUR OWN POST. Wtf is wrong with you? Get a life.


2) FAN.
You become fan of aamir khan, amitabh bachan, sachin tendulkar, Adolf Hitler, Osama bin Laden. It sounds great. you become fan and then you contribute your thoughts and learn about from other's comments. You share knowledge. You can learn about facebook pages here. But what happens when some crazy people create pages and then there are more stupid people (thousands in number) who become fans?? NOTHING HAPPENS. People become fans and then comment once or twice and then do not even bother about it later.
Ok, thats not the end. We have users who become fans because they just like the fan club.For example the "I HATE CIGERATES fan club" Yup they exists. I have one question. What do you try to prove by becoming a fan. You become fan of things you hate? Seriously this is so fucked up.
 PS : This is just a fun post. Your comments on this are valuable. You may not like this post and if that is the case, you should know that  i am working on the like feature on blogger so that i can start liking my own posts.