CVS

The Concurrent Versions System (CVS) is a widely used and mature revision control system, with command-line tools for all major modern operating systems (including Windows), and GUI tools for some of them (notably Windows).

Pros

  • It is everywhere and is very mature.

  • Many Unix system administrators and virtually every open source or free software developer is familiar with it.

  • It’s easy to use for simple projects.

  • It’s easy to access remote repositories.

  • It’s based on RCS, which allows for some hacking of the central repository.

Cons

  • Commits are not atomic, so the repository could be left in an inconsistent state if a commit fails half-way through.

  • Commits are by file only; you must also tag if you need to reference a group of files.

  • Directory structure support is poor.

  • Does not allow easy renaming of files and directories while retaining history.

  • Poor support for binary files, and little support for other objects such as symbolic links.

  • Based on RCS, which allows for some hacking of the central repository.

Tip

CVS tracks revisions by file, which means that each file has its own internal CVS revision number. As each file is changed, that number changes, so a single project can’t be tracked by a single revision number, since each file is different. Use tags for that kind of tracking.

Example

This example is not suitable for enterprise or multiuser access (see the “See Also” section for links to more information). This is just to show how easy the basics are. This example has the EDITOR environment variable set to nano (export EDITOR='nano --smooth --const --nowrap --suspend'), which some people find more user-friendly than the default vi.

The cvs command (with no options), the cvs help command (where help is not a valid argument, but is easy to remember and still triggers a useful response), and the cvs --help cvs_command command are very useful.

Create a new repository for personal use in a home directory:

/home/jp$ mkdir -m 0775 cvsroot
/home/jp$ chmod g+srwx cvsroot
/home/jp$ cvs -d /home/jp/cvsroot init

Create a new project and import it:

/home/jp$ cd /tmp

/tmp$ mkdir -m 0700 scripts

/tmp$ cd scripts/

/tmp/scripts$ cat << EOF > hello
> #!/bin/sh
> echo 'Hello World!'
> EOF

/tmp/scripts$ cvs -d /home/jp/cvsroot import scripts shell_scripts NA

  GNU nano 1.2.4                   File: /tmp/cvsnJgYmG

Initial import of shell scripts
CVS: ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically*
CVS:
CVS: ---------------------------------------------------------------------

                                         [ Wrote 5 lines ]
N scripts/hello

No conflicts created by this import

Check out the project and update it:

/tmp/scripts$ cd
/home/jp$ cvs -d /home/jp/cvsroot/ checkout scripts
cvs checkout: Updating scripts
U scripts/hello

/home/jp$ cd scripts

/home/jp/scripts$ ls -l
total 8.0K
drwxr-xr-x  2 jp jp 4.0K Jul 20 00:27 CVS/
-rw-r--r--1 jp jp     30 Jul 20 00:25 hello

/home/jp/scripts$ echo "Hi Mom..." >> hello

Check the status of your sandbox. The second command is a hack to give you a short summary status since the real status command is a little verbose:

/home/jp/scripts$ cvs status
cvs status: Examining .
===================================================================
File: hello                Status: Locally Modified

   Working revision:       1.1.1.1 Thu Jul 20 04:25:44 2006
   Repository revision:    1.1.1.1 /home/jp/cvsroot/scripts/hello,v
   Sticky Tag:             (none)
   Sticky Date:            (none)
   Sticky Options:         (none)

/home/jp/scripts$ cvs -qn update
M hello

Add a new script to revision control:

/home/jp/scripts$ cat << EOF > mcd
> #!/bin/sh
> mkdir -p "$1"
> cd "$1"
> EOF

/home/jp/scripts$ cvs add mcd
cvs add: scheduling file `mcd' for addition
cvs add: use `cvs commit' to add this file permanently

Commit changes:

/home/jp/scripts$ cvs commit
cvs commit: Examining .

  GNU nano 1.2.4                    File: /tmp/cvsY1xcKa

