Set label on latest element in a branch - clearcase

I have been working on a branch B1. There are several elements checked in on this branch. Now I want to put, or move if already labelled, label L1 on all latest versions on this branch.
How can I achieve this?

Basically, you need all elements (files or folders)
whose one of their versions have a label LB1,
but whose current visible version is not labelled LB1,
and then move LB1 to that visible version.
For that:
cleartool find -cview -element "{lbtype_sub(LB1)}" \
-version "{!lbtype(LB1)}
-exec "cleartool mklabel –replace REL3 \"%CLEARCASE_XPN%\""
Note the difference between:
lbtype (label-type-name)
In all cases, TRUE if the object itself is labeled label-type-name. (Because elements and branches cannot have labels, this primitive can be true only for versions.)
lbtype_sub (label-type-name):
With elements, TRUE if the element has a version that is labeled label-type-name.
The OP Paul confirms in the comments the following command is working:
cleartool find . -cview -elem "lbtype_sub(L1)" -exec "cmd /c cleartool mklabel -rep L1 %CLEARCASE_XPN%"
My config spec must be set to view the latest version in branch B1

Related

How do I check on which branch a label resides?

How Can I check if a label has been applied on main branch or the project branch?
I have a label which we apply on all the elements in a VOB in main branch, but I just found out that the label is applied on certain elements in a project branch.
Therefore I now need to make checks to find if any other elements on the sub branch have this particular label.
I now need to make checks to find if any other elements on the sub branch have this particular label
A cleartool find query shoould be enough:
cleartool find -all -version "lbtype(mylabel) && brtype(mybranch)" -print
Well, I'd make a slight change in case there were multiple project or developer branches:
cleartool find -all -version "lbtype(mylabel) && !brtype(main)" -print
This would print only the versions that have the label that AREN'T on /main.
Yes, I know it's a quibble...

Command to delete branches of Clearcase element with "0" versions

What is the command in Clearcase to delete the branches of an element in which it is not modified (Element's version in that branch is "0") ?
You can simply remove the version 0 of that element (that I detail here).
That will remove the associated branch.
cleartool rmver file##/main/aBranch/0
You would need to "cleartool find" all elements with a version 0 (and no version 1), and rmver those version 0.
For a given branch, this would return all the versions to delete:
cleartool find -type f -version "version(.../blah/LATEST)&&version(.../blah/0)" -print
You can combine that with an exec directive:
# on Windows:
cleartool find ... -exec "cleartool rmver --force \"%CLEARCASE_XPN%\"
# on Unix:
cleartool find ... -exec 'cleartool rmver --force "$CLEARCASE_XPN\"'
Be careful with rmver, this is a destructive operation, so do test that carefully before executing the full find -exec rmver command!
Another approach is mentioned in "Purging Zero-Version-Only Elements in ClearCase" article, by George F. Frazier:
you need to purge your view of those troublesome entities.
Run the following command to find all zero-version elements:
cleartool find -avobs -branch'{
brtype(mybranch)&&!
(version(.../mybranch/1))}'
-print > c:\files.txt
This will find all elements with no version 1 on mybranch (if you read closely you'll notice it doesn't do the right thing if you have removed the 1 version of an element that already has versions greater than or equal to 2 — this is a rare situation though).
Once finished, it's simply a matter of using rmbranch to nuke the elements (make sure you know what you're doing here!).
There are many ways to do that; since I run the MKS toolkit, I execute the following from a command window:
cleartool rmbranch -f 'cat c:\files.txt'
Tamir suggests a trigger to automatically remove version 0, as listed in the IBM Rational ClearCase: The ten best triggers, under the section Empty Branch.
cleartool mktrtype -c "Automatically remove empty branch" -element -all -postop uncheckout -execwin "ccperl \\mw-ddiebolt\triggers\test_empty_branch.bat" REMOVE_EMPTY_BRANCH
That is good for future cases where an undo checkout leaves a version 0.
rmver won't work.
/home/ccadmin $ cleartool rmver -force ./VaREngine/Makefile##/main/nz_mig/nz_relOne/0
cleartool: Error: Cannot delete version zero without deleting branch: "./VaREngine/Makefile".

Command to find labels applied on particular branch

Command to find labels applied on particular branch..
Suppose i have a branch name called BR_test , i want to know what are all the labels applied on this branch.
If this was UCM, a simple lsbl would be enough:
cleartool lsbl -stream myStream#\mypvob
But if this is base ClearCase, the simple way would be to determine what element (directory or file) is always labeled (typically a root directory), and fetch all the labels on that element for a given branch, through a combination of cleartool find and cleartool describe, based on fmt_ccase format (Windows syntax here):
C:\mySnapshotView\myVob\myRootDir>
ct find . -nrec -name "." -ver "brtype(myBranch)" -exec "cleartool descr -fmt "%l" \"%CLEARCASE_XPN%\""
That will list all labels for all versions of that element for a specific branch.

