How do I check on which branch a label resides? - clearcase

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...

Related

Set label on latest element in a branch

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

Find Objects that have not a label in any version

I want to find objects that have not got a LABEL in any version.
I can check if any object has a LABEL in its LATEST version with following command :
cleartool find . -version "version(/main/LATEST) && !lbtype(MYLABEL)" -print
And this command also lists all versions :
cleartool find . -version "!lbtype(MYLABEL)" -print
I want the object list that has not got label (MYLABEL) in any versions. How can I do this?
You can first try looking for elements instead (with the lbtype_sub query primitive):
cleartool find . -ele "!lbtype_sub(MYLABEL)" -print
See "Additional examples of the cleartool find command"
About *_sub query primitives
When using the ClearCase find command in what circumstances should the *_sub query primitives (attype_sub, label_sub and attr_sub) be used instead of just lbtype or attype?
When the type being queried does not apply to the "level" (-element -branch -version) being queried.
For example, query for a label using -element: labels are only on versions within elements
(you can limit to files only with -type f, or folders only with with -type -d)
If that does not work would recommend a three steps process.
find all the elements (file or folder) that have one version with that label
find all the elements
remove the first elements from the second list
The end result is what you are looking for.

Get elements of a label which is present only in the current version but not in any other previous versions

how do I get elements of a label which is present only in the current version but not in any other previous versions?
That wouldn't be possible with ClearCase, considering a label can only be associated with one version of an element (an "element" is a file or directory).
You could try and search for a label only applied on one element and not applied on any other element though.
how do i get all changed elements of a label from the current branch since last integration branch?
The query described in "How can I find all elements on a branch with version LATEST that has no label applied?" can be of interest.
Simpler queries are also available on this IBM page:
Find all element versions with a given label that are not on a given branch:
Windows:
cleartool find -all -version "lbtype_sub(MYLABEL) && !brtype(mybranch)" -print
UNIX and Linux:
cleartool find -all -version 'lbtype_sub(MYLABEL) && !brtype(mybranch)' -print

How to clean up unused branch types

I'm trying to reduce access times to ClearCase a bit, and am thinking about removing all the unused branch types (i.e. ones where no element has a branch of that type in the VOB). Is there a simple query that can return unused types, or do I have to scan for instances for each of the existing types?
I prefer something Cleartool or CAL based, as I want to build a tool that can be used by others.
I didn't see any "simple query", so it is best to check for each brtype instance in each vob.
First get the list of brtype for a given vob:
cleartool lstype -s -kind brtype -inVOB
(a bit like in the "Send to mkbranch script")
Then make a cleartool find to check if any version of a given element exists for one specific brtype.
cleartool find /aVobTag -element "brtype(aBrTypeName)"
Note: looking for elements is faster than looking for version here.
If you have the same name of brtype used in multiple branches, the "Additional examples of the cleartool find command" page illustrates:
How to find elements on a specific branch in multiple VOBs:
cleartool find -avobs -element "brtype(branch)" -print

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.

Resources