Finding a element version in ClearCase that exists in only certain versions of its parent directory - find

Here is the situation.
Let's say I have a file, "foo.cpp".
Its parent directory is /path/to/foo/ .
/vobs/myvob/path/to/foo##/main/release/1 DOES NOT contain foo.cpp
/vobs/myvob/path/to/foo##/main/release/2 DOES contain foo.cpp
/vobs/myvob/path/to/foo##/main/release/3 DOES NOT contain foo.cpp
So, foo.cpp exists only in:
/vobs/myvob/path/to/foo##/main/release/2/foo.cpp##/main/release/some-branch/{versions}
where {versions} are several versions of foo.cpp e.g. 1, 2, 3, LATEST.
My config spec is very generic, as my script needs to parse over hundreds of different branches in order to find certain versions of the files:
element * CHECKEDOUT
element * /main/release/LATEST
element * /main/LATEST
So clearly,
ct find . -name 'foo.cpp' -print
will not find foo.cpp on branch "some-branch".
I tried:
ct find . -a -nvi -name 'foo.cpp' -branch 'brtype(some-branch)' -print
ct find . -a -nvi -name 'foo.cpp' -print | grep some-branch
ct find . -a -nvi -name '*' | grep foo.cpp
None of these found foo.cpp.
Any ideas? Could my config spec be modified in any way to make this easier?

From "Additional examples of the cleartool find command":
The cleartool find command is used to locate ClearCase objects within a VOB, and is not restricted by the view's configuration specification (config spec).
Make sure to use a dynamic view.
ct find . -a -nvis -name 'foo.cpp' -ver 'brtype(some-branch)' -print
# or:
ct find . -nvis -name 'foo.cpp' -ver 'brtype(some-branch)' -print
The option -ver is mandatory in order to find and list versions.

If you are 100% sure that the file is in /vobs/myvob/path/to/foo##/main/release/2, you could modify your config spec to have
element * CHECKEDOUT
element /vobs/myvob/path/to/foo /main/release/2
element * /main/release/LATEST
element * /main/LATEST
Then, perform your search as described above. You will then not need -nvi option as you will be in a view that can see the object.
Taking into account you want a generic answer, I would then suggest the usage of the following command
cleartool find -all -name "foo.cpp" -version 'brtype(some-branch)' -print
Don't use -nvi option unless you want to list only the versions that are not visible in your view.

Related

Eclipse, Add all source file paths to an external tool as an argument

I would like to add an External Tool to my Eclipse CDT Project.
This external tool, which is a program that I have written myself, requires different arguments (the map file and a list of all *.c *.cpp and *.h files). I already managed to hand over the map file but is there any way of getting a list of all *.c and *.h files (maybe with an Eclipse Variable) so that I can directly add this to the argument field?
I found one solution which can be used on a linux system. Just use a a pipe with the following command and put it in a shell script.
First of all, how to find all source code files:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h'
Complete command:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs <myTool>
The first command will find out all absolute paths to the all .c .cpp and .h files listed in the rootfolder and the second one will convert its input into a set on arguments. The result will be the same as if every found file path would have been handed over as a single argument to mytool.

cleartool find difference recursive in certain file type to predecessor

In my script I'm calling ClearCase to check if any file of a certain file type in the current path (including all subfolders) has been changed. I'm not familiar with cleartool at all, the command should like this:
cleartool diff -predecessor -recursive *.filetype
As a return value I only need a bool: true if any differences exist, false if nothing has changed
As a return value I only need a bool: true if any differences exist, false if nothing has changed
You need a script. A simple find + exec won't be enough, because the exit status won't be exactly what you need.
#! /bin/bash
noChange=0 ### "cleartool diff" exit status means no difference
files=$(cleartool find . -name "*.filetype")
for f in ${file}; do;
cleartool diff -pre -options "-status_only" "${f}"
if [ $? != $noChange ]; then
exit 0
fi
done
exit 1
(0 is true, false is 1 in shell)
Note the use, in cleartool diff of the -options parameter:
opt/ions pass-through-opts
Specifies one or more compare method options that are not directly supported by diff.
That way, you get only the status from cleartool diff, which is precisely what you want to test in your case.
Since your previous question shows you have Git too, you can easily execute that script in a bash session, even on Windows.
On first glance, the command you're looking for is something like this:
cleartool find . -name "*.filetype" -exec 'cleartool diff -pred "$CLEARCASE_PN"'
On windows, it would look like this:
cleartool find . -name "*.filetype" -exec "cleartool diff -pred \"%CLEARCASE_PN%\""
The single quotes in the Unix example are significant since otherwise the "CLEARCASE_PN" environment variable reference would be expanded at the time you start the command and not when the -exec is actually fired.
The \"%CLEARCASE_PN%\" construct in the Windows command line and the "$CLEARCASE_PN" on unix is to account for filenames including spaces.
Now, looking at what you want... I'm not sure it would accomplish the underlying purpose, whatever that is.

