The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
cvs - create your own repository 25 April 2000
Need more help on this topic? Click here
This article has no comments
Show me similar articles
cvs is an open source version control software.  It is pretty widely used.  It also forms the basis for the FreeBSD source code tree.  This article talks about creating a cvs repository for your own project. You can put anything into cvs so long as it's in a file.  I'm using cvs for storing the source code for FreshPorts.

Don't confuse cvsup with cvscvs is a separate program.  cvsup is used to get data from a cvsup server, which in turn, reads from a cvs repository.

Also, I am by no means a cvs expert.  I'm just writing down what I did so when I go to do it again, I have my notes.  Of course, corrections and additions are always welcome in the comments section.

Resources
Here are some useful cvs resources:

http://www.sourcegear.com/CVS
http://www.loria.fr/~molli/cvs-index.html
http://www.gnu.org/manual/cvs/index.html
<= Good basic stuff about cvs

And more recently (29 September 2000) found:

http://www.cvshome.org/new_users.html - CVS for new users
http://www.cvshome.org/docs/blandy.html - Introduction to CVS
http://www.cvshome.org/docs/manual/index.html - CVS--Concurrent Versions System

And more recently (11 January 2001) found:

http://www.arsdigita.com/asj/cvs - Using CVS for Web Development
http://www.arsdigita.com/asj/version-control/ - Good and simple instructions.  READ THIS!
http://www.loria.fr/~molli/cvs/doc/cvs_toc.html - CVS--Concurrent Versions System
http://cvsbook.red-bean.com/cvsbook.html - ideal for setting up a server

Creating the cvs repository
The first step is to create the cvs repository (also known as a tree).
  1. create an empty directory which will hold the tree.

    mkdir ~/mycvs
  2. Set the CVSROOT environment variable.

    export CVSROOT=~/mycvs

    The above is for a bash shell.  If you are using a csh derived shell, try setenv CVSROOT /mycvs.
  3. Create the repository:

    cvs init

If you now look in ~/mycvs, you'll find the basic files which constitute a repository.

Adding your project to the repository
Now we'll add your project to the repository.
  1. cd /path/to/project
  2. cvs import myproject devel beta

This instructs cvs to import the files located in the current directory.   cvs uses the value of CVSROOT to determine which tree the files will be imported into.  You should note the following points about the above command:

  • The files will be added under the directory ${CVSROOT}/CVSROOT/myproject.
  • myproject is the module name.
  • "devel" is the tag given to the entire branch.
  • "beta" is the release tag give to each of the files.

See man cvs for more detail.

Importing a vendor branch

I import vendor branches for the third party software which I use within my websites. For example, Phorum and phpPgAds. When a new release comes out, I import that source code into my CVS Repository. This makes it easier for me to maintain my local customizations of these popular software packages.

Here I am importing the latest version of Phorum:

$ cvs import -ko -m "Import Phorum 3.4.6" phorum PHORUM_3_4_6 Phorum
U phorum/attach.php
C phorum/common.php
U phorum/down.php
U phorum/download.php
U phorum/edit.php
U phorum/help.php
U phorum/index.php
C phorum/list.php
U phorum/login.php
U phorum/moderator.php
U phorum/phorum.css

...

U phorum/smileys/smilie3.gif
U phorum/smileys/smilie4.gif
U phorum/smileys/smilie5.gif
U phorum/smileys/smilie6.gif
U phorum/smileys/smilie7.gif
U phorum/smileys/smilie8.gif
U phorum/smileys/smilie9.gif

5 conflicts created by this import.
Use the following command to help the merge:

        cvs checkout -j<prev_rel_tag> -jPhorum phorum

To resolve the conflicts, I did this:

$ cvs checkout -jPHORUM_3_4_4 -jPHORUM_3_4_6 phorum
cvs server: Updating phorum
U phorum/attach.php
U phorum/common.php
RCS file: /home/repositories/3rdPartyProducts/phorum/common.php,v
retrieving revision 1.1.1.2
retrieving revision 1.1.1.3
Merging differences between 1.1.1.2 and 1.1.1.3 into common.php
U phorum/down.php
U phorum/download.php
U phorum/edit.php
U phorum/help.php
U phorum/index.php
U phorum/list.php
RCS file: /home/repositories/3rdPartyProducts/phorum/list.php,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.2
Merging differences between 1.1.1.1 and 1.1.1.2 into list.php
rcsmerge: warning: conflicts during merge
...

