How to save cleartool diff file - clearcase

Used rcleartool> diff -g -pred myfile.xml to get the file differences grahically. But is there a way to save this diff file? For me the file save button is disabled. Any hints?

I would start by omitting the -g (-graphical) optin of the diff command: that should yield a text result, that you can easily redirect to a file for saving its result.
rcleartool> diff -pred myfile.xm > res
You could do so from a regular CMD/bash session as well using rcleartool directly:
rcleartool diff -pred myfile.xm > res
See also "cleartool: how to write the result from command find to a text file".

Also, the reason the save option is disabled is because the diff tool is also the merge tool. The "save" option is only enabled during a merge, and only when all unresolved merge points have been handled.

Related

What is the Cleartool command to undo check out if it is identical?

I checkout a powershell file and signing it if it is not signed already then check-in back.
But my check-in fails as saying identical to predecessor. What is the cleartool command to undo checkout if it is identical to previous version?
You can simply try:
cleartool unco
That is "undo checkout"
Now you cannot do that in the checkin command itself.
What you can do is a cleartool diff: if there is no difference detected, then you unco, if there are, you check in.
You have that approach detailed in this thread:
You may need to diff against the previous version, but you can use something like diff <file> <file>##/main/branch/version, and if different (or whatever that diff returns if they are different), then allow the checkin to succeed). Otherwise maybe unco -rm the file.
Or:
In our makefile we have a section that basically follows the following format for each file:
call checkin_if_changed.bat "dir1\sub\file.h"
The contents of the file "checkin_if_changed.bat" are as follows:
cleartool diff -pre -dif %1
echo File: %1 diff result: %ERRORLEVEL%
goto diff%ERRORLEVEL%
:diff1
cleartool ci -c "Build box build." %1
goto end
:diff0
cleartool unco -rm %1
:end
Basically we do a cleartool diff against the prev version of the file.
If the cleartool diff returns a 0 it means the files are identical, so we do an unco -rm.
If cleartool diff finds a difference it returns a 1, meaning the files are different, and we check it in.
Or:
I've used the somewhat messy:
cleartool lsco -cvi -avo -fmt "ci -nc '%n'\nunco -rm '%n'" | cleartool
If the file is identical (and fails the checkin), then it unchecks it
out.
If it isn't identical, it checks it in, then the unco command
fails (since it's not checked out) with an error (but continues).
You can dump all of the output to a log file if you don't want to see it on
the command line. You can probably refine that if you need to.
If you have a post checkin trigger that forces you to enter a comment, then
change the -nc to -c 'some comment' instead.

Clearcase error reports

Is there a way to mute or remove error messages from a Clearcase command such as mklabel? I'd like to suppress error messages from the mklabel command if possible.
The scripts you see in this thread (or this one, or in one of the ten best scripts) usually employ the same technique:
cleartool mklabel ... 2> /dev/null
In a perl script for instance:
my $cout = `cleartool desc $pn##\/$lbtype 2>/dev/null` ;
This is part of cleartool output redirection techniques.
I prefer redirecting stderr in a file, that I can parse (after executing the command) to detect rare errors, while ignoring all the warning (like label already existing and moved).
But the main idea remains: for a cleartool mklabel, there is no -silent or -quiet option.

How to post review for multiple clearcase files in review board

Old File : /vobs/code1/dir1/file1.c##/main/branch1/4 .
New File : /vobs/code1/dir1/file1.c##/main/branch1/mybranch/1
$ diff -q /vobs/code1/dir1/file1.c##/main/branch1/4 /vobs/code1/dir1/file1.c##/main/branch1/mybranch/1
Files /vobs/code1/dir1/file1.c##/main/branch1/4 and /vobs/code1/dir1/file1.c##/main/branch1/mybranch/1 differ
$ post-review --server http://reviewserver.oursite.com --revision-range='/vobs/code1/dir1/file1.c##/main/branch1/4:/vobs/code1/dir1/file1.c##/main/branch1/mybranch/1'
There don't seem to be any diffs!
$
Why i am getting above message when there are difference in files ?
Generate unified diffs of all files using option -U of GNU diff command:
diff -U 100000 file1.c##/main/4 file1.c##/main/10 > uni_diffs
diff -U 100000 file2.c##/main/br1/3 file2.c##/main/branch2/4 >> uni_diffs
diff -U 100000 file3.c##/main/abc/4 file3.c##/main/30 >> uni_diffs
....
Note 100000 is passed so that complete file can also be viewed on review board.
Assuming file length is less than 1000000.
Post the above unified diff file to review board :
post-review --diff-filename=uni_diffs ....
Deepak
In many RBTool versions there is a mistake in class ClearCaseClient, function diff_between_revisions.
Problematic part in postreview.py looks like this:
revision_range = revision_range.split(';')
Two ways to handle this issue if staying with current version of Review Board and RBTools:
1) Changing semicolon to colon in the postreview.py code
2) Using semicolon as delimiter in the command line argument.
Choose the preferred solution and use it. ;-)

cleartool question

Lets say I have a directory at \testfolder, and the latest is currently at /main/10. I know that the operation resulting in testfolder##/main/6 is to remove a file named test.txt.
What's a sequence of cleartool operations that can be done in a script that will take "testfolder##/main/6" and "test.txt" as input, and will cat out the contents of test.txt as of that time?
One way I can think of is to get the time of /main/6 operation, create a view with config spec -time set to that time, and then cat the test.txt at the directory. But I'm wondering if I can do this in a easier way that doesn't involve manipulating config specs, perhaps through "cleartool find" and extended path names
If you are using a dynamic view, you should be explore directly the extended pathnames of testfolder in order to access the content of test.txt.
cd m:\myview\myVob\path\to\testfolder
# In version 5 of testfolder, test.txt was still there
cd ##/main/5
# Note: test.txt is a directory! only LATEST is a file
type test.txt#/main/LATEST
The OP adds:
how about if test.txt was moved from testFolder to testFolder2, and then a new version of test.txt is checked in? In this when I go into testfolder##/main/5, test.txt##/main/LATEST is incorrect...
Technically, this is a case of evil twins: 2 objects of the same names exists (one in testfolder##/main/5, one in testfolder##/main/10) with different history.
You need, to get back the former test.txt (a like rollbacking a file), remove your current test.txt and get back the old one currently moved to Folder2. (cleartool move)
cd testFolder2
cleartool checkout -c "move test.txt back to testFolder"
cd ../testFolder
cleartool checkout -c "get back test.txt from testFolder2"
cleartool rmname test.txt
cleartool move ../testFolder2/test.txt
cleartool ci -nc .
cleartool ci -nc ../testFolder2

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.
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
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.
[ 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!
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.
ct shell cat File##version

Resources