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

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

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

How to get list of all the versions and labels applied for a particular file in clearcase?

I have a file
"N:\E123_view\ABC\XYZ\data.doc"
I want to get all the versions of the file and all the labels tagged to it.
One approach, in command line, is to use a version tree: cleartool lsvtree.
cd N:\E123_view\ABC\XYZ
cleartool lsvtree -all data.doc > afile.txt
lists all versions on a branch, not the selected versions only; annotates each version with all of its version labels.
Another approach is to use lshistory combined with fmt_ccase
cleartool lshistory -fmt "%n %l\n" data.doc
%n will print the version, as in /main/rel2_bugfix/1
%l will print the label (if present).

How to remove label of a directory and all its contents in clear case?

I have applied a label to directory in clear case recursively. How can I remove all those labels?
The simplest approach would be in command line, using cleartool rmlabel
cleartool rmlabel -rec YOUR_LABEL yourDirectory
Note: this is for ClearCase V7.1+ only, not CC7.0.x or CCV6.x, and not for CCRC (ClearCase Remote Client)
With older ClearCase versions, you had to do (see technote swg21126736):
# Unix syntax
cleartool find yourDirectory -version "lbtype(YOUR_LABEL)" -exec 'cleartool rmlabel YOUR_LABEL"$CLEARCASE_XPN"'
# Windows syntax
cleartool find yourDirectory -version "lbtype(YOUR_LABEL)" -exec "cleartool rmlabel YOUR_LABEL\"%CLEARCASE_XPN%\""
Note: you could remove a label using a GUI, but as described in technote swg21146450, this is a file-by-file operation only!
(Not very practical if you have hundreds of elements -- files and directories -- to process...)

Cleartool - find unloaded/removed files

Is there a command in Cleartool which i can use to list all files which have been removed from a branch?
Thanks
The basic command to find anything in ClearCase is... cleartool find, also illustrated in "ClearCase UCM: Need to See Content of Deleted File".
In your case, you would search for versions of files which aren't at the LATEST of a branch:
cleartool find . -type f -version "! version(.../BRANCH/LATEST)" -print
(see version selector for more on this '.../' notation)
To display only the file (and not all the versions):
cleartool find . -type f -element "! version(.../BRANCH/LATEST)" -print
The OP linuxlewis mentions in the comments:
this will show all differences which exist between sibling branches. I just want to be able see the file names,if any were removed,from the current branch
I mention the possibility of a grep for BRANCH, to detect files which have versions in BRANCH but not LATEST)
However, a cleaner solution is to add another filter to the search: && version(.../BRANCH)
cleartool find . -type f -element "! version(.../BRANCH/LATEST) && version(.../BRANCH)" -print
That will search all "elements" (files or directories in ClearCase) which have versions in branch BRANCH, but not one in BRANCH/LATEST.

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