Command to find labels applied on particular branch - clearcase

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.

Related

command in clearcase to get list of all labels applied on an element

I'm trying to get the list of all the labels applied on an element.
I'm using
cleartool desc <element>
This seems to list all the other details of the element as well.
Is there any particular option with desc command that lists only labels?
Thanks
Use cleartool fmt_ccase in order to restrict the describe to only the labels.
cleartool descr -fmt "%l" myFile
You can see that technique used in:
"Which tag or branch is created from a particular branch"
"Command to find labels applied on particular branch"
"Cleartool - List Objects with Their Labels"
For instance, a slightly more complete output would be:
cleartool descr -fmt \"%n labels:%l\n\" myFile
Note: in UCM, a cleartool lsbl would be enough (for listing baselines).
But for base ClearCase, cleartool descr works.
To get labels for all versions of the element, add '-version' and a query to get all versions. My example uses !lbtype(x), since all our versions do NOT have the label 'x'.
cleartool find . -version "!lbtype(x)" -name "yourelement" -exec "cleartool descr -fmt \"%n labels:%l\n\" \"%CLEARCASE_XPN%\""
To output list with space separation, change the -fmt to -> -fmt \"%Nl \".
List could be very long if there are lots of versions and labels.
If you are using dynamic views, you can also use extended naming to see the set of labels applied to versions of the element:
% ls myfile.c##
Note that the output also includes the 'main' branch. You can omit the branch(es) on a non-directory element simply:
% ls -1F myfile.c## | grep -v /
Extra credit - You can also use extended names to see the set of labels applied to versions of a particular branch:
% ls -1F myfile.c##/main/mybranch | grep -v / | grep '[A-Za-z]'
(the trailing 'grep' assumes labels have at least one alphabetic character and will omit version numbers that would otherwise also be included in the output.) That output will also include 'LATEST' but you can easily omit that, too, if desired.

Which tag or branch is created from a particular branch

In ClearCase suppose I have a branch App_Feb_Branch. Now I want to know if any Tag or Label has been created from this branch. How can I get this information?
You can list baselines (for ClearCase UCM) or grep for version with a label (for base ClearCase).
See "Command to find labels applied on particular branch":
ct find . -nrec -name "." -ver "brtype(myBranch)" -exec "cleartool descr -fmt "%l" \"%CLEARCASE_XPN%\""
With fmt_ccase formatting options, you can use the %l to only display labels for the versions found.
That is what the cleartool descr -fmt "%l" \"%CLEARCASE_XPN%\" part of the cleartool find above does.

Checking if Two Different Config Specs Select Exactly the Same Element Versions

I have two similar but different config specs that I believe should select all of the same element versions. How can I most easily check if this is the case?
You can create two dynamic views, each one with their own config spec:
cleartool setcs -tag aViewTag yourConfigSpecFile
You can then compare the result of:
cleartool ls
(in both views)
A cleartool ls display the exact version found in each view.
Even better, using fmt_ccase:
# unix
cleartool find . -exec 'cleartool desc -fmt "Version: %n\n" $CLEARCASE_XPN'
#windows
cleartool find . -exec "cleartool desc -fmt \"Version: %n\n\" \"%CLEARCASE_XPN%\""
That will list all the selected versions, and you can redirect the output in a file, one for each view.
Then the comparison is trivial.

Cleartool: How to apply label to files which are in my current view only?

I could not find the proper command to apply a label to files which are in my current view. I have tried the following command:
cleartool mklabel -r TEST_LABEL /vob/test/a
However, the problem is that this command will apply the "Test_Label" label to every files in the "vob/test/a" directories regardless of whether the files are in my current view.
Is there any command to apply label only to the files listed in my current view?
cleartool mklabel -r(ecurse) LABEL_NAME <directory name>
This command will apply LABEL_NAME to all files in folder and below of your view, you can just go to that directory,then type following command to create and apply label
> cd /vob/test/a
> cleartool mklbtype –nc TEST_LABEL
> cleartool mklabel -r TEST_LABEL .
The mklabel documentation state states, as to what version is labeled:
Processes the entire subtree of each pname that is a directory element (including pname itself). VOB symbolic links are not traversed during the recursive descent into the subtree.
One example mentions:
Attach that label to the version of the current directory selected by your view, and to the currently selected version of each element in and below the current directory.
Now, if you want to be really sure of the versions actually labelled, one solution is to use a find command, combined with your mklabel:
cleartool find . -cview -exec "cleartool mklabel TEST_LABEL \"%CLEARCASE_XPN%\""
If you had already that label applied to incorrect version and want to move it:
cleartool find . -cview -exec "cleartool mklabel -replace TEST_LABEL \"%CLEARCASE_XPN%\""
That way, you can first list the versions involved:
cleartool find . -cview -print
And then, if you agree with the output, apply the mklabel through the -exec directive.
The OP user1096966 reports making it work with a cleartool ls, to be sure to select only element visible in the current view:
cleartool ls -r -vis
The is no '-exec' directive, so a pipe might be involved, as in (not tested, but you get the idea):
cleartool ls -r -vis -s -nxn | xargs cleartool mklabel -replace TEST_LABEL
The doco is really clear about what is being labelled, in fact the first example shown in doco states that exactly...current view objects are labelled by default & currently selected versions (i.e. if in your view then label it, else not.)
....extract below from doco below (note: context and command and that label-type-selector pname is the last parameter...left blank below because resident in working dir)...
Example:
•Create a label type named REL6. Attach that label to the version of the current directory selected by your view, and to the currently selected version of each element in and below the current directory.
cmd-context> mklbtype –nc REL6
Regards
Jim2

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