ClearCase: How to find elements that do NOT have a particular label - version-control

I'm looking for a ClearCase command that will list all the elements that are visible in my current view, but do NOT have a particular label applied to them.
Say for example, most of the elements that are visible in my view have LABEL_X applied to them. I want a list of those elements that do not have LABEL_X.
I obviously need to use cleartool find, but the usage and ClearCase man page baffle me in terms of how to construct a query like this.

This should work:
ct find -all -ele '! lbtype_sub(LABEL_X)' -print
ct find -ele '! lbtype_sub(LABEL_X)' -print
Notes:
ct stands for cleartool
Unix syntax here (for windows, replace simple quotes with double quotes)
beware of the space between ! and lbtype_sub (in winodws you do not need the space)
-ele very IMPORTANT to get only one occurrence of a given file (and not all the different versions of a file matching a criteria)
-ele limits the search to elements, not versions (that would trigger a lot more results with versions involved...)
-all list all elements included "deleted" (that is "unreferenced") ones.
The second line lists only visible elements (in the current view)
You should execute those second command lines on the sub-directory of your choice within a given ClearCase (snapshot or dynamic view): all files within that sub-directory (and sub-sub directories...) matching the cirteria will be listed.
Warnings:
files and directories are listed. If you want only files, add -type f to the query:
ct find -type f -ele '!lbtype_sub(LABEL_X)' -print
what is displayed is the extended path for elements, that is the name of the file followed with ##.
To list only the name without ##, use '-nxn' (no extendedpathname option)
ct find -nxn -ele '!lbtype_sub(LABEL_X)' -print
Another more complex but also more complete way to list only the name without ##, is to use descr -fmt. For instance:
ct find . -ele "!lbtype_sub(LABEL_X)" -exec "cleartool descr -fmt \"%En %d\n\" \"%CLEARCASE_PN%\""
ct find . -ele '! lbtype_sub(LABEL_X)' -exec 'cleartool descr -fmt "%En %d\n" "$CLEARCASE_PN"'
would give you (in windows or unix syntax) the date and name of the files and directories not labeled LABEL_X.
With that 'descr -fmt' display, you can combine any kind of information and presentation you want for the result.

Above works, but remember to specifiy -cview to get JUST the current view, otherwise you'll get files from all the other views as well.

I needed to use the following on my Linux clearcase install:
cleartool find -cview -all -version '\!lbtype(LABEL_X)' -print
The syntax from VonC's post did not work properly with the "!" not being escaped.

Related

How can I stop find from searching a dir tree once it finds a match?

This is a variant of "How can I stop find from searching after first result found?" which I posted earlier today but is different enough to warrant a new question (IMO). It involves the find command ant potentially a perl soln if find can't do what I need.
Using find, I want to search a dir tree for all instances of dirs with name "out". Once an instance of "out" is found, I want it to stop searching under that dir but keep searching other paths for "out".
Consider this example...
mkdir -p top/a/b/out/c/d/out/e/leaf
mkdir -p top/a/bb/cc/out/dd/ee/out/ff/gg/out/hh/leaf
I want to find...
top/a/b/out
top/a/bb/cc/out
... but no other instances of "out".
Also, I want it to stop searching (wasting time) once it hits an instance of "out" in a path.
I am going to run this in perl, so I suppose I could get creative and write some recursive func to do this. And so I will also tag this with question with "perl" should that be the eventual solution.
Use the -prune action:
find top -name out -print -prune
This action prevents find from recursing into a directory.

Clearcase: list element labels in a view

Using ClearCase, I would like to retrieve all the elements of the VOB that do not have a particular label.
I am trying to do something similar to the following but it doesn't work.
Any help ?
cleartool find . -elem '( ! (lbtype(MYLABEL)))' -print
It should be a query similar to:
cleartool find . -elem '! lbtype_sub(MYLABEL)' -print
From cleartool find and query_language:
lbtype_sub (label-type-name)
With elements: TRUE if the element has a version that is labeled label-type-name.
More details in "ClearCase: How to find elements that do NOT have a particular label"

Query labels with a specific attribute in ClearCase