Find changes between labels

Using cleartool I am able to find all the files associated with a label using something like:
ct find -avobs -version "lbtype (Build-Label)" -print
How do I find all objects changed (including adds and deletes) between two labels?
In ClearCase (under Administration in my install) there is Report Builder. Under Elements/Labels you can select either "Elements Changed Between Two Labels" or "Versions Changed Between Two Labels" depending on which you need. You can then select the path to analyze and select the two labels to compare.
After the process runs you have the option to save the results as HTML, XML, or CSV.
There is a another way to do it , where LABEL1 is the old label and LABEL2 is the latest. Check the date of creation of the labels and swap them before issuing the command as it prints the negation of the && conditional statement. Works like magic!
$(cleartool find $PWD -ver "!lbtype($LABEL1) && lbtype($LABEL2)" -print)
As mentioned in the answer to "How to search files by label"
cleartool find -all -element "{lbtype_sub(REL1)}" -print
is simpler and lbtype_sub allow the query to be true if any version of the element has the label
(see query_language man page)
cleartool find -all -element '{lbtype_sub(REL1) && lbtype_sub(REL2)}' ^
-version '{!(lbtype(REL1) && lbtype(REL2)) && ^
(lbtype(REL2) || lbtype(REL1))}' -print
would find all elements that do not have both labels, listing all versions in the current VOB labeled either REL1 or REL2 but not both.
Note: if the label is a UCM baseline, this is off course even simpler (ct diffbl):
ct diffbl -ver BL1#\myPVob BL2#\myPVob
To find all elements, also those deleted or not selected by your config_spec, add –nvisible to the find options.
For comparision I have a shell script called freeze-list which more or less runs the same find command as you have there (redirecting the output to <label>.versions).
I then have some other perl scripts which takes two such files, reads them and compares each element. I have for instance freeze-compare-text for a plain diff -u output, freeze-compare-kdiff3 to start kdiff3 comparision on each file where there are some changes (with some intelligence to avoid false positives where the 0 element on a new branch is identical with the starting version etc). And I also have a freeze-compare-diffstat (basically piping the output to diffstat).
If you just are interested in finding changes between to labels as a one time operation, you can run
ct find -avobs –nvisible -version "lbtype(label1)" -print | sort > label1.versions
ct find -avobs –nvisible -version "lbtype(label2)" -print | sort > label2.versions
comm -3 label1.versions label2.versions
which will list all elements which do not have identical versions in label1 and label2.

How to display recent changes and logs for current view spec in clearcase?

newbie for clearcase.
Since clearcase's config is rather different from other concept in git, I may mean logs for
any files with specified version/branch path.
Like I want to show log for all element match:
element * .../specified-lable-or-branch/
First you need to be aware of the differences between ClearCase and Git, ClearCase being file-centric (no notion of repository-wide revision or commit)
You can display logs for any visible file by typing:
cleartool lshistory /myView/myVob/path/to/myFile
See lshistory man page. (and also How do I understand about ClearCase event records in the VOB database)
The lshistory command lists event records in reverse chronological order, describing operations that have affected a VOB's data.
File system data history.
Lists events concerning elements, branches, versions, and VOB links.
This includes records for creation and deletion of objects, and records for attaching and removal of annotations: version labels, attributes, and hyperlinks.
Another kind of logs is the lsvtree (history of versions):
The lsvtree command lists part or all of the version tree of one or more elements.
By default, the listing includes all branches of an element's version tree except for obsolete branches.
alt text http://youtrack.jetbrains.net/_persistent/tree.PNG?file=74-3724&v=1&c=true
The OP adds:
How can I display all history for elements match a pattern like has new version under a branch?
You can combine almost any commands with a find query.
Windows syntax:
cleartool find . -name "apattern" -exec "cleartool lshistory \"%CLEARCASE_PN%\""
cleartool find . -version "{created_since(target-data-time)}" -exec "cleartool lshistory \"%CLEARCASE_PN%\""
Unix syntax:
cleartool find . -name "apattern" -exec 'cleartool lshistory "$CLEARCASE_PN"'
cleartool find . -version "{created_since(target-data-time)}" -exec 'cleartool lshistory "$CLEARCASE_PN"'
For the " like has new version under a branch?" specifically:
cleartool find . -version "brtype(mybranch)" -exec ...
should do it (any element which has no version created for that branch will not be listed).

Resources