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.
Related
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.
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.
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.
Whenever developer tries to debug the code they wanted to know list of files created and modified from particular day . I use
cleartool find command with created_since , but it finds only the files which are created not modified.
How to find both?
The cleartool find command can give you what you want, provided you look for versions created since a date, not element (file or directory).
See "Additional examples of the cleartool find command":
cleartool find <vobtag> -version "{created_since(target-data-time)}" -print
Since you are in UCM, you can limit that search to a specific branch name (corresponding to a specific Stream)
cleartool find <vobtag> -version "{brtype(BRANCH) && created_since(target-data-time)}" -print
Add the user in this request:
cleartool find <vobtag> -version "{created_by(user2) && brtype(BRANCH) && created_since(target-data-time)}" -print
And you should get what you need for a developer for a given Stream and date.
Below is example of finding all files changed after 27-Aug-2014
cleartool find . -version "{created_since(27-Aug-2014)}" -print
I followed what brainimus had to say here.
IBM Clear Case-> Administration -> Report builder.
In the Tree view Under \Reports Select Elements, and then choose the appropriate option.
I know one awkward solution for this taks will be :
first use ct ls to get the entire version info of the file
and pipe the version info to a parsing script to actually get the labels of the file .
But I guess ClearCase should have a "build in" solution for this task without support from any external scripts.
Please help me if you happen to know a "build in" solution for the task.
Thanks in advance.
fmt_ccase contains all the format-string for various ClearCase elements.
For a version of a file, you can:
cleartool descr -fmt "%l\n" /path/to/a/version
%l
Labels: For versions, all attached labels; the null string otherwise.
Labels are output as a comma-separated list, enclosed in parentheses.
A <SPACE> character follows each comma.
Variants:
%Cl
Max labels: Specify the maximum number of labels to display with the max-field-width parameter (see Specifying field width).
If there are more labels, "..." is appended to the output.
If no max-field-width is specified, the maximum default value is 3.
%Nl
No commas: Suppress the parentheses and commas in label list output;
separate labels with spaces only.
So the result can be:
Labels: (Rel3.1C, Rel3.1D, Rel3.1E)
Labels without commas or parens: Rel3.1C Rel3.1D Rel3.1E
In both case, you still need to parse the result, but at least the output can contain only the labels, as in:
Rel3.1C Rel3.1D Rel3.1E
onaclov2000 adds (from the comments):
The only problem with this is that you are grabbing the label on the specific version of the file.
Given that branches etc can exist, we'll need to be able to get ALL labels on a file.
If you use version tree graphical and select tools -> "locate" you can see ALL the labels attached to that file.
Is there a common command in cleartool that will return the results of "locate", or "contents"?
The lsvtree (graphical version tree) does display the labels of all the versions of the element currently seen by the view when you click "Label Name"
That being said, there does not seem to be a "built-in" solution and some parsing is involved:
For instance (which is a bit shorter than the OP version but still based on a cleartool ls):
ct ls -l addon.xml##|grep version|gawk "{gsub(/^version.*##\\\\/,\"\",$0) ; gsub(/ \ [.*/,\"\",$0); print $0}"
(GnuWin32 syntax)
or, only with a dynamic view:
cd m:/myView/path/to/addon.xml##
# list all files, not directories: the files are the labels
dir /B /A-D
The IBM article "Additional examples of the cleartool find command" is a great source for find query.
To expand on the "lsvtree" bit mentioned by VonC in his answer, you have:
To find all elements with any label:
Windows:
cleartool find . -type f -exec "cleartool lsvtree -a %CLEARCASE_PN%" | findstr
"("
./hello.c##/main/1 (LABEL100, LABEL99, LABEL98, LABEL97)
./foo.xml##/main/BR1/1 (REL2)
./bar.o##/main/1 (REL1)
UNIX/Linux:
cleartool find . -type f -exec 'cleartool lsvtree -a $CLEARCASE_PN' | grep "("
./hello.c##/main/1 (LABEL100, LABEL99, LABEL98, LABEL97)
./foo.xml##/main/BR1/1 (REL2)
./bar.o##/main/1 (REL1)
That finds only labels for versions currently selected in the view, but you could reuse the lsvtree part to grep all versions of a file with labels.