Info Node: (cvsbook.info)The Slow Method Of Reverting
(cvsbook.info)The Slow Method Of Reverting
The Slow Method Of Reverting
----------------------------
This method involves passing the -p flag to update, in conjunction with
-r. The -p option sends the contents of the named revision to standard
output. By itself, this isn't terribly helpful; the contents of the
file fly by on the display, leaving the working copy unchanged.
However, by redirecting the standard output into the file, the file will
now hold the contents of the older revision. It's just as though the
file had been hand-edited into that state.
First, though, qsmith needs to get up to date with respect to the
repository:
paste$ cvs update
cvs update: Updating .
U hello.c
cvs update: Updating a-subdir
cvs update: Updating a-subdir/subsubdir
cvs update: Updating b-subdir
paste$ cat hello.c
#include <stdio.h>
void
main ()
{
printf ("Hello, world!\n");
printf ("BETWEEN HELLO AND GOODBYE.\n");
printf ("Goodbye, world!\n");
}
paste$
Next, he runs update -p to make sure that the revision 1.3 is the one he
wants:
paste$ cvs update -p -r 1.3 hello.c
===================================================================
Checking out hello.c
RCS: /usr/local/cvs/myproj/hello.c,v
VERS: 1.3
***************
#include <stdio.h>
void
main ()
{
printf ("Hello, world!\n");
printf ("between hello and goodbye\n");
printf ("Goodbye, world!\n");
}
Oops, there are a few lines of cruft at the beginning. They aren't
actually being sent to standard output, but rather to standard error, so
they're harmless. Nevertheless, they make reading the output more
difficult and can be suppressed with -Q:
paste$ cvs -Q update -p -r 1.3 hello.c
#include <stdio.h>
void
main ()
{
printf ("Hello, world!\n");
printf ("between hello and goodbye\n");
printf ("Goodbye, world!\n");
}
paste$
There - that's exactly what qsmith was hoping to retrieve. The next
step is to put that content into the working copy's file, using a Unix
redirect (that's what the ">" does):
paste$ cvs -Q update -p -r 1.3 hello.c > hello.c
paste$ cvs update
cvs update: Updating .
M hello.c
cvs update: Updating a-subdir
cvs update: Updating a-subdir/subsubdir
cvs update: Updating b-subdir
paste$
Now when update is run, the file is listed as modified, which makes
sense because its contents have changed. Specifically, it has the same
content as the old revision 1.3 (not that CVS is aware of its being
identical to a previous revision - it just knows the file has been
modified). If qsmith wants to make extra sure, he can do a diff to
check:
paste$ cvs -Q diff -c
Index: hello.c
===================================================================
RCS file: /usr/local/cvs/myproj/hello.c,v
retrieving revision 1.4
diff -c -r1.4 hello.c
*** hello.c 1999/04/20 04:14:37 1.4
--- hello.c 1999/04/20 06:02:25
***************
*** 4,9 ****
main ()
{
printf ("Hello, world!\n");
! printf ("BETWEEN HELLO AND GOODBYE.\n");
printf ("Goodbye, world!\n");
}
--- 4,9 --
main ()
{
printf ("Hello, world!\n");
! printf ("between hello and goodbye\n");
printf ("Goodbye, world!\n");
}
paste$
Yes, that's exactly what he wanted: a pure reversion - in fact, it is
the reverse of the diff he previously obtained. Satisfied, he commits:
paste$ cvs ci -m "reverted to 1.3 code"
cvs commit: Examining .
cvs commit: Examining a-subdir
cvs commit: Examining a-subdir/subsubdir
cvs commit: Examining b-subdir
Checking in hello.c;
/usr/local/cvs/myproj/hello.c,v <- hello.c
new revision: 1.5; previous revision: 1.4
done
paste$