Set Up Source Control Repository

This is a quick post on how to setup a CVS repository. There are millions of articles like this but I figured I should contribute to the pile. This is how I’ve set up my repository. A code repository is where your code be held and where other developers can check out code and make modifications without worrying if they are overwriting other people’s work (this is not always true though). The repository will handle versioning the files and keeping track of revisions. It allows you to set points in which you can always revert back to in case of a problem.

Setting up a repository is quite easy. The most common one today is called CVS. A new alternative is called subversion, which is gaining popularity and is seen as the heir to CVS.

There are many articles that cover setting up CVS repository, but we will review it quickly. You can install CVS with your favorite package manager (apt, rpm, etc) or download the source or binaries from the cvs website.

How to Set Up CVS
First create a directory on a server accessible to developers. In this example we will create it in the directory /var/. In the shell prompt, type the following:

$ mkdir /var/cvsroot

Next, we set an environment variable with the path to your cvsroot. Use the following code to set the environment variable temporarily. If you do not want to set this variable every time you login you can tell your shell do it at login. Do this by adding the following line to ~/.profile.

$ export CVSROOT=/var/cvsroot

After CVSROOT is set CVS knows where the repository is and we can now initialize the repository. Initializing means creating the proper CVS directory structure that will hold metadata about the repository.

cvs init

Don’t worry about running cvs init multiple times. Even after you have a full repository you can call cvs init and not lose any of your information.

If you have preexisting code and you want to import to your repository, enter the root directory of the project and use the import option.

$ cd /path/to/projectname/
$ cvs import –m "initial import" projectname VENDOR_NAME  RELEASE_TAG

This command imports all the code in the current directory and puts it into cvs repository. The -m option gives the message “initial import” to all the files being imported. projectname gives the project a name; it does not use the directory you are currently in as the project name. The vendor tag is VENDOR_NAME in the example above. This can be your company name or name of application. And the release tag is RELEASE_TAG which describes what the release name is for this version of the code. (source)

Set up ViewCVS
Browsing CVS on its own its not very intuitive. You cannot simply open a file in the repository easily understand what changes have occurred. Luckily there is a program called ViewCVS, which pretty much does exactly that. Mostly every developer has seen it or used it. It is used by most open source projects. It’s also a great tool to have around to study code.

Installation is fairly simple. First download the latest version of ViewCVS and then extract its contents.

$ tar –zxf viewcvs-.tar.gz
$ cd viewcvs
$ ./install-viewcvs

For this installation just use default options. Next go to the directory you installed it.

$ cd /usr/local/viewcvs

and with your favorite editor open viewcvs.conf

$ jed ./viewcvs.conf

and look for :

cvs_roots = Development : /var/cvsroot

# this is the name of the default CVS root.
default_root = Development

If you need to change the path to your cvsroot set the variable cvs_roots to your repository. Next, set a other ScriptAlias in your apache’s httpd.conf

$ jed /etc/httpd/httpd.conf

Add the following line where you see other ScriptAliases.

ScriptAlias /viewcvs "/usr/local/viewcvs-0.9.2/cgi/viewcvs.cgi"

Restart httpd by typing:

$ apachectl restart

Now we have a repository and a way to view it. If you want to see it in action type the following: www.yourhostname.com/viewcvs. If you want viewcvs to be in a different directory just change the ScriptAlias line to ScriptAlias /yourpath

This entry was posted in Technology. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>