In ClearCase, how can I view old version of a file in a static view, from the command line?

Solution 1:

I'm trying to look at a bunch of old versions

I am not sure if you are speaking about "a bunch of old versions" of one file, "a bunch of old versions" from several files.

To visualize several old versions of one file, the simplest mean is to display its version tree (ct lsvtree -graph File), and then select a version, right-click on it and 'Send To' an editor which accepts multiple files (like Notepad++). In a few click you will have a view of those old versions.
Note: you must have CC6.0 or 7.0.1 IFix01 (7.0.0 and 7.0.1 fail to 'sent to' a file with the following error message "Access to unnamed file was denied")

But to visualize several old versions of different files, I would recommend a dynamic view and editing the config spec of that view (and not the snapshot view you are currently working with), in order to quickly select all those old files (hopefully through a simple select rule like 'element * aLabel')


[From the comments:]

what's the idiomatic way to "cat" an earlier revision of a file?

The idiomatic way is through a dynamic view (that you configure with the exact same config spec than your existing snapshot view).

You can then browse (as in 'change directory to') the various extended paths of a file.

If you want to cat all versions of a branch of a file, you go in:

cd /view/MyView/vobs/myVobs/myPath/myFile@@/main/[...]/maBranch
cat 1
cat 2
...
cat x

'1', '2', ... 'x' being the version 1, 2, ... x of your file within that branch.


For a snapshot view, the extended path is not accessible, so your "hack" is the way to go.

However, 2 remarks here:

  • to quickly display all previous revisions of a snapshot file in a given branch, you can type:

(one line version for copy-paste, Unix syntax:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(.../aBranch/LATEST) && ! version(.../aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'

(multi-line version for readability:)

cleartool find addon.xml -ver 'brtype(aBranch) && 
                               !version(.../aBranch/LATEST) && 
                               ! version(.../aBranch/0)' 
          -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'
  • you can quickly have an output a little nicer with

(one line version for copy-paste, Unix syntax:)

cleartool find addon.xml -ver 'brtype(aBranch) && !version(.../aBranch/LATEST) && ! version(.../aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"' | ccperl -nle '$a=$_; $b = $a; $b =~ s/^>+\s(?:file\s+\d+:\s+)?//g;print $b if $a =~/^>/'

(multi-line version for readability:)

cleartool find addon.xml -ver 'brtype(aBranch) && 
                               !version(.../aBranch/LATEST) && 
                               ! version(.../aBranch/0)' 
         -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'
| ccperl -nle '$a=$_; $b = $a; 
               $b =~ s/^>+\s(?:file\s+\d+:\s+)?//g;
               print $b if $a =~/^>/'

That way, the output is nicer.


The "cleartool get" command (man page) mentioned below by Brian don't do stdout:

The get command copies only file elements into a view.

On a UNIX or Linux system, copy /dev/hello_world/foo.c@@/main/2 into the current directory.

cmd-context get –to foo.c.temp /dev/hello_world/foo.c@@/main/2

On a Windows system, copy \dev\hello_world\foo.c@@\main\2 into the C:\build directory.

cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c@@\main\2

So maybe than, by piping the result to a cat (or type in windows), you can then do something with the output of said cat (type) command.

cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c@@\main\2 | type C:\build\foo.c.temp 

Solution 2:

I know this is an old thread...but I couldn't let this thrashing go by unresolved....

Static views have a "ct get" command that does exactly what you are looking for.

cleartool get -to ~/foo File@@/main/28

will save this version of the file in ~/foo.

Solution 3:

[ Rewritten based on the first comment ]

All files in Clearcase, including versions, are available in the virtual directory structure. I don't have a lot of familiarity with static views, but I believe they still go through a virtual fs; they just get updated differently.

In that case, you can just do:

   cat File@@/main/28

It can get ugly if you also have to find the right version of a directory that contained that file element. We have a PERL script at work that uses this approach to analyze historical changes made to files, and we quickly ran out of command-line space on Windows to actually run the commands!

Solution 4:

If File is a Clearcase element, and cat File works, and the view is set correctly, then try:

cat File@@/main/28

(note: without the ct shell-- you shouldn't need this if you're already in the view.)

Try typing:

ct ls -l File

If it shows the file with an extended name similar to the above, then you should be able to cat the file using an extended name.