* Tweaked hello
* Added mcd
CVS: ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
CVS:
CVS: Committing in .
CVS:
CVS: Modified Files:
CVS:    hello
CVS: Added Files:
CVS:    mcd
CVS: ----------------------------------------------------------------------

                                       [ Wrote 12 lines ]

/home/jp/cvsroot/scripts/hello,v <-- hello
new revision: 1.2; previous revision: 1.1
/home/jp/cvsroot/scripts/mcd,v <-- mcd
initial revision: 1.1

Update the sandbox, make another change, then check the difference:

/home/jp/scripts$ cvs update
cvs update: Updating .

/home/jp/scripts$ vi hello

/home/jp/scripts$ cvs diff hello
Index: hello
===================================================================
RCS file: /home/jp/cvsroot/scripts/hello,v
retrieving revision 1.2
diff -r1.2 hello
3c3
< Hi Mom...
---
> echo 'Hi Mom...'

Commit the change, avoiding the editor by putting the log entry on the command line:

/home/jp/scripts$ cvs -m '* Fixed syntax error' commit
/home/jp/cvsroot/scripts/hello,v  <--  hello
new revision: 1.3; previous revision: 1.2

See the history of the file:

/home/jp/scripts$ cvs log hello
RCS file: /home/jp/cvsroot/scripts/hello,v
Working file: hello
head: 1.3
branch:
locks: strict
access list:
symbolic names:
        NA: 1.1.1.1
        shell_scripts: 1.1.1
keyword substitution: kv
total revisions: 4;     selected revisions: 4
description:
----------------------------
revision 1.3
date: 2006-07-20 04:46:25 +0000;  author: jp;  state: Exp;  lines: +1 -1
* Fixed syntax error
----------------------------
revision 1.2
date: 2006-07-20 04:37:37 +0000;  author: jp;  state: Exp;  lines: +1 -0
* Tweaked hello
* Added mcd
----------------------------
revision 1.1
date: 2006-07-20 04:25:44 +0000;  author: jp;  state: Exp;
branches: 1.1.1;
Initial revision
----------------------------
revision 1.1.1.1
date: 2006-07-20 04:25:44 +0000;  author: jp;  state: Exp;  lines: +0 -0
Initial import of shell scripts
=============================================================================

Add some revision metadata that is automatically kept up-to-date by the revision control system itself. Commit it and examine the change:

/home/jp/scripts$ vi hello

/home/jp/scripts$ cat hello
#!/bin/sh
# $Id$
echo 'Hello World!'
echo 'Hi Mom...'

/home/jp/scripts$ cvs ci -m'* Added ID keyword' hello
/home/jp/cvsroot/scripts/hello,v <--hello
new revision: 1.4; previous revision: 1.3

/home/jp/scripts$ cat hello
#!/bin/sh
# $Id: hello,v 1.4 2006/07/21 08:57:53 jp Exp $
echo 'Hello World!'
echo 'Hi Mom...'

Compare the current revision to r1.2, revert to that older (broken) revision, realize we goofed and get the most recent revision back:

/home/jp/cvs.scripts$ cvs diff -r1.2 hello
Index: hello
===================================================================
RCS file: /home/jp/cvsroot/scripts/hello,v
retrieving revision 1.2
retrieving revision 1.4
diff -r1.2 -r1.4
1a2
> # $Id$
3c4
< Hi Mom...
---
> echo 'Hi Mom...'

/home/jp/scripts$ cvs update -r1.2 hello
U hello

/home/jp/scripts$ cat hello
#!/bin/sh
echo 'Hello World!'
Hi Mom...

/home/jp/cvs.scripts$ cvs update -rHEAD hello
U hello

/home/jp/cvs.scripts$ cat hello
#!/bin/sh
# $Id: hello,v 1.4 2006/07/21 08:57:53 jp Exp $
echo 'Hello World!'
echo 'Hi Mom...'

See Also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.170.134