CVS was unable to resolve conflicts in list.php. In short, my local changes and the vendor branch changes overlap. We both changed the same lines of code. CVS doesn't know which should be used, so it leaves it up to you to fix it. The conflicts will be highlighted within the file. Please refer to the "Tracking Third-Party Sources" section of the red-bean link shown near the top of this page.

Checking out the files
The first step in modifying something from your repository is to check out the files.  So I did this:
mkdir /home/dan/work/myproject
cvs co myproject

Note that "myproject" is the name of the module we created when we did the import.  However, the above will place the files in /home/dan/work/myproject.   If you want the files to be placed into the current directory and you don't want cvs to create a subdirectory, try this instead:

mkdir /home/dan/work/myproject
cvs co -d . myproject
Checking out a single file
If youi want to get a single file from the repository, you do it like this:
cvs co myproject/the.file.i.want

If you want a particular revision of that file:

cvs co -r1.1 myproject/the.file.i.want

That will give you revision 1.1 of that file.

Perhaps the file lives in a subdirectory of the project.  No problem.  Just supply the pathname

cvs co myproject/path/to/the.file.i.want
What's changed?
Now you can make your changes.  To see what's changed between your work files and your repository, use this command:
cvs diff

Or compare the current files against revision 1.3:

cvs diff -r1.3 category-watch.php3
Adding new files to the repository
If a new file is needed, you can add it to the repository by doing this:
$ cvs add mynewscript.pl
cvs add: scheduling file 'mynewscript.pl' for addition

On your next commit, the file will be added to the repository.

Checking things back in
Once you are happy with any changes you have made, you can commit these changes to the repository by doing this:
cvs commit
cvs commit: Up-to-date check failed for `about.html'
Sometimes, when you try to commit stuff back to the database, things don't go as planned.  For example:
$ cvs commit
cvs commit: Examining .
cvs commit: Up-to-date check failed for `about.html'
cvs commit: Examining _private
cvs commit: Examining graphics
cvs commit: Examining images
cvs commit: Examining scripts
cvs commit: Examining work
cvs commit: Examining work/graphics
cvs [commit aborted]: correct above errors first!

It was suggested to me that about.html was older than that which was in the repository and that I should try this instead:

$ cvs update about.html
RCS file: /home/dan/mycvs/freshports/about.html,v
retrieving revision 1.1.1.1
retrieving revision 1.2
Merging differences between 1.1.1.1 and 1.2 into about.html
about.html already contains the differences between 1.1.1.1 and 1.2

That worked for me!

other useful options
This section shows you some interesting options.
  • status
# cvs status category-watch.php3 
===================================================================
File: category-watch.php3       Status: Locally Modified

   Working revision:    1.3     Mon May  1 13:35:50 2000
   Repository revision: 1.3     /home/dan/mycvs/freshports/category
                                                      -watch.php3,v
   Sticky Tag:          (none)
   Sticky Date:         (none)
   Sticky Options:      (none)
  • history (might help you find the revision you want)
cvs history -c category-watch.php3 
Backing out a commit 30 September 2003
You made a mistake. You committed something you didn't want to commit. There is an easy way to undo those changes and commit a new revision. For our example, we'll assume the last commit created revision 1.4. We want to reverse all of those changes. We want revision to go back to what we had in revision 1.3. By the nature of a repository, all revisions are held forever. We will use the features of cvs to automatically undo the changes for ut. The file we need to change is freshports.php.

A very useful cvs feature is the ability to merge changes between revision. The following command merges the changes between the two revisions into the working copy of the file:

cvs up -j 1.4 -j 1.3 freshports.php

The order of the revisions is important. In this case, we first specify the revision containing the mistaken commit first, and then the revision we wish to which we want to revert.

After executing the above command, check that your working copy is identical to revision 1.3:

cvs di -r 1.3 freshports.php

After verifying this is how we want the file to look, we commit:

cvs ci freshports.php

Done. Revision committed. We're back with what we had in revision 1.3.


Need more help on this topic? Click here
This article has no comments
Show me similar articles