开发者

Script to get a file's version in clearcase

I would like to get a file's clearcase version by means of a script开发者_JAVA技巧. Is that possible?

Thank you.


The surest way to get the version of a file is to:

  • use the CLI command 'cleartool'
  • combine it with the fmt_ccase options available for a cleartool describe command.
cleartool descr -fmt "%Vn" myFile

That way, no need to parse anyhting: if this is a versioned file, the result won't be an empty one.

cleartool descr -fmt "\tElement: %-13.13En Version: %Vn\n" util.c
Element: util.c Version: /main/rel2_bugfix/1

Note: if the file is CHECKEDOUT, you might want to add the option -pred (predecessor) to the descr command:

ct descr -fmt "%Vn" .project
\main\MyProject_Int\MyProject_Dev\CHECKEDOUT
ct descr -pred -fmt "%Vn" .project
\main\MyProject_Int\MyProject_Dev\CHECKEDOUT  predecessor version: \main\MyProject_Int\MyProject_Dev\4

or just use %PVn (same result, but no parsing involved)

ct descr -fmt "%PVn" .project
\main\MyProject_Int\MyProject_Dev\4


I would like to think everyone would agree there's quite a few ways to receive the output you want. Instead of using the GUI to save a listing of all my merge files during a findmerge I run the cleartool 'find' command to get what I need, then port that output into another command to auto label each.

For instance:

cleartool find . -user -version "{brtype(branch-name) && created_since(date) && (! version(/main/branch-name/0))} -print

The above command will find all versions that were created on a branch by a specific user created on a certain date (fmt: 1-Jan-10 or 1-Jan) and is NOT the zero version. You can actually put in a date range if you wanted as well. As is, the current command will returned those files that currently CHECKEDOUT as well. To remove that from the output, add the following after the -print: | grep -v CHECKEDOUT.

You can play with the command to find the exact match you want, but what is above will give you a solid basis to begin with.


cleartool describe -short -predecessor <filename>


I'm not sure which scripting language you are using, but you can always invoke the system command cleartool ls <filename> and then parse the output to get the version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