tags:

views:

3926

answers:

5

In a static view, how can I view an old version of a file?

Given an empty file (called empty in this example) I can subvert diff to show me the old version:

    % cleartool diff -ser empty File@@/main/28

This feels like a pretty ugly hack. Have I missed a more basic command? Is there a neater way to do this?

(I don't want to edit the config spec - that's pretty tedious, and I'm trying to look at a bunch of old versions.)

+1  A: 

[ 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!

Chris Arguin
I don't want to diff between versions, I just want to look at a previous version (not necessarily the immediate predecessor). I'm only using diff because it's the only single command I know to see a complete version. What I really want is something like "cleartool cat" (which doesn't exist AFAICT.)
Matt Curtis
Thanks Chris. The virtual directory structure doesn't exist in static views (AFAICT). I guess the answer is: there's not a cleaner way of doing it in a static view in a single line... Nice story about the Perl script, it seems most ClearCase shops have a hodge-podge of essential "support scripts" :)
Matt Curtis
@Matt you are correct, extended path are not directly accessible from a snapshot view. However I have update my answer in order to have a clearer output of previous file versions, from a snapshot view.
VonC
+3  A: 

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 snasphot 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:

    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

    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.

VonC
Thanks, but I need to do it on the command line (the host is Unix and the X GUI is unusable over our slow network link.)By "a bunch of old versions", I'm trying to see what changed across various revisions, so there's a number of files and a number of revisions.
Matt Curtis
..and editing the config spec seems like the long way round (when I have a one-liner). I guess what I'm asking is: what's the idiomatic way to "cat" an earlier revision of a file?
Matt Curtis
I just updated my answer. Check it out and leave a comment if it is still not good enough.
VonC
Yep, it looks like a definitive answer to me. (I guess I'll stick with the "diff" hack in the static view.) Thanks VonC.
Matt Curtis
A: 

ct shell cat File@@version

Justin
That doesn't seem to work, I get this error:cat: File@@/main/28: No such file or directory
Matt Curtis
+1  A: 

Wow, thanks ClearCase. You dont provide a way to view previous versions. That is a good idea, because developers never need to view previous versions of their code, and that isn't at all the entire purpose of source control software. Now i see why it was such a good idea for our company to dump source safe for this really "dynamic" source control software.

robert
I don't like clearcase either, but it's always a good idea to dump source safe. Even if you dump it in favor of manual zipfiles. Source safe is like like a car that comes equipped with a car bomb. It looks like a car, drives like a car but occasionally it's actually a bomb. You'd be better off with a bicycle.
caspin
A: 

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.

Bart
@Bart: Not correct in a static view (stated a few times in the question).
Matt Curtis