File Version Numbering
Chris Hare
Frequently I've wanted to have multiple copies of a
file as it went
through various stages of rewriting and reworking. Havng
used a DEC
VAX at various points in my career, I liked the version
numbering
which VMS provides.
To address this I wrote a program called vedit (Listing 1).
vedit is a shell program which implements version numbering
using
a similar scheme to VMS. For each file, vedit checks
the name
to see if there is a file in the current directory which
has a version
number. Version numbers are added to filenames by including
a semicolon
and a number.
For example, the file "demo" does not use
version numbering,
while "demo;2" does. The number 2 indicates
that this is the
second version of the file "demo". The Bourne
Shell script
in Listing 1 is simple enough, and is easy to use and
understand.
However, there are some issues which should be mentioned
here. The
seimcolon is a special character to the Bourne and Korn
shells. It
is used as a command separator to allow the user to
enter mupltiple
commands on the same line. For example, you can write
$ who
chare w1 Mar 23 21:40
$ date
Sat Mar 26 14:39:35 EST 1994
$ pwd
/u/chare/Filecabinet/publish/sysadmin/vi
or you can use the semicolon and write it as
$ who; date; pwd
chare w1 Mar 23 21:40
Sat Mar 26 14:40:52 EST 1994
/u/chare/Filecabinet/publish/sysadmin/vi
Consequently, the use of the semicolon in the file name
requires some special handling. To access a file under
version control
without using the vedit command, you must use the backslash
to "escape" the meaning of the semicolon to
the shell, as,
for example,
$ cat demo\;2
To discuss the operation of the shell script in Listing 1,
I have numbered it using the UNIX pr command. Line
30 lists
the files that contain a semicolon, and replaces all
of the text in
the file name with blanks. The end result is a list
of numbers in
reverse sorted order. The result of this list is the
last or highest
number in the list. If the file is new, then the first
version number
used is 1.
Lines 36 to 58 determine what version number is to be
used, and set
some variables which will be used later in the script.
Lines 63 to
75 copy the original file to the new filenme for editing.
Should the
copy fail, the user is informed with the error message.
The most likely
causes of such a failure would be the permissions on
the directory
involved, or an inability to read the source file.
The file is loaded for editing in line 79; upon exit,
the script verifies
that editing did in fact occur. The diff command in
line 85
compares the two files. If no changes were made, then
execution jumps
to line 117, where the user is told that no changes
were made and
the newly created file is removed.
If changes were made, then the lines and bytes in the
file are counted
by the wc command in line 104, and the information on
the
edit is recorded in an edit history file, the name of
which consists
of the filename plus a .INDEX entension. The information
in
the index file includes the file name and version, the
name of the
person who edited it, the date and time, and the lines
and byte count
of the new file.
Line 116 connects the newly created file with the name
supplied by
the user. This way, the user doesn't need to remember
the current
version of the file, unless he or she chooses to return
to an earlier
version.
Conclusions
Source Code Control or Revision Control systems can
be used to accomplish
a similar goal, but are not for the average user. System
administrators
can use vedit to edit and manipulate system configuration
files and keep a log of those edits.
About the Author
Chris Hare is Ottawa Technical Services Manager for
Choreo Systems, Inc.
He has worked in the UNIX environment since 1986 and
in 1988 became one of
the first SCO authorized instructors in Canada. He teaches
UNIX introductory,
system administration, and programming classes. His
current focus is on
networking, Perl, and X. Chris can be reached at chare@choreo.ca,
or
chare@unilabs.org, which is his home.
|