This lesson introduces one of ClearCase's most powerful features, rule-based selection of source versions. Each view has a configuration specification (config spec), an ordered set of rules for selecting versions of elements. So far, we have not paid close attention to version selection, because the default config spec was appropriate for the task at hand—new development. The catcs (“cat config spec”) command shows the current config spec:
% cleartool catcs element * CHECKEDOUT (Rule 1) element * /main/LATEST (Rule 2) |
This set of rules says:
“For each element, if a checkout has been performed in this view, use the checked-out version; otherwise, use the most recent version on the main branch.”
Each view is assigned the default config spec when it is created with the mkview command.
The rules in config spec are applied dynamically—every time you access an element, a view_server process associated with your view decides which version of that element to use. It does so by consulting the rules in order—the first rule to provide a “match” selects a version.
At the end of the preceding lesson, you were in the src directory, in a shell set to view USER_HOST_tut. Verify that you are still in the same situation.
% cleartool pwv -short USER_HOST_tut % pwd VOBTAG/src |
If you've gotten lost, you may need to use a full pathname to find the source directory.
cd VOBTAG/src |
If this command fails, it is probably because you exited the shell that was set to your view. Enter the following commands to reestablish your view context and your working directory within the VOB.
cleartool setview USER_HOST_tut cd VOBTAG/src |
Start by assessing your view's current configuration of source versions.
% cleartool ls -vob_only Makefile@@/main/2 Rule:/main/LATEST hello.c@@/main/3 Rule:/main/LATEST hello.h@@/main/1 Rule:/main/LATEST util.c@@/main/2 Rule:/main/LATEST |
The –vob_only option restricts the listing to elements—it omits the derived objects you've created with clearmake. Previous invocations of the ls command (for example, Step 28 and Step 32) used the –short option to suppress the “Rule:” annotations. Since config specs had yet to be introduced, the annotations would have been distracting and not very meaningful. Now, however, we want to see how views select versions.
This command shows that for each of the four file elements, your view selects the most recent version on the main branch.
Now, let's switch to another view, USER_HOST_old, to see how it selects versions of elements. The REL1REL2 script created this view for you and used it to build the first two releases of the hello program. REL1REL2 ended by reconfiguring the view, using a non-default config spec.
% exit % cleartool setview USER_HOST_old % cleartool catcs element * REL2 |
The catcs command reveals that this view is configured with a single rule, which says:
“For each element, use the version assigned the REL2 version label.”
Evidently, this is a view that “turns back the clock” to the Release 2 era. Let's explore.
![]() | Note: Exiting your current shell is not required before you set a new view. We do so in this tutorial for simplicity—you will never be more than one shell level away from your starting point. |
Go to the source directory, then enter the same command as in Step 37 to verify that different versions of the elements are selected.
% cd VOBTAG/src % cleartool ls -vob_only Makefile@@/main/2 Rule: REL2 hello.c@@/main/3 Rule: REL2 hello.h@@/main/1 Rule: REL2 util.c@@/main/1 Rule: REL2 |
These are the same versions that were most recent when you began this tutorial (Step 14).
Just to make sure that this is an old configuration, check that source file util.c, as seen through this view, has none of the string-manipulation changes you entered in Step 22.
% tail -7 util.c
char *
env_time() {
time_t clock;
time(&clock);
return ctime(&clock);
}
|
And check that the executable, ../bin/hello, is also the old version, which does not massage the reporting of your home directory.
% ../bin/hello Hello, USER! Your home directory is /net/HOST/home/USER. It is now DATESTRING . |
Now, let's turn back the clock again, to Release 1. This time, instead of setting a view that already has a different config spec, we'll change the configuration of an existing view, USER_HOST_tut. The setcs (“set config spec”) command performs the reconfiguration, using a config spec stored in a text file.
% exit % cleartool setview USER_HOST_tut % cleartool setcs /usr/atria/doc/tutorial/cs.2 % cleartool catcs element * REL1 |
Once again, there is a single rule. It says:
“For each element, use the version assigned the REL1 version label.”
Once again, go to the source directory and enter the ls command to verify the new view configuration.
% cd VOBTAG/src % cleartool ls -vob_only Makefile@@/main/1 Rule: REL1 hello.c@@/main/2 Rule: REL1 |
What happened to hello.h and util.c? You have turned back the clock to a time before these elements were created in the src directory. In a view configured for Release 1, it is altogether appropriate that these latter-day elements do not appear. ClearCase implements this feature by allowing directories themselves to be version-controlled. Each version of a directory element catalogs (contains a list of) a certain set of names:
Version 1 of directory element src (labeled REL1) catalogs two element names: hello.c and Makefile.
Version 2 of directory element src (labeled REL2) catalogs four element names: hello.c, hello.h, util.c, and Makefile.
Your view sees elements hello.c and Makefile only, because it selects the REL1 version of the directory element src, just as it selects the REL1 versions of the file elements. You can verify this by using the –d (“directory”) option to the ls command.
% cleartool ls -d . |
.@@/main/1 Rule: REL1 |
For even more confirmation, examine the version tree of directory element src, and list the events in this element's history.
% cleartool lsvtree . .@@/main .@@/main/1 (REL1) .@@/main/2 (REL2) % cleartool lshistory -d . DATESTRING USER import directory element ".@@" 20-May.1416 cory create directory version ".@@/main/2" @(REL2) "Release 2: add hello.h, util.c" 07-May.09:13 akp create directory version ".@@/main/1" (REL1) "Release 1: hello.c, Makefile" 03-May.09:56 akp create directory version ".@@/main/0" 03-May.09:56 akp create branch ".@@/main" 03-May.09:56 akp create directory element ".@@" "create source directory and binaries directory for "hello world" program" Verify that the view selects 'Release 1' file versions |
To complete your exploration of the Release 1 era, verify that the view selects the correct (very old) version of source file hello.c, no version at all of file hello.h, and the correct version of executable hello.
% cat hello.c
int main() {
printf("Hello, world!\n");
return 0;
}
% cat hello.h
cat: cannot open hello.h: No such file or directory
% ../bin/hello
Hello, world!
|
Notice that we had you examine, but not change, files with your current one-rule config spec (element * REL1). It does not make sense to try and add a new version (or element) with such a config spec. The new version would be invisible to your view until the REL1 label was applied, and you must be able to see it to label it!
After you fix a bug in Lesson 5, you'll do additional new development in Lesson 6. In anticipation of this future need for a “new development” view, reset your current view, USER_HOST_tut, to use the default config spec.
% cleartool setcs -default % cleartool catcs element * CHECKEDOUT element * /main/LATEST |