3

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Haiyuan Zhang
  • 40,802
  • 41
  • 107
  • 134
  • @Haiyuan: just completed my answer to list *all* labels of a file. No "build in" solution I am afraid. – VonC Mar 24 '10 at 14:13

2 Answers2

7

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 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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"? – onaclov2000 Mar 24 '10 at 13:26
  • @onaclov2000: not sure about the downvote, but I have extended my answer to address the "list all labels" query. – VonC Mar 24 '10 at 14:10
  • I upvoted you due to your update! sorry it didn't come sooner, I happened upon this question again during a google search – onaclov2000 Feb 17 '11 at 15:33
  • I know this is an old post but when I try the `ct ls -l.....` I get an `unterminated regexp` at the last gsub right after `\` at the space – depperm Aug 15 '18 at 15:38
  • that should be `\\` – depperm Aug 15 '18 at 15:45
  • @VonC I don't have a working example of what he was trying to do – depperm Aug 15 '18 at 17:39
  • @depperm But you have a working example of what *you* are trying to do: please edit the answer to illustrate what is working for your case. – VonC Aug 15 '18 at 20:12
  • @VonC no i don't...I'm using the `ct ls -l....` line and it isn't working – depperm Aug 15 '18 at 20:23
  • @depperm OK. On which OS? With which shell? (Windows CMD, Linux bash?) And which version of ClearCase? – VonC Aug 15 '18 at 20:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/178097/discussion-between-depperm-and-vonc). – depperm Aug 15 '18 at 20:48
3

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.

Community
  • 1
  • 1
jeff
  • 31
  • 1
  • I took the liberty to expand on your initial link. StackOverflow is a Q&A site which aims at including as much information as possible in each answer, in order to limit its dependency to external sources (like this link which could expire/be changed at any time). +1 btw. – VonC Jan 20 '11 at 11:29