JaVa
   

CVS Pitfalls and Solutions

CVS can be cryptic to understand at times. Here are some common stumbling blocks, along with solutions

Up-to-Date Check Failed for "file"

You will most likely see this during your CVS career. It is a highly recommended practice to always call cvs update before attempting to commit files into the repository. CVS will give this message when you attempt to commit a file that has been modified in the repository since the last time you updated. Update your working copy, resolve any merge conflicts, and call commit again.

Recovering a File Deleted with "cvs remove"

When a file is in the way and no longer needed, you remove it from the repository with cvs remove. However, you may later decide the file is needed once again. There are several bad ways to fix this problem; we will use a safe way. Assuming you would like to recover the most recent version of the file before it was removed, you can trick CVS into giving you the file back. At the end of the CVS Foundations section, we removed Test.java from the local repository. To recover the file:

[wrox@linuxserver client]$ cvs update -j1.2 -j1.1 Test.java cvs update: warning: Test.java was lost U Test.java RCS file: /home/wrox/cvsroot/client/Attic/Test.java,v retrieving version 1.2
retrieving version 1.1
Merging differences between 1.2 and 1.1 into Test.java


Now you can commit the file and keep on working.

CVS Files in Source Drops

Often, as part of a source drop or an automated build and deployment solution, a snapshot needs to be taken of the repository. In such cases the CVS specific directories aren’t needed and in fact just clutter up the distribution. To get a clean snapshot of the repository, use cvs export instead.

Using CVS on the Windows Platform

A Win32 port of CVS is freely available on the Internet. However, there are a couple of common issues to be aware of:

Resolving Merge Conflicts

When more than one devloper works on the same file at the same time, one of them will commit it first. The other developer, not as quick on the draw or perhaps with larger changes, is then stuck resolving merge conflicts. CVS will warn you when there are merge conflicts. If you don’t see these messages, don’t worry, the compiler will catch them for you when attempting to build the project. A CVS merge conflict message will look something like this:

Merging differences between 1.1 and 1.2 into Test.java rcsmerge warning: overlaps during merge cvs update: conflicts found in Test.java


Now, you must find the merge conflicts in the file. Using your editor, open the file and search for <<<, the string CVS uses to mark the beginning of a merge conflict. The conflict area will look something like this:

<<<<<<< Test.java
 test.doSomething(test.new InnerPeace());
=======
 test.doSomething(test.new InnerConflict());
>>>>>>> 1.2


The first part, the less than signs, shows the offending area in your local copy. All of your code will be between this marker and the line of equals signs inserted by CVS. After the equals signs is the code that was in the most recent version in the repository, up to the line of greater than signs. After the greater than signs the file is fine (unless there are more merge conflicts; these will be marked in the same fashion). Determine what should be kept, and commit the file.

Using CVS from NetBeans/Forte

Updating source files from within the IDE is a great feature available in many of the popular Java editors today. NetBeans has an excellent CVS client implementation; to use it, follow these steps:

  1. Create a new project that will contain the files you intend to get from CVS.

  2. Right click on filesystems; CVS is mounted just like a local directory or JAR file.
  3. Now we can set up the CVSROOT connect string similar to how it was done on the command line.
  4. Click next and login into the CVS remote server, with the credentials we created earlier in the chapter.
  5. At the last step, we need to choose a module to check out. Remember that we created a module called projosdev during the CVS server setup. Type projosdev in the Checkout text area, and select OK.

NetBeans will do an initial checkout of the files in the projosdev module. Notice that NetBeans displays the current CVS status of all files mounted in filesystems beneath the working directory you chose. This is fairly helpful especially when other developers may modify files, and the [Ncheckout] status message appears. When you right click on the files located beneath the CVS mount, a CVS menu appears now. This menu contains all the CVS commands needed to do all the versioning described in this chapter through NetBeans.

To add arguments to CVS commands in the right click menu, hold down the CTRL key.

Other Software

If you are performing development on the Windows platform and using CVS for source code management, you may find WinCVS useful. The tool is written in C++ and distributed freely under the standard GPL. Download from http://www.wincvs.org/. Many developers find it a boon to be able to store snippets of code, or entire projects, on a central server so they can look up solutions to problems wherever they go. HTTP is still the most firewall-friendly way to access data from work. There are many tools facilitating the administration of repositories and browsing of source trees over HTTP. One of the originals is WebCVS, which can be found at http://stud.fh-heilbronn.de/~zeller/cgi/cvsweb.cgi/.

CVS Home (http://www.cvshome.org ) contains browsable CVS manuals in HTML form, as well as a wealth of FAQ and How-To resources and links to other CVS pages.


JaVa
   
Comments