Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
104 views
in Technique[技术] by (71.8m points)

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

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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(?:files+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(?:files+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 devhello_worldfoo.c@@main2 into the C:uild directory.

cmd-context get –to C:uildfoo.c.temp devhello_worldfoo.c@@main2

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:uildfoo.c.temp devhello_worldfoo.c@@main2 | type C:uildfoo.c.temp 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...