How can I query those of the labels in ClearCase with cleartool that have a specific attribute.
I can list the labels with
lstype -kind lbtype
but I'd like to get only those that have an attribute called TestAttr.
You can
first find all the version with a certain attribute
then describe those versions in order to display their respective branch
(unix syntax)
cleartool find . -version 'attype(an_attribute_name)' \
-exec 'cleartool descr -fmt "%Sn" "$CLEARCASE_XPN" '
You will still need to parse the result to extract the branch, and sort -u the result.
The OP comments:
I'd like to query the labels not the files. I have no files with that attribute
Then find is the wrong command.
The best you could do is to list all labels in a given VOB, and describe them in order to display their attribute (if they have one)
ct lstype -kind lbtype -invob vob:/avob -fmt "%n ~ %[an_attribute_name]a"
Only the lines with some value displayed after the "~" (an arbitrary separator just put here to easily distinguish the name of the label from its attribute value) are to be considered.
A label with no attribute (at least not the 'an_attribute_name' attribute) will display only its name followed by "~", without any other data after the '~'.

How can I interact with ClearCase from Perl?

My project needs couple of things to be extracted from ClearCase data using the Perl script in a excel sheet,those are -
By giving two particular time line or two baseline.
all the activity associated within that baseline (column header "activity")
Owner's id (column header-Owner)
all the element associated within a particular activity. (column header-"element details")
For each element the versions associated (column header-"Versions")
for each element the total number of lines of code,total number of lines of code added,total number of lines of code deleted,total number of lines of code changed..(column header"No. of lines of code","lines of code added","lines of code deleted" & " lines of code changed")
Please kindly help me on this...
Basically, ClearCase Perl scripting is based on parsed outputs of system and cleartool commands.
The scripts are based on a cleartool run cmd like package CCCmd, and used like:
use strict;
use Config;
require "path/to/CCCmd.pm";
sub Main
{
my $hostname = CCCmd::RunCmd('hostname');
chomp $hostname;
my $lsview = CCCmd::ClearToolNoError("lsview -l -pro -host $hostname");
return 1;
}
Main() || exit(1);
exit(0);
for instance.
So once you have the basic Perl structure, all you need is the right cleartool commands to analyze, based on fmt_ccase directives.
1/ all the activity associated within that baseline (column header "activity")
ct descr -fmt "%[activities]CXp" baseline:aBaseline.xyz#\ideapvob
That will give you the list of activities (separated by ',').
For each activity:
2/ Owner's id (column header-Owner)
ct descr -fmt "%u" activity:anActivityName#\ideapvob
3/ all the element associated within a particular activity. (column header-"element details")
Not sure: activities can list their versions (see /4), not easily their elements
4/ For each element the versions associated (column header-"Versions")
For a given activity:
ct descr -fmt "%[versions]CQp\n" activity:anActivityName#\ideapvob
5/ for each element the total number of lines of code,total number of lines of code added,total number of lines of code deleted,total number of lines of code changed..(column header"No. of lines of code","lines of code added","lines of code deleted" & " lines of code changed")
That can be fairly long, but for each version, you can compute the extended path of the previous version and make a diff.
I would advise using for all that a dynamic view, since you can access any version of a file from there (as opposed to a snapshot view).
Also if you need to use perl with Clearcase have a look at the CPAN module ClearCase::CtCmd. I would recommend to use this perl module for invoking clearcase commands.
For the CCCmd package, I had to remove the double-quotes in the RunCmd and RunCmdNoError subs to get it to work.

how find objects between two labels in clearcase

I would like to get all sources/objects between two releases that happened within a month from clearcase. I wrote the below command and it displays only less number of sources compared to the actual one.
Please advive where I am wrong
cleartool find <path> -element "lbtype (Label b) && ! lbtype(label a) && ! -element (.../Branch1/latest)" -print
where:
label a is the label of last month release
label b is the current label
and branch1 is the branch from where all release happened
Thanks in advance
To see in general what has changed between two dates:
cleartool find . -version 'created_since(10-Jan) && !created_since(11-Jan)' -print
But in your case, you missing probably a '_sub' directive (see find examples for more requests):
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.
cleartool find <path> -element "lbtype_sub(Label b) && ! lbtype_sub(label a) && ! -element (.../Branch1/latest)" -print