Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

For example, if you're running a program that fails at the same spot every time, you can use script to copy your keystrokes and what the screen says in response. This is particularly useful when upgrading your system or building software from source code; the last 30 or so lines of the typescript file make a nice addition to a request for help.

Revision Control

Generally speaking, revision control is the process of tracking changes. In the UNIX world, this means changes to source code or configuration files. Revision control allows a developer to see how a piece of code looked on a specific date, or an administrator to see how the system was configured before things stopped working. Even a lowly writer can use revision control to see how a manuscript has changed over time. If you're not using revision control, you're making your work more difficult than it needs to be.[2]

While you'll encounter many revision−control systems, from UNIX's SCCS (Source Code Control System) to Microsoft's Visual SourceSafe, we'll discuss RCS (Revision Control System), included with almost all UNIX systems. Once you learn how to work with RCS, you should find it simple to work with most any other revision−control system.

When using revision control, you're essentially keeping a record of what happened to a file. First, you mark the file as checked out, which tells the system that you are going to change the file. You then edit the file as you like, record changes in the system, and release the file for others to edit. RCS uses three basic commands to accomplish this: ci (check−in), co (check−out), and rcs.

Think of revision control as a library—an old−fashioned brick−and−mortar one. To edit a file, you must first tell RCS to keep track of it, or give it to the library. To use it you check it out, like removing a book from a library. Once checked out, nobody else can save or edit that file, though any legitimate user can view, use, copy, compile, or access that file. Once you finish with the file, you check it back in, thus releasing it for others to edit. The whole process is called RCS.

Each file in RCS has a version number. Each time you return an edited file to the system, the Revision Control System compares the returned file with what you checked out. If there is any change at all, the version number is increased by one, which is the system's way of tracking changes to the file. You can use the version number to identify specific versions of the file.

Begin the revision−control process by checking in a file with ci(1), which is much like giving a book to the library. For example, a good file to protect with RCS is /etc/rc.conf. To start the RCS process, enter ci <path/filename> as shown in the following listing:

...............................................................................................

v # ci /etc/rc.conf rc.conf,v <−− rc.conf

w enter description, terminated with single '.' or end of file: NOTE: This is NOT the log message!

x >>System configuration file y >> .

initial revision: 1.1 done

#

...............................................................................................

When you first check in a file with ci (v), ci creates or edits a revision−control file. You see this in the second line of the preceding output, where it creates rc.conf,v. It then asks you for a description (w); enter a descriptive bit of text here (x) for any RCS user to later view the file's description. (While this

61

description isn't very important for standard system files, it can be very helpful for source code or configuration files for custom or complex programs.) Once you've finished the description, enter a single period on a line by itself (y) to exit ci.

If you run ls immediately after checking something in, you'll notice that the file appears to have vanished. Instead you'll see a file with the same name, with a trailing ",v". This is an RCS file, where the file and its changes are stored. While it's fine for some files to disappear in this fashion, source code or Web pages can't just vanish. To solve that problem, when checking in a file you can leave a copy in the working directory with ci −u.

If a file is checked in and has vanished, and you want to put a clean copy in the working directory without editing it, use the co command. In the following example, you can see that the file test has been pulled out of the file test,v, and that it's revision 1.1.

...............................................................................................

# co test

test,v −−> test revision 1.1 done

#

...............................................................................................

Looking closely at the directory where the file test lives, you'll see this:

...............................................................................................

# ls −l total 62

−r−−r−−r−− 1 mwlucas mwlucas 12663 Oct 4 18:06 test −r−−r−−r−− 1 mwlucas mwlucas 12867 Oct 4 17:56 test,v

#

...............................................................................................

I own this file, test, but the permissions have been set to read−only (−r−−r−−r−−, as discussed in Chapter 7). I no longer have permission to edit my own files! This is because the file isn't checked out to me. I've checked it in, or handed it over to the Revision Control System librarian. I can view the file, but if I want to edit it, I have to ask the Revision Control Librarian for it—I need to check it out, and then lock it for my personal use. I use the −l flag with co.

...............................................................................................

# co −l test test,v −−> test

