old-www/LDP/LG/issue20/rcs.html

431 lines
13 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Introduction to RCS Issue 20</title>
</HEAD>
<BODY BGCOLOR="#EEE1CC" TEXT="#000000" LINK="#0000FF" VLINK="#0020F0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
&quot;Linux Gazette...<I>making Linux just a little more fun!</I>&quot;
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H2>Introduction to RCS</H2>
<H4>By H&aring;kon L&oslash;vdal
<a href="mailto:halovda@krs.hia.no">halovda@krs.hia.no</a></H4>
</center>
<hr>
<P>
Do you find yourself having lots of different unsorted and more or less
old backup files lying around when working on something, but do not dare
to delete any of them because you might need to go back and find out
what changes you have made compared to your current version&nbsp;?
<P>
Would you like to get all those backups out of the way (without reducing
the number of backups), have them sorted and systemated, and perhaps
even with some sort of documentation like exactly when changes where
made, by who (when several persons are involved), and a few lines that
describes the changes which can be the input of an automatically made
change-log&nbsp?
<P>
In that case read on because RCS will do that for you.
<HR>
<P>
Lets have a look at an example (a traditional hello world program)
of what RCS can do:
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;ls -l
total 0
(hlovdal) localhost:/tmp/rcstest&gt;cat &gt; hello.c
/*
* $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $
*
* $Log: rcs.html,v $
* Revision 1.2 2002/10/09 22:24:19 lg
* Remove all lg_toc##.html; change hyperlinks to index.html
*
* Revision 1.1.1.1 2002/08/14 22:27:03 dan
* Preliminary.
*
*/
main(){
printf("hello world");
}
(hlovdal) localhost:/tmp/rcstest&gt;gcc -o hello hello.c
(hlovdal) localhost:/tmp/rcstest&gt;./hello
hello world(hlovdal) localhost:/tmp/rcstest&gt;ls -l
total 5
-rwxrwx--- 1 hlovdal hlovdal 3928 Jun 28 01:01 hello
-rw-rw---- 1 hlovdal hlovdal 60 Jun 28 01:00 hello.c
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
(The two $-tags in the comment are for automatically documentation, more
about those later)
<P>
Our hello world program works now, so we would like to save it in it's
current state before making any changes to it. This is done by running
ci, Check In, on the source file. That is, the source file is put into
the RCS database. When the file is checked in, it is by default also
removed from the current directory.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;mkdir RCS
(hlovdal) localhost:/tmp/rcstest&gt;ci hello.c
RCS/hello.c,v &lt;-- hello.c
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
&gt;&gt; A plain simple hello world program
&gt;&gt; .
initial revision: 1.1
done
(hlovdal) localhost:/tmp/rcstest&gt;ls -l
total 5
drwxrwx--- 2 hlovdal hlovdal 1024 Jun 28 01:02 RCS
-rwxrwx--- 1 hlovdal hlovdal 3928 Jun 28 01:01 hello
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
By looking into the RCS directory we can now see that there is a
file with the same name as our program with an extra extension ",v".
(By omitting the RCS directory the file would be in the current directory)
This file now holds the source plus some additional information, and
will later on contain the source for all versions. The rcs file is not
particularly interesting to look at directly:
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;cat RCS/hello.c,v
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 97.06.28.01.03.43; author hlovdal; state Exp;
branches;
next ;
desc
@A plain simple hello world program
@
1.1
log
@Initial revision
@
text
@/*
* $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $
*
* $Log: rcs.html,v $
* Revision 1.2 2002/10/09 22:24:19 lg
* Remove all lg_toc##.html; change hyperlinks to index.html
*
* Revision 1.1.1.1 2002/08/14 22:27:03 dan
* Preliminary.
*
*/
main(){
printf("hello world");
}
@
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
This our first version of the hello world program sort of worked, but
it lacks an ending newline and the source isn't pretty. Lets fix that.
The source was moved when it was checked in, so we must use co, Check Out,
to copy the source out of the RCS database.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;co hello.c
RCS/hello.c,v --&gt; hello.c
revision 1.1
done
(hlovdal) localhost:/tmp/rcstest&gt;ls -l
total 6
drwxrwx--- 2 hlovdal hlovdal 1024 Jun 28 01:02 RCS
-rwxrwx--- 1 hlovdal hlovdal 3928 Jun 28 01:01 hello
-r--r----- 1 hlovdal hlovdal 189 Jun 28 01:04 hello.c
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
Note that co by default fetches the source read-only. This is
usually not what we want, so in order to get the source writable we
use the "-l" option to mark the file locked for others.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;co -l hello.c
RCS/hello.c,v --&gt; hello.c
revision 1.1 (locked)
done
(hlovdal) localhost:/tmp/rcstest&gt;ls -l
total 6
drwxrwx--- 2 hlovdal hlovdal 1024 Jun 28 01:02 RCS
-rwxrwx--- 1 hlovdal hlovdal 3928 Jun 28 01:01 hello
-rw-r----- 1 hlovdal hlovdal 197 Jun 28 01:05 hello.c
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
By looking at the hello.c file we see that now some values have been
inserted into $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and $Log: rcs.html,v $
inserted into $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and Revision 1.2 2002/10/09 22:24:19 lg
inserted into $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and Remove all lg_toc##.html; change hyperlinks to index.html
inserted into $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and
inserted into $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and Revision 1.1.1.1 2002/08/14 22:27:03 dan
inserted into $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and Preliminary.
inserted into $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;cat hello.c
/*
* $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $
*
* $Log: rcs.html,v $
* Revision 1.2 2002/10/09 22:24:19 lg
* Remove all lg_toc##.html; change hyperlinks to index.html
*
* Revision 1.1.1.1 2002/08/14 22:27:03 dan
* Preliminary.
*
* Revision 1.1 1997/06/28 01:03:43 hlovdal
* Initial revision
*
*/
main(){
printf("hello world");
}
(hlovdal) localhost:/tmp/rcstest&gt;vi hello.c
...
</PRE>
<P>
We makes a few changes. Exactly what was changed can be examined with
the program rcsdiff.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;rcsdiff hello.c
===================================================================
RCS file: RCS/hello.c,v
retrieving revision 1.1
diff -r1.1 hello.c
9,10c9,14
&lt; main(){
&lt; printf("hello world");
---
&gt;
&gt; #include &lt;stdio.h&gt;
&gt;
&gt; int main(int argc, char *argv[]){
&gt; printf("hello world\n");
&gt; return 0;
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
The rcsdiff program is just a front end for ordinary diff, so it accepts
all the options to diff, for example "-u".
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;rcsdiff -u hello.c
===================================================================
RCS file: RCS/hello.c,v
retrieving revision 1.1
diff -u -r1.1 hello.c
--- hello.c 1997/06/28 01:03:43 1.1
+++ hello.c 1997/06/28 01:05:21
@@ -6,6 +6,10 @@
* Initial revision
*
*/
-main(){
-printf("hello world");
+
+#include &lt;stdio.h&gt;
+
+int main(int argc, char *argv[]){
+ printf("hello world\n");
+ return 0;
}
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
This version looks good, so we want to save it with Check In. By giving
option "-l", ci runs a implicit "co -l" so that the source file remains
checked out. When ci is run we are asked to enter a log description of
our changes. This log description is inserted into $Log: rcs.html,v $
our changes. This log description is inserted into Revision 1.2 2002/10/09 22:24:19 lg
our changes. This log description is inserted into Remove all lg_toc##.html; change hyperlinks to index.html
our changes. This log description is inserted into
our changes. This log description is inserted into Revision 1.1.1.1 2002/08/14 22:27:03 dan
our changes. This log description is inserted into Preliminary.
our changes. This log description is inserted into.
<P>
<PRE>
(hlovdal) localhost:/tmp/rcstest&gt;ci -l hello.c
RCS/hello.c,v &lt;-- hello.c
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
&gt;&gt; Fixed main prototype, inserted a missing newline and a missing #include
&gt;&gt; .
done
(hlovdal) localhost:/tmp/rcstest&gt;cat hello.c
/*
* $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $
*
* $Log: rcs.html,v $
* Revision 1.2 2002/10/09 22:24:19 lg
* Remove all lg_toc##.html; change hyperlinks to index.html
*
* Revision 1.1.1.1 2002/08/14 22:27:03 dan
* Preliminary.
*
* Revision 1.2 1997/06/28 01:07:23 hlovdal
* Fixed main prototype, inserted a missing newline and a missing #include
*
* Revision 1.1 1997/06/28 01:03:43 hlovdal
* Initial revision
*
*/
#include &lt;stdio.h&gt;
int main(int argc, char *argv[]){
printf("hello world\n");
return 0;
}
(hlovdal) localhost:/tmp/rcstest&gt;gcc -o hello hello.c
(hlovdal) localhost:/tmp/rcstest&gt;./hello
hello world
(hlovdal) localhost:/tmp/rcstest&gt;
</PRE>
<P>
<HR>
<H2>
In short RCS is this simple to use:
</H2>
<OL>
<LI>"mkdir RCS"
<LI>Insert $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and $Log: rcs.html,v $
<LI>Insert $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and Revision 1.2 2002/10/09 22:24:19 lg
<LI>Insert $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and Remove all lg_toc##.html; change hyperlinks to index.html
<LI>Insert $Id: rcs.html,v 1.1.1.1 2002/08/14 22:27:03 dan Exp $ and
<LI>Insert $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and Revision 1.1.1.1 2002/08/14 22:27:03 dan
<LI>Insert $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and Preliminary.
<LI>Insert $Id: rcs.html,v 1.2 2002/10/09 22:24:19 lg Exp $ and into one comment. Optional, but nice
to have. (NB! Note that $Log: rcs.html,v $
to have. (NB! Note that Revision 1.2 2002/10/09 22:24:19 lg
to have. (NB! Note that Remove all lg_toc##.html; change hyperlinks to index.html
to have. (NB! Note that
to have. (NB! Note that Revision 1.1.1.1 2002/08/14 22:27:03 dan
to have. (NB! Note that Preliminary.
to have. (NB! Note that does *not* include previous
versions. If $Log: rcs.html,v $
versions. If Revision 1.2 2002/10/09 22:24:19 lg
versions. If Remove all lg_toc##.html; change hyperlinks to index.html
versions. If
versions. If Revision 1.1.1.1 2002/08/14 22:27:03 dan
versions. If Preliminary.
versions. If is inserted after some time only that
and later versions will end up in the log. It is therefore
smart to have $Log: rcs.html,v $
smart to have Revision 1.2 2002/10/09 22:24:19 lg
smart to have Remove all lg_toc##.html; change hyperlinks to index.html
smart to have
smart to have Revision 1.1.1.1 2002/08/14 22:27:03 dan
smart to have Preliminary.
smart to have in the file from the start)
<LI>Edit the file
<LI>Optionally run rcsdiff when you want to see what changes
you have made since last check in.
<LI>Run "ci -l" each time you want to save what you have done so far.
<LI>Repeat 3 to 5.
</OL>
<P>
For more info on RCS look at the rcsintro(1) man page.
<P>
Here in this example RCS is used on C source, but RCS can be used on many
other things. Config files in /etc are for example excellent candidates
of being put under RCS control.
<P>
RCS is one method of version control. Two others are SCCS and CVS.
CVS (Concurrent Versions System) is a further development of RCS intended
to be used on larger software projects. For example most (?) BSD clones
are distributed and developed using CVS.
<P>
SCCS (Source Code Control System) is an old proprietary system which few
(if any) uses. I think SCCS and RCS have a somewhat a similar relation
as traditional compress vs gzip.
<P>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1997, H&aring;kon L&oslash;vdal<BR>
Published in Issue 20 of the Linux Gazette, August 1997</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./sameer.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./lyx.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->