ClearCase - How to Find All Checkins By One User for an Entire PVOB?

I have been asked to find every checkin by one specific user across an entire ClearCase Project VOB since a particular date. How might I obtain this information?
I assume it's some usage of the cleartool find command, but I've not yet figured out the syntax to get the information that I'm looking for.
I guess I'm looking for a "change set" across every activity of that user across every stream of a given PVOB since a particular date.
Looking at cleartool find (which work for versions created with or without UCM), it should be something like:
cleartool find . -user <auser> -version "{created_since(date1)}" -print
This is done within a vob, not a pvob, as it search for version (data), not UCM activities (metadata recorded on PVob level)
You need first to go to a view, preferably a dynamic view:
cd m:\aView\aVob
# unix
cd /view/aview/vobs/avob
As noted by the OP's answer, what works is:
using create_by instead of -user,
adding -all -nvis.
With the repeated help of (and huge thanks to) #VonC, here is what I wound up using, at a command prompt (not in a ClearTool session), with my working directory set to the directory just beneath the root of my snapshot view:
cleartool find . -all -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>
Update: The command below, which was originally my answer, returns only invisible files:
cleartool find . -all -nvisible -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>

How to clone a ClearCase label type?

Could we clone or copy a already existed ClearCase label type?
In past, we labeled our source code with name OLD_LABEL. Then we do a lot of branching and labeling.
X:\myvob1\code>cleartool lsvtree README
README##\main
README##\main\1 (DEV_LABEL2, DEV_LABEL1,OLD_LABEL,DEV_TEST...)
README##\main\dev_4.0
Now, could we clone the OLD_LABEL to a new one like NEW_LABEL instead of renaming the OLD_LABEL?
X:\myvob1\code>cleartool lsvtree README
README##\main
README##\main\1 (DEV_LABEL2, DEV_LABEL1,NEW_LABEL,OLD_LABEL,DEV_TEST...)
README##\main\dev_4.0
I tried the cleartool cptype but the NEW_LABEL does not appear.
I know that we can rename the OLD_LABEL to NEW_LABEL with cleartool rename. But we also want to keep the OLD_LABEL.
You can simply apply NEW_LABEL on all versions which have OLD_LABEL.
No need to clone.
A simple cleartool find is enough, using the query language
For visible files in a view:
cleartool find . -version 'lbtype(OLD_LABEL)' -exec 'cleartool mklabel NEW_LABEL "$CLEARCASE_XPN"'
For all files:
cleartool find -all -element 'lbtype_sub(OLD_LABEL)' -version 'lbtype(OLD_LABEL)' -exec 'cleartool mklabel NEW_LABEL "$CLEARCASE_XPN"'

How do I do a recursive find & replace within an SVN checkout?

How do I find and replace every occurrence of:
foo
with
bar
in every text file under the /my/test/dir/ directory tree (recursive find/replace).
BUT I want to be able to do it safely within an SVN checkout and not touch anything inside the .svn directories
Similar to this but now with the SVN restriction: Awk/Sed: How to do a recursive find/replace of a string?
There are several possiblities:
Using find:
Using find to create a list of all files, and then piping them to sed or the equivalent, as suggested in the answer you reference, is fairly straightforward, and only requires scanning through the files once.
You'd use one of the same answers as from the question you referenced, but adding -path '*/.svn' -prune -o after the find . in order to prune out the SVN directories. See this question for a discussion of using the prune option with find -- although note that they've got the pattern wrong. Thus, to print out all the files, you would use:
find . -path '*/.svn' -prune -o -type f -print
Then, you can pipe that into an xargs call or whatever to do the individual replacements, as suggested in the question you referenced. There is a lot of discussion there about different options, which I won't reproduce here, although I prefer the version from John Zwinck's answer:
find . -path '*/.svn' -prune -o -type f -exec sed -i 's/foo/bar/g' {} +
Using recursive grep:
If you have a system with GNU grep, you can use that to find the list of files as well. This is probably less efficient than find, but it does allow you to only call sed on the files that match, and I personally find the syntax a lot easier to remember (or figure out from manpages):
sed -i 's/foo/bar/g' `grep -l -R --exclude-dir='*/.svn' 'foo' .`
The -l option causes grep to only output the list of file names, rather than the matching lines.
Using a GUI editor:
Alternately, if you're using windows, do what I do -- get a copy of the NoteTab editor (available in a free version), and use its search-and-replace-on-disk command, which ignores hidden .svn directories automatically and just works.
Edit: Corrected find pattern to */.svn instead of .svn, added more details and some other possibilities. However, this depends on your platform and svn version: .svn without */ may be required in some cases, like on CentOS 7.
How about this?
grep -i "search_string" `find "*.some_extension"`
That is halfway solution to finding a search_string within files that have a specific extension....once you know the files that has the string, can be easily modified by piping it into sed....