< Zurück | Inhalt | Weiter >

8.2.1 Setup

Before you can use CVS to track your sources, you need to initialize a reposito- ry. You can use this repository for several different projects, so you only need to do this setup once.

There are two different ways to connect to a repository—directly on a filesystem, or indirectly over a network. We will use the simpler filesystem mechanism for this discussion. The network connections are described in the references at the end of this chapter.

In order for CVS to know where the repository is located and how to connect to it, it looks for an environment variable called CVSROOT. You can assign a value to CVSROOT from the command line each time you create a CVS project, or for more convenience, you can set it in the shell startup script (e.g., .bashrc) so that its ready all the time. The CVSROOT value is really only


used, though, to set up the project. Once a project is established, the informa- tion in CVSROOT is kept, along with other data, in a directory of files (called CVS). From that point on, CVSROOT (the environment variable) no longer needs to be set. The CVS commands will always use what is in the local sandbox to determine where the repository is; the value of the environment variable will be ignored.

It is possible to have different repositories for different projects. One repository might be for your personal work—revisions of memos and docu- ments that you create on your local machine and store in a repository also on your local machine. Another repository might be a shared network-based repository, used for a project at work. Still another might be a network-based project for some Open Source work that you do in your spare time. Since the CVS repository keeps track of whence it comes, you needn’t set a value for CVSROOT every time you switch projects. Instead, CVS knows from within the sandbox where to go for its updates, commits, and so on.

So let’s get started and create a CVS repository on our local Linux system, in our own home directory. We will call the repository srcbank, as it will be the “bank” where we will deposit our source files.


$ mkdir ${HOME}/srcbank

$ export CVSROOOT="${HOME}/srcbank"

$ cvs init


The mkdir creates the directory named srcbank as a subdirectory of our home directory. The export command sets the shell variable CVSROOT to refer to the location of the new directory. The cvs init command initializes the repository with some needed directories and data files.

Before the cvs init command, the srcbank directory is empty. After- ward it contains a directory called CVSROOT (literal name, not the shell variable’s value) which contains a variety of administrative files—most of which you need never worry about.

If your are using a remote repository, that is, one that you connect to over a network (typical when you are sharing a repository amongst team members), then you need one additional step—you need to log in to the CVS repository’s server:


$ cvs login


which will prompt you for a password. Having logged in once, you will not need to log in again, even after reboots of your system, as CVS keeps the password (by default; it can be changed) in a file called .cvspass in your home directory. This makes using CVS with a remote repository (once you’ve logged in as simple as if the repository were local). From here on, the commands will all look the same. If your repository is remote, CVS will use the password from your .cvspass file, without asking you for it.