revision 1.1 (locked) done

...............................................................................................

Notice the third line of this listing (the second line of output), which specifies locked. This file is checked out and locked by me, and I am the only one who can save it until I unlock it.

Running another ls at this point will show that the permissions on the file test are now set back to read and write, allowing me to save.[3] (We'll discuss permissions in Chapter 7.) Anyone else who tries to check out this file will get a warning that the file is in use and will be told the username of the person who has locked the file.

62

When finished, I check in the file and, since I want other people to be able to edit the file, I use ci −u to release my lock.

...............................................................................................

# ci −u test test,v <−− test

new revision: 1.2; previous revision: 1.1

v enter log message, terminated with single '.' or end of file:

>>enable sendmail again

>>.

done

#

...............................................................................................

When you check something in, you are asked for a log message (v). Enter a brief description of your changes here. (These log messages are comparable to the CVS log messages seen on the various BSDs’ commit mailing lists.)

These log messages allow others to know what changes you've made to a file without checking through all the changes—or, alternatively, to see what you were trying to do when your change broke something and someone has to start debugging. Your own RCS logs can also be useful for you, months later, when you stare at something and wonder just what was going on inside your head at the time.

Note If you have lots of files in RCS, the ",v" files can quickly clutter a directory. You can hide them by creating a directory called RCS. The ci program will then put the ",v" files in that directory, keeping the working directory cleaner.

Now that you understand the basics of checking files in and out, let's examine some of the more interesting functions of RCS. These include getting old versions of files, breaking locks, finding differences between file versions, and putting RCS identifiers in files.

Getting Older Versions

Every file in RCS has a revision number, and each time you check in a file, the revision number increases. The system remembers what the file looked like during earlier revisions, however, so you can use the revision number to check out any previous version of a file.

For example, if you're trying to track a bug that's just appeared, you can check out earlier versions of your code to see if they also exhibit the bug by using co's −r flag. To retrieve version 1.1 of /etc/rc.conf, enter the following:

...............................................................................................

# co −r1.1 rc.conf

RCS/rc.conf,v −−> rc.conf revision 1.1

done

#

...............................................................................................

63

Breaking Locks

Always check files in once you've finished with them. If you don't, and another user needs to edit your locked file, they'll have to break your lock, and any changes you've made since locking it will be lost.

To break a lock on a file, use rcs −u. RCS will ask you to enter a message about why you're breaking the lock, and this message will be mailed to the lock holder.

Note Be careful when breaking locks: If someone is really editing a file when you force the lock, they'll be justifiably upset. If they've gone home for the day, that's another thing. Do your best to find the person before you break his or her lock!

Viewing Log Messages

The rlog command shows you the log messages for the file.

...............................................................................................

# rlog /etc/rc.conf

RCS file: /etc/RCS/rc.conf,v

 

 

 

Working file: /etc/rc.conf

 

 

 

head: 1.4

 

 

 

 

branch:

 

 

 

 

locks: strict

 

 

 

 

access list:

 

 

 

 

symbolic names:

 

 

 

 

keyword substitution: kv

 

 

 

 

total revisions: 4;

selected revisions: 4

 

 

description:

 

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

 

revision 1.4

 

 

 

 

vdate: 2000/09/08 17:45:29;

wauthor: mwlucas;

xstate: Exp; ylines: +2 −0

minor updates

 

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

 

revision 1.3

 

 

 

 

date: 2000/09/07 19:05:30;

author: mwlucas;

state: Exp;

lines: +1 −1

z *** empty log message ***

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

 

revision 1.2

 

 

 

 

date: 2000/09/05 16:09:47;

author: mwlucas;

state: Exp;

lines: +1 −1

enable sendmail

 

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

 

revision 1.1

 

 

 

 

date: 2000/09/02 14:53:43;

author: mwlucas;

state: Exp;

 

Initial revision

 

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

 

========================================================================

#

...............................................................................................

All sorts of useful information appear here, including the date each check−in was made (v), the author of the change (w), the entry's state (x), which we won't worry about here (see ci(1)), and the number of lines changed (y).

64