clearcase latest version of a file on a particular branch - clearcase

I know the filename of a clearcase versioned file. How can i find the latest version of this file on a particular branch ? It should not pick any child branches. Also the parent branch names may not be know always.
Thanks.

If you are using a dynamic view, you can directly access the LATEST version of a given branch by using the extended path:
cat file##/main/branch/subbranch/LATEST
If you don't know the exact branch path (parent branches) this version is stored in, you can modify your dynamic view and add first the selection rule
element /path/to/file .../subbranch/LATEST
That will select the LATEST version of subbranch within the dynamic view.
Or you can do a cleartool find, in order to see the full extended path for that file:
cleartool find . -name "yourFile" -ver "version(.../subbranch/LATEST)
You will be able to cat (or type in Windows) directly the result (which will be the full extended path)
The diea behind the cat or the cleartool find is to be able to use the syntax .../subbranch/LATEST.
That syntax with the three dots means: '.../subbranch' whatever branches followed by /subbranch.

Related

ClearCase: Find all versions of a file newer than labelled version

Suppose I have a file with versions 0 to 4. On version 2 I applied a label called mylabel. Now I want to do a find query using cleartool which gives me all versions created after my labelled version 2. That is I only want to get versions 3 and 4 as output, but not versions 0-2.
I know how to find all versions except the labelled one:
cleartool find . -version "!lbtpye(mylabel)" -print
There is also a command to get the history of this element:
cleartool lshistory -minor PATH_TO_FILE
This theoretically gives me the date when the label was applied, so I could do
cleartool find . -version "created_since(date)" -print
But the lshistory command always outputs the full history of the element and I feel it is too much to parse all this information just to get the desired date.
So basically I want to know if there is a more elegant way to do this. I could imagine that I could maybe first check which version has mylabel (because the version number is already provided by the find query) and then search for files with a version higher than the labelled version. So in my example with mylabel at version 2 I would hope for something like:
cleartool find . -version "version( > /main/2)" -print
After VonC's answer I should mention that the labeltype will only be created once and the label itself moved every few days. It is therefore not possible to check for the time the labeltype was created.
version( > /main/2) jas no equivalence in the ClearCase config spec 'version selectors'.
That means an easier option should rely on a convention, like the convention the date of applying the label should be very close to the date of creating the label type.
Meaning the mklbtype shoudl be done just before mklabel, and you could then use the label type creation date for your cleartool find . -version "created_since(date)" -print query.
Basically, the crux of the issue is to keep track of the date where the label where last applied (or moved, since it is here a shifting label).
Another approach would be to store that date as an attribute attached to the lbtype: only one lbtype, and one attribute changed each time the label is moved.
See cleartool mkattr.

In ClearCase using commandprompt, how to check whether we have checkedout the latest version of the file?

I have a file called prog.c in clearcase, for example the user has checked out this file, say the user has checked out the version 3 of the file.
After that, if some other users checked in the same version of file. say the latest version be 6.
How to check the latest version of the file using the CLEARTOOL command?
One way would be a cleartool lsvtree yourFile:
That would display a textual representation of the version tree, allowing you to see if the version you have is the LATEST on a given branch.
But one nice trick I sometime use in snapshot view is: 'cleartool co -nc yourFile'.
if it works, I cleartool unco immediately.
but, if the version isn't the LATEST, the checkout will fail, with a warning asking to update first.
Note that in a dynamic view, the problem is slightly different: one can checkout (unreserved) while other checkout/check-in.
You will know you don't have the LATEST version on the checkin stage: it will complain you must merge with the actual latest version in order to create a "new latest" version which will the the result of the combination (merge) of your work and the later versions.
One way to know where your at, with a checked out version, is to do a:
cleartool descr -pred -fmt "%Sn" MyFile
(see "Change set predecessor using cleartool", and "How to list all my check-ins using ClearCase?")
"%Sn" will give you the branch and version of the file currently checked out.
You can compare that with:
cleartool descr -fmt "%Sn" M:\aDynamicView\Vob\path\to\myFile
If you have a dynamic view with the same config spec and no checkouts, you can use it as "reference view", and see if the branch version in that reference view is the same than the version previous to the one checked out in your local (snap or dyn) view.

clearcase query results into winmerge

I can compare two files in Winmerge by triggering a comparison on the command line with a command similar to:
WinMergeU C:\file1.txt C:\file2.txt
I can query a list of files with particular properties in clearcase with a clearcase query similar to:
Y:\VOB_A>cleartool find . -type l -exec "cleartool describe -fmt "%n %[slink_text]Tp\n\n\" \"%CLEARCASE_PN%\""
.\Directory\createsymlink.txt -->..\..\VOB_B\SymlinkFolder\createsymlink.txt
What I want is to generate a set of clearcase query results that can then be used as input to winmerge (ie generate a bunch of diff commands on checkins fulfilling a certain criteria like user or day).
How can I write a clearcase query to get a list of file elements (referable in clearcase ie winmerge could open the path to the version on a dynamic view), and get their corresponding previous version of the file?
The bit to format this to winmerge I imagine would look somewhat like this:
... describe -fmt "WinMergeU ...
One, you would need to generate the right full extended pathname for each file (one being the result of your query, one being the previous version of the one found by said query)
Two, you need to do so in a dynamic view (in order to access to any version though the extended path name of the file.
Once your query gives you a version, you can ask, with a cleartool descr -fmt "%PSn" (see fmt_ccase man page), for the previous version and add that to your result file.
Trying to do it all in one pass (find + predecessor version + WinMerge call) seems too complicated.

Accessing an eclipsed element in ClearCase

In my current working environment, I make use of eclipsed files extensively for testing purposes. When it comes time to formalize things, I have a script which generates a diff by comparing the file with a backup saved by my eclipse script.
I'd like to be able to work without the backup of the original file; is there any way I can retrieve the current version of the file that I can pass to diff? Even though the file is view-private, I see I can enter foo##/ and see a list of versions, but I'm not sure how to find which version is the latest. Everything I've tried using cleartool ls or describe with the file name tells me that it's not a VOB object (which is true, although cleartool ls does show it as eclipsed, so it must know, somehow, that there is an element there)
Thanks
Eclipsed file means dynamic view.
The simplest solution would to make a second dynamic view based on the same config spec.
Considering how cheap and quick those views are, this isn't an issue.
On that second dynamic view, you can do a
cleartool descr -fmt "%Xn" /path/to/element
In order to get the extended pathname of the file (see fmt_ccase for more on the %Xn syntax).

How can a ClearCase directory version be determined for a given file version?

Because ClearCase updates directory version numbers when files inside are created, our config-spec generating script is failing (details omitted).
So, as an example, given a file such as "/proj/src/scripts/build.sh##/main/branch42/3", how can we determine the latest version of the scripts directory that contains that version of the build.sh file.
Note: we're looking for a unix command-line solution that can be scripted.
If you do a ls /proj/src/scripts##/main/branch42/*/build.sh/main/branch42/3 you should get a list of all versions of the scripts directory that contain version .../3 of build.sh. Then you should be able to pick out the latest of those.
The above is probably not a fool proof approach, so you might try something more like
cleartool find /proj/src/scripts --allversions --nonvisible -name build.sh -version 'brtype(branch42) && version(3)' -print
(I no longer have a clearcase environment to test in, so the above is from memory and is not an accurate command)
Another approach is to:
set a label on the right version of the build.sh script and its directory (you can move that label when needed)
have a second dynamic view always configured to select that label
element * SCRIPT_LABEL
element /proj/... .../branch42/LATEST
That way, you simply read the information you need from that second dynamic view.

Resources