I noticed that when doing code view, people here in my company usually just give the branch in which his work is done, and nothing else. So I guess there must be a easy way to find out all the files that has a version in the given branch which is the same thing to find all the files
that has been changed.
Yes, I don't know the expected "easy way" to find files in certain branch, so need your help and thanks in advance.
You can quickly list all files from a particular branch:
cleartool find . -type f -branch "brtype(abranch)" -print
I would recommend combining that with:
-user to limit to a particular user, in case several users use the same branch.
cleartool find . -type f -branch "brtype(abranch)" -user aloginname -print
-created_since filter, to find all elements created since a certain date, in case their is incremental review for a work done on the same branch.
cleartool find . -type f -branch "brtype(abranch)" -element "{created_since(10-Jan)}" -user aloginname -print
Here is a python script that does the trick. It may look a lot more complicated but it's copy paste and go. Feel free to swap out the cmd with VonC's.
import subprocess
import os
import sys
from optparse import OptionParser
def pipeCmd(Cmd):
pipe = subprocess.Popen(Cmd,
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE )
(stdout_data,stderr_data) = pipe.communicate()
return (pipe,stdout_data,stderr_data)
def main(br_name):
cmd = "cleartool find -vis -avobs -element 'brtype(" + br_name + ")' -exec 'cleartool describe -short $CLEARCASE_PN'"
pipe,data,err = pipeCmd(cmd)
if 0 == pipe.returncode:
print data
else:
print err
# Process cmd arguments
if (1):
if (len(sys.argv) <= 1):
print "Finds all branches in your view."
print "\nExamples:\n"\
"allBranches.py -b $BRANCH_NAME \n"\
"allBranches.py --branch=$BRANCH_NAME\n"
parser = OptionParser()
branchName = "Example: 'rs__BRANCH_NAME_int'"
parser.add_option("-b", "--branch", dest="BRANCH_NAME", help=branchName, metavar="BRANCH_NAME")
(options, args) = parser.parse_args()
if (options.BRANCH_NAME):
print "\nFinding " + options.BRANCH_NAME + " elements...\n"
main(options.BRANCH_NAME)
sys.exit(0)
Related
I would like to describe all batch AND executable files with a cleartool command.
I can do this for one type of file :
cleartool find "Z:\PATH" -name *.bat -exec "cleartool describe %%CLEARCASE_PN%%"
But I can't find any way to do it for both types of files.
I could duplicate the line, but this is not a good solution because of poor performance.
I have tried surrounding with single or double quotes, with pipe or double pipe, but nothing works (-name "*.bat, .exe", -name (.bat || *.exe), etc.). Is there any solution ?
Thanks
The easiest way is to find all files, and test in the exec directive if the extension if the one expected:
cleartool find "Z:\PATH" -type f -exec "myscript %%CLEARCASE_PN%%"
With myscript a script written in the language of your choice, testing the file extension and calling cleartool describe if that extension matches.
Note the -type f, to limit the search for the files only (not the folders).
For instance, in Perl (and calling cleartool from Perl):
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use File::Basename;
$file=$ARGV[0];
my ($dir, $name, $ext) = fileparse($file, #exts);
if ($file ~= /bat|exe) {
system("cleartool describe $file");
}
I am a new user to Clearcase/CCRC :
I want to learn using cleartool commands in windows platform for CCRC.
I have created a snapshot view using CCRC.
I want to search for a first occurence of a string in a file (in all the branches) using cleartool command.
For eg :
If a func name XXXX is introduced in File Y at version 10, then i want the command which will search for the function XXXX (in file Y) from base version till the version the function is introduced and should output me as version 10.
Please help me to do this.
Once your snapshot view is loaded, you don't need a cleartool command.
You can use a simple grep command in order to search within the files.
A cleartool find command would be useful to search for a string within the message comment of a version of a file, not for the file content itself. See those examples
UNIX/Linux:
cleartool find -all -ver "! lbtype(<non-existing label>)" -exec 'cleartool
desc -fmt "Version: %n\tComment: %c\n\n" $CLEARCASE_XPN' | grep <the string
you are looking for>
Windows:
cleartool find -all -ver "! lbtype(<non-existing label>)" -exec "cleartool
desc -fmt \"Version: %n\tComment: %c\n\n\" %CLEARCASE_XPN%" | findstr "<the
string you are looking for>"
For a given file, you can list all versions with fmt_ccase:
cleartool find -name "yourfile" -exec "cleartool desc -fmt \"%Ln\" \"%CLEARCASE_XPN%\" && cleartool diff -pred \"%CLEARCASE_XPN%\"|grep XXXX"
(note: on Windows, you can use grep with GoW: Gnu on Windows)
The idea is to list all versions for a given file, and for each:
print the version (cleartool desc -fmt "%Ln")
diff with the previous version and grep for XXXX
I'm trying to search all files in a given branch for a specific string. So far I have
cleartool find . -branch 'brtype(<branch-name>)' -print
This gets all the files in the current directory for branch name "branch-name".
But I want to be able to search/grep those files.
How would yo do this?
You can use an -exec directive of the command cleartool find in order to chain a grep command:
# Windows syntax
cleartool find . -type f -branch 'brtype(MyBranch)' -exec "grep aSpecificString \"%CLEARCASE_PN%\""
# Unix syntax
cleartool find . -type f -branch 'brtype(MyBranch)' -exec 'grep aSpecificString "$CLEARCASE_PN"'
Note the -type f, to limit the search to files (not directories).
Note also that you will get the same file multiple times, if there are several versions of that file in the branch MyBranch.
To limit to one file result per branch, replace -branch by -ele (for 'element')
(as I illustrated in "How to find the files modified under a clearcase branch"):
# Unix syntax
cleartool find . -type f -ele 'brtype(MyBranch)' -exec 'grep aSpecificString "$CLEARCASE_PN"'
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.
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
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.
You can do this directly without having to pipe:
cleartool find . -ver "lbtype(LBL_A) && !lbtype(LBL_B)" -print
hlovdal's answer illustrates that, in this case, you have to find more elements than you need, and then filter them (despite all the ClearCase find features).
Note:
cleartool find . -type f -element 'lbtype_sub(LBL_A)' -print
could give you directly the elements (and not the version which may not be interesting in this case). You can find the version with -version and a format directive as explained below.
With the help of fmt_ccase, you can tailor the output to get precisely what your perl script will need to go on:
cleartool find . -type f -element 'lbtype_sub(LBL_A)' -exec 'cleartool describe -fmt "%En %Cl\n" \"$CLEARCASE_XPN\"' | grep -v ","
-fmt "%En %l\n" will display the full path of the element (instead of the version: /a/b/myFile##/main/myVersion) => /a/b/myFile'. the '\n` ensure one result per line.
-version and -fmt "%n %l\n" would display the version
\"$CLEARCASE_XPN\": the double quotes arount the extended path of the version found ensure a file with spaces in its name will still work.
grep -v ",": if there is any comma, that means "more than one label"
%Cl: avoid displaying the all list of labels. Anyway, if there are more than one, you are not interested!
So, for finding the exact version:
cleartool find . -type f -version 'lbtype_sub(LBL_A)' -exec 'cleartool describe -fmt "%n %Cl\n" \"$CLEARCASE_XPN\"' | grep -v ","|awk '{sub(/ \(.*/,"");print}'
Note:
The above works with unix syntax. The windows syntax would be:
cleartool find . -type f -element "lbtype(LBL_A)" -exec "cleartool describe -fmt \"%n %Cl\n\" \"%CLEARCASE_XPN%\"" | grep -v "," | gawk "{gsub(/ \(.*,"");print}"
, which would list the version of files with only one (correct) label.
awk '{sub(/ \(.*/,"");print}' will transform "myFile##/main/myVersion (LBL_A)" into "myFile##/main/myVersion"