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.

Community
  • 1
  • 1
Matt Curtis
  • 23,168
  • 8
  • 60
  • 63

5 Answers5

15

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 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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 Oct 07 '08 at 08:53
  • ..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 Oct 07 '08 at 08:55
  • I just updated my answer. Check it out and leave a comment if it is still not good enough. – VonC Oct 07 '08 at 10:26
  • 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 Oct 09 '08 at 03:35
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.

Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
Brian
  • 131
  • 1
  • 2
  • 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. – Matt Curtis Feb 17 '11 at 03:53
  • 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". – Matt Curtis Feb 17 '11 at 04:00
  • @VonC 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 (http://www.faqs.org/docs/artu/ch01s06.html#id2877684) is a beautiful thing. – Matt Curtis Feb 19 '11 at 10:26
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!

Chris Arguin
  • 11,850
  • 4
  • 34
  • 50
  • 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 Oct 07 '08 at 08:47
  • 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 Oct 09 '08 at 05:08
  • @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 Oct 09 '08 at 06:44
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.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
Bart
  • 19
  • 1
-1

ct shell cat File@@version

Justin
  • 1