Display ASCII graph of Cleartool ls commands - clearcase

In git it is possible to show an ASCII graph of the log with git log --graph which outputs a commandline graph something like:
* 040cc7c (HEAD, master) Mannual is NOT built by default
* a29ceb7 Removed offensive binary file that was compiled on my machine
| * 901c7dd (cvc3) cvc3 now configured before building
| * d9e8b5e More sane Yices SMT solver caller
| | * 5b98a10 (nullvars) All uninitialized variables get zero inits
| |/
| * 1cad874 CFLAGS for cvc3 to work succesfully
|/
* d642f88 Option -aliasstat, by default stats are suppressed
Is this also possible with ClearCase / ClearTool when using the lsstream or lsvtree commands, without the need to open a GUI?

Since I couldn't find anything that suited me, I created my own python script with this ability. It is still a little rough, but works for me.
For anyone interested, it is available here as a github gist

With command line, you have cleartool lsvtree.
If you want the history to focus on the branch you currently are (instead of starting by default at /main), you need to use the -bra/nch branch-pname option.
Starts the version tree listing at the specified branch.
You can also use an extended name as the pname argument (for example, foo.c##\main\bug405) to start the listing at a particular branch.
But if you need additional information like the author, then you would need to fallback to cleartool lshistory: see "How to ask cleartool lsvtree to show the author's name"

Related

How to find where a string was added at first in code, with ClearCase?

I want to find in which ClearCase label a specific string was added in code?
I am using base ClearCase.
I recommended before (8 years ago) to limit the scope of your search and use the exec clause of a cleartool find.
Example:
cleartool find -all -type f -user myLogin \
-version "lbtype(A_LABEL)" \
-exec ...
If you can do so in a dynamic view, you can then directly grep the content of CLEARCASE_XPN, the variable set by cleartool find for each version found.
It reference an extended pathname that (in a dynamic view) you can directly read and grep for your code)
You can do so for each label you can find in your Vob, from the oldest to the newest.
Z:myvob>ct lstype -kind lbtype -short
Z:myvob>ct find . -version "lbtype(A_LABEL)" -print
If you are looking for a specific change in a given source file, the cleartool annotate command will give you a good start. If you're familiar with GIT, this is the equivalent of "git blame."
Annotate works only if the element is one of the text file types (text_file, utf?_text_file, etc.) since those store delta information on a per version basis.
One caveat is that this will tell you what version the change came from, but if that version was created by a merge, you may have to backtrack the merge to find the original location of the change. ALMToolbox's "visual annotate" tool does that for you, if I recall correctly.

ClearCase UCM: Branch created of file that is not part of an activity. What happened?

I have somehow created a branch of a file in clearcase UCM that is not part of an activity. I have no idea how to reproduce this, but my stream is showing many files with this symptom. How can I find these files, remove them, and prevent it from happening again in the future?
Here is an example of one such file, names redacted to protect the innocent:
xxxxxxxxxxx.cpp##/main/xxx-integration/xxxxxx-xxxxxxxx/0 Rule: .../xxx-xxxxxxx/LATEST
A ct lsact -long | grep <filename> returns no results.
Update:
I used a find command to track down all the files that are on the branch given (and redacted) above, though I still do not understand the issue.
Per VonC's answer, where is what I ended up doing:
cleartool find . -type f -version "version(.../xxx/LATEST)&&version(.../xxx/0)" -print | tee ~/tmp/files2
I then read through the list of files generated to make sure they made sense, then I verified they were not attached to an activity and removed the versions:
cat ~/tmp/files2 | while read
do
if [ -z "$(ct describe -fmt "%[activity]p" $REPLY)" ]
then
ct rmbranch -f ${REPLY%/0}
fi
done
That can happen ig those file were checkout in a base ClearCase view, ie a non-UCM view, withg a simple config spec:
element * .../xxx-integration/LATEST -mkbranch xxxxxx-xxxxxxxx
You can use a find command similar to "How can I find all elements on a branch with version LATEST that has no label applied?".
The difference is: for each version found, you need to describe it in order to check if there is an activity attached to it or not (with a fmt_ccase):
cleartool describe -fmt "%[activity]p" "$CLEARCASE_XPN"

How to get the contributing activity details on integration stream?

I need help in knowing how to get the details of when a particular contributing activity is delivered to integration stream.
I used to use diffbl -activity baseline1 baseline2 in cleartool to get the list of activities made from one baseline to another baseline.
Now the new need is that i need to get the date time of when some of the activities listed as an output of diffbl are delivered.
I tried using lsact, describe but i am getting the "Activity not found" error.
Probably because the activity I am querying at is a contributing activity.
Could somebody know how to get the date time of when a contributing activity is delivered or how to customize the output of "diffbl -activity baseline1 baseline2" to get the activity date time details as well?.
When I look at the cleartool diffbl man page, I don't see any formatting option.
That means you need to parse the result of that command, feeding each activity to a cleartool describe -fmt, using one of the fmt_ccase option to display what you want.
This thread gives you an idea of the process to follow, but it is in bash (unix), to be adapted for windows if you need it:
for act in $(ct diffbl -act bl1#/vobs/apvob bl2#/vobs/apvob | grep ">>" | grep -v "deliver." | cut -f2 -d " "); do echo "Activity: $act"; cleartool desc -fmt "%d\n" activity:$act; echo; done
In multiple line for readibility:
for act in $(ct diffbl -act bl1#/vobs/apvob bl2#/vobs/apvob
| grep ">>"
| grep -v "deliver."
| cut -f2 -d " ");
do
echo "Activity: $act"; cleartool desc -fmt "%d\n" activity:$act; echo;
done
Note that by excluding "deliver." activities, we are focusing only on contributing activities, as explained in "How to find files asssociated with a ClearCase UCM activity?".
The OP Lax reports having successfully managed to extract the names of the activities, with a:
desc -fmt "%Nd\n" "activity:myActivityId"
(#\pvob being already part of the result of the diffbl command. Lax is just parsing the activityid from the diffbl results and putting it to desc command)
He adds:
I am needing this in the context of C#, so parsing is just like parsing any other string: I am using a regex to seperate the output to my interested activities. ex:
Regex.Matches(diffBlOutput, "myInterestedPattern");
And for each match in regex result, I get the activity with
RegexMatch.Groups["activity"].ToString()
activityid is actually a substring of this string as the result is always "activtyid activityName" so, substring(0,result.indexOf(' ')); gets me the activity id.

File churn in CVS

I'm looking to find the number of times that each file has changed on a particular branch in our cvs repository. I'm particularly looking for all the files which have changed the most. A "top 40" list would be good enough.
This was added as an edit by the original asker, I have converted it to a community wiki answer because it should be an answer, not an edit.
In this case, the branch has been in use for about 6 months. If I set to the latest in that branch ("cvs -z9 co -r r80m-1 ..."), it looks like the last number of the revision is the number of changes in the current branch -- if the file has been changed in the past 180 days, then it's on this branch. I'm using linux, so I eventually did it this way:
for file in `find . \! \( -name CVS -prune \) -type f -mtime -180`
do
cvs status "$file" | grep Working.revision | gawk -v FNAME=$file '{ print FNAME gensub(/(\.)([0-9]*)$/, "\\1\\2 churn:\\2 ", 1) }' >> cvs_churn.txt
done
sort -k3 -t: -n cvs_churn.txt | uniq
So, for each line in "cvs status" output like:
Working revision: 1.2.34
The gawk command changes it to:
./path/file.c Working revision: 1.2.34 churn:34
and I can then sort on ":34".
This works, but it's pretty crude. I'm hoping others may be able to answer with better approaches.
I've seen in some other questions eg: Free CVS reporting tools people have mentioned statCVS. It sounds interesting (more than I need, but some of the other info might also be useful). However, it says it only works on the "default" branch. The documentation was a little unclear -- can I set to the branch of interest, and use it for this?

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