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

5

17

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.)

Clarification: I want to send the version of the file to stdout, so I can use it with the rest of Unix (grep, sed, and so on.) If you found this question because you're looking for a way to save a version of an element to a file, see Brian's answer.

Delilahdelimit answered 7/10, 2008 at 1:2 Comment(1)
headline should make it clear your talking about CCChartist
E
16

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 
Emersed answered 7/10, 2008 at 6:3 Comment(4)
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.Delilahdelimit
..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?Delilahdelimit
I just updated my answer. Check it out and leave a comment if it is still not good enough.Emersed
Yep, it looks like a definitive answer to me. (I guess I'll stick with the "diff" hack in the static view.) Thanks VonC.Delilahdelimit
R
13

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.

Retrorocket answered 10/2, 2011 at 21:1 Comment(3)
Ah! Perfect. I have no idea how I missed this (racking my brain, was it in ClearCase 6?). Never mind, answer ACCEPTED! Thanks Brian. I've slightly edited your answer with a sample usage.Delilahdelimit
Actually, sorry Brian, I've unaccepted your answer and given it back to VonC. Unfortunately, while it will let you save the version of the element to a file, simply getting the file's contents is tricky as it does not work with stdout (/dev/fd/1); cleartool reports "The destination pathname already exists".Delilahdelimit
@Emersed Nice work answer-gardening. I just realised I'd accepted your answer but not upvoted it. So there's your upvote, 2 and a bit years later :) All said, it's a bit of a shame that CC (at least CC7) doesn't permit get to stdout. The Rule of Composition (faqs.org/docs/artu/ch01s06.html#id2877684) is a beautiful thing.Delilahdelimit
B
2

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

Brader answered 7/10, 2008 at 4:58 Comment(3)
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.)Delilahdelimit
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" :)Delilahdelimit
@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.Emersed
C
1

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.

County answered 5/10, 2010 at 21:50 Comment(1)
Not correct in a static view (stated a few times in the question).Delilahdelimit
O
-1

ct shell cat File@@version

Observe answered 28/12, 2009 at 5:27 Comment(1)
That doesn't seem to work, I get this error: cat: File@@/main/28: No such file or directoryDelilahdelimit

© 2022 - 2024 — McMap. All rights reserved.