Выбрать главу

Figure 8.19: Add Repository dialog.

Click Finish. You’ll find a new entry in the CVS Repositories view. Expand that to look like Figure 8.20. Each time you expand an entry by clicking on the right arrow, Eclipse goes out to the server to retrieve the information for that directory.

Figure 8.20: CVS Repositories view.

Right-click one of the file entries under the ecrobot directory and select Show History. The History view (Figure 8.21) now shows the full history of this file including author, timestamp, comments, and so on. You may have to expand the Older than This Month entry to see the history. There’s not much here, but it gives you the idea.

Figure 8.21: CVS History view.

Other items in the CVS Repositories view context menu include Show Annotation and Open, both of which retrieve the file from the repository and open it in a read-only editor window.

Having connected to a repository, we might want to check out some or all of the contents to work on locally. Right-click the ecrobot entry again and select Check Out. Eclipse retrieves all the files in ecrobot and creates a new project of the same name in the default workspace. The Console view shows the CVS commands and responses.

Go back to the C/C++ perspective and you’ll see that the ecrobot project is identified as having come from a CVS repository. All the files have their version number listed, and are identified as ASCII files.

Select Properties from the context menu for ecrobot. There’s a section called CVS shown in Figure 8.22. This lists all the properties of the repository from which the project came. You can now edit the files in the local project.

Figure 8.22: Project CVS properties.

The next thing we might want to do is create a branch where we can safely share the project files with other team members, and make changes until we’re ready to check them back into HEAD. The branch is created on the repository server and requires write access, which anonymous users normally don’t have.

8.2.3 Setting Up a CVS server

To continue our exploration of CVS, you’ll need write access to a CVS server. If you don’t have one, there’s a nice server called CVSNT that runs both on Windows and Linux, that’s available from http://www.cvsnt.org/. CVSNT was originally developed to provide CVS server functionality under Windows and was later ported to Linux. The download for Linux is in the form of a gzipped RPM.

There’s a fairly complete installation guide for Linux at the cvsnt.org wiki at http://www.cvsnt.org/wiki/InstallationLinux, so I won’t bother going into a lot of detail here. You only need to install the required package, cvsnt2.5.03.2382-1.i386.rpm. None of the optional database or protocol packages are necessary for our purposes.

There are a couple of incompatibilities between Eclipse and CVSNT that need to be dealt with. RPM created a cvsnt/ directory under etc/ with files Pserver.example and Plugins.example. Copy Pserver.example to Pserver and open it in an editor. Find a line that says #Compat0_OldVersion=0 and uncomment it by deleting the #. Then uncomment the line #Compat0_OldCheckout=0 a little farther down.

You’ll need to create an initial CVS repository. Create a directory in a suitable place, /usr/local/cvsroot is what I chose, and then as root user execute:

cvs –d /usr/local/cvsroot init

Back in the CVS Repositories view, right-click and select New→Repository Location…. This brings up the Add Repository dialog we saw in Figure 8.19. This time the entries are:

Host: localhost

Repository path: <your_repository_path> (/usr/local/cvsroot)

User: <your_user_name>

Password: <your_password>

Connection type: extssh

The new repository looks something like Figure 8.23. The HEAD and Versions nodes have the requisite CVSROOT entries, but are otherwise empty, as is the Branches node. Our next task then is to add a project to the repository that we can share with other members of our team.

Figure 8.23: New local CVS repository.

Let’s use the thermostat project as an example. Go to the C/C++ perspective and right-click thermostat in the Project Explorer view. Select Team→Share Project…. The first dialog box gives you the choice of using an existing repository or creating a new one. Highlight your local repository and click Next. Here you have a choice of module naming options. Keep the default, Use project name as module name. Click Next.[13]

The next dialog lets you select which of the project’s resources to share (Figure 8.24). Typically you want to share all of them. Click Finish to launch the Commit wizard.

Figure 8.24: Share Project Resources dialog.

Interestingly, the Commit wizard finds a couple of files with “unknown names or extensions” and asks you whether they are binary or ASCII. .cdtproject is in fact ASCII. thermostat_s is binary. Finally, you can enter a comment for the commit operation. Something like “Adding new project” might be appropriate.

The thermostat project is now identified as being under CVS control on the localhost and all the resource files have version numbers. Back in the CVS Repository Exploring perspective, thermostat now shows up as an entry under HEAD in your local repository.

8.2.4 Team Synchronizing

Having committed the project to CVS, we can continue working on our own copy in the workspace and later synchronize any changes with what’s in the repository. Make some minor change to thermostat.c, add a comment, perhaps. When you save the changes, greater-than signs (>) appear next to the project name and the file, indicating changes that will need to be checked in to the repository.

Right-click thermostat.c in the Project Explorer view and select Team→Synchronize with Repository. This brings up the C Compare Viewer, showing the differences between the Local File on the left and the Remote File in the repository on the right (Figure 8.25). Icons in the tool bar let you step through the differences. You can also copy any non-conflicting changes from the Remote File to the Local File, that is, from right to left.

Figure 8.25: C Compare Viewer.

Where a team of developers is involved, it’s quite likely that the file in the repository, the Remote File, contains changes from someone else. The C Compare Viewer highlights those changes as well. In practice, you should perform a Team→Update operation on the file before synchronizing with the repository. 

Now you can commit the new version back to the repository. Right-click thermostat.c and select Team→Commit…. This operation is also known as “checking in.” You’re prompted to enter a comment for the commit operation. Then click Finish. The new version is written back to the repository.

вернуться

13

I encountered an error at this point: “Errors saving CVS synchronization information to disk.” CVS created a hidden directory, .settings, in the project workspace that is owned by root and not world-writable. Changing the permissions fixed the problem.