CVS

From ICPWiki
Revision as of 11:31, 19 September 2007 by Olenz (talk | contribs) (→‎Creating/Checking in a module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page gives a short introduction on how to use the Concurrent Versioning System (CVS). For further documentation, refer to the CVS manual via info cvs.

Goals

CVS is a tool that helps developers to

  • work on a set of files in parallel and
  • to archive old versions of the files

To do this, CVS maintains a repository that keeps the files and all the necessary information. The repository is typically a subdirectory called <somedir>/cvsroot. Do not modify, delete or copy the files in this subdirectory directly! In the following, it is assumed that the subdirectory is locally accessible. However, it is also possible to access a CVS repository remotely.

Checking out a module

Inside the repository, CVS keeps a number of modules. A module can contain files and subdirectories. Think of a module as a subdirectory.

To be able to work with the files, you need to check out the module into a working directory. The command for this is relatively long and complicated, however, this needs to be done only once. Afterwards, you can work with the files via much simpler commands! The command is

 cvs -d <cvsroot> checkout [-d <workdir>] <module>
  • <cvsroot> is the path to the repository, e.g. /usr/local/cvsroot
  • <workdir> is the name of the working directory that will be created and that contains the files after checkout. If you leave out this option, the name of the module will be used. To check out the files into the local directory, use -d ..
  • <module> is the name of the module

When the command is executed, a subdirectory workdir will be created and all the files and subirs that belong to the module will be put into the directory.

Checking the status of the working directory

The contents of the repository will change, as other people will probably work on the same files. Therefore it is useful to be able to check whether any of the files has changed. To do this, you can use

cvs -n update

This will return a list of files and a one-character code in front of it, e.g.

? config.h
M fft.c

The one-character codes tell the following:

?
The file is not in the repository.
M
The file is modified in your working directory.
U
The file is modified in the repository and needs to be updated (cvs update).
A
The file has been added to CVS. Call cvs commit to actually commit the file.
R
The file has been removed from CVS. Call cvs commit to actually delete the file from the repository.
C
There will be a conflict when the files are merged.

Bringing the working directory up-to-date

When you notice that something has changed, you should update your copy of the files. To do this, use

cvs update

This will incorporate all the changes that have been done to the files in the repository since you last updated them. If you should have changed any of the files that had to be updated, your changes will not be overwritten, but they will be merged into a new version. Usually this works without your intervention, but sometimes a conflict arises. When this happens, CVS will tell you about it and you will have to manually merge the files. Refere to the manual for details.

Commiting changes

Now you can start to do with the files whatever you want. Add some program code, delete some, modify some text, etc. Whenever you want other people to be able to get the changes that you have done, you need to commit the changes to the repository. To do this, simply call

cvs commit

This will compare all the files to the files in the repository, and if a file has changed, it will ask you to give a log message about what you have changed. These messages can be read later on.


Adding and removing files

The working directory may contain files that are not kept in the repository (e.g. compiled programs). Therefore, not every file in your working directory is automatically added to CVS. If you want to add a file to the repository, call

cvs add <file>

When you want to remove a file from the repository, use

cvs remove <file>

In both cases, to have the changes come into effect, you need to call cvs commit afterwards.

Creating/Checking in a module

Creating a new module from a directory that contains files requires the following steps:

  1. Make sure that only the files and subdirectories that should actually go into the repository are in the directory. Remove any generated files (like the .dvi or .aux files from a LaTeX directory), or files that should not go into the repository! Alternatively, you can generate a new, empty directory and just copy a single file there.
  2. Now change into the directory that you want to check in.
  3. Call
    cvs -d <cvsroot> import -m "Imported." <module path> blah whatever
    • blah and whatever are the so-called release and vendor tags. They do not serve any purpose in our case but they have to be present, therefore just use whatever you like.
    • <cvsroot> is the path to the repository, e.g. /usr/local/cvsroot.
    • <module path> is the module name under which the module will reside.
    • Note, that this will not make the directory a working directory, but will only check in the files!
  4. Now move the directory aside, so that it will not be overwritten when checking out the module.
  5. Now verify that everything worked by checking out the module:
    cvs -d <cvsroot> co <module path>
    If everything worked fine, you should now have a working directory that contains all the files that you just checked in.