Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClearCase: Find files having exactly one specific label and not more

I'd like to find files in ClearCase that are labeled with a specific label but that do not have any other labels set.

For example, if I have files labeled like this:

file1 LBL_A, LBL_B
file2 LBL_A

I'd like to have a query that gives me just file2 and not file1.

Is there a way to do this with cleartool find? If this is not possible to do with a single query, I'd also be happy for any ideas how to do this in several steps (I'll be calling cleartool from a perl script, so it will be easy to save lists of files temporarily and run further commands on them).

Thanks a lot in advance!

Jan

like image 494
Jan Avatar asked Jun 24 '09 10:06

Jan


2 Answers

Assuming LBL_A is the (only) label you want running

cleartool find /some/dir -version 'lbtype(LBL_A)' -print | xargs cleartool describe -fmt "%n: %l"

should give

file1: (LBL_A, LBL_B)
file2: (LBL_A)

as output which you then can check in your perl script or filter through sed -n 's/\(.*\): (LBL_A)/\1/p' (assuming no colons in filenames).

Update: As VonC correctly points out, the command above will fail for files with spaces in. To handle that run as:

cleartool find ... -print | tr '\012' '\000' | xargs -0 cleartool ....

which will translate newlines into ascii null and then have xargs use that as delimiter.

like image 129
hlovdal Avatar answered Oct 02 '22 21:10

hlovdal


You can do this directly without having to pipe:

cleartool find . -ver "lbtype(LBL_A) && !lbtype(LBL_B)" -print
like image 38
Garen Avatar answered Oct 02 '22 22:10

Garen