cleartool question - clearcase

Lets say I have a directory at \testfolder, and the latest is currently at /main/10. I know that the operation resulting in testfolder##/main/6 is to remove a file named test.txt.
What's a sequence of cleartool operations that can be done in a script that will take "testfolder##/main/6" and "test.txt" as input, and will cat out the contents of test.txt as of that time?
One way I can think of is to get the time of /main/6 operation, create a view with config spec -time set to that time, and then cat the test.txt at the directory. But I'm wondering if I can do this in a easier way that doesn't involve manipulating config specs, perhaps through "cleartool find" and extended path names

If you are using a dynamic view, you should be explore directly the extended pathnames of testfolder in order to access the content of test.txt.
cd m:\myview\myVob\path\to\testfolder
# In version 5 of testfolder, test.txt was still there
cd ##/main/5
# Note: test.txt is a directory! only LATEST is a file
type test.txt#/main/LATEST
The OP adds:
how about if test.txt was moved from testFolder to testFolder2, and then a new version of test.txt is checked in? In this when I go into testfolder##/main/5, test.txt##/main/LATEST is incorrect...
Technically, this is a case of evil twins: 2 objects of the same names exists (one in testfolder##/main/5, one in testfolder##/main/10) with different history.
You need, to get back the former test.txt (a like rollbacking a file), remove your current test.txt and get back the old one currently moved to Folder2. (cleartool move)
cd testFolder2
cleartool checkout -c "move test.txt back to testFolder"
cd ../testFolder
cleartool checkout -c "get back test.txt from testFolder2"
cleartool rmname test.txt
cleartool move ../testFolder2/test.txt
cleartool ci -nc .
cleartool ci -nc ../testFolder2

Related

What is the Cleartool command to undo check out if it is identical?

I checkout a powershell file and signing it if it is not signed already then check-in back.
But my check-in fails as saying identical to predecessor. What is the cleartool command to undo checkout if it is identical to previous version?
You can simply try:
cleartool unco
That is "undo checkout"
Now you cannot do that in the checkin command itself.
What you can do is a cleartool diff: if there is no difference detected, then you unco, if there are, you check in.
You have that approach detailed in this thread:
You may need to diff against the previous version, but you can use something like diff <file> <file>##/main/branch/version, and if different (or whatever that diff returns if they are different), then allow the checkin to succeed). Otherwise maybe unco -rm the file.
Or:
In our makefile we have a section that basically follows the following format for each file:
call checkin_if_changed.bat "dir1\sub\file.h"
The contents of the file "checkin_if_changed.bat" are as follows:
cleartool diff -pre -dif %1
echo File: %1 diff result: %ERRORLEVEL%
goto diff%ERRORLEVEL%
:diff1
cleartool ci -c "Build box build." %1
goto end
:diff0
cleartool unco -rm %1
:end
Basically we do a cleartool diff against the prev version of the file.
If the cleartool diff returns a 0 it means the files are identical, so we do an unco -rm.
If cleartool diff finds a difference it returns a 1, meaning the files are different, and we check it in.
Or:
I've used the somewhat messy:
cleartool lsco -cvi -avo -fmt "ci -nc '%n'\nunco -rm '%n'" | cleartool
If the file is identical (and fails the checkin), then it unchecks it
out.
If it isn't identical, it checks it in, then the unco command
fails (since it's not checked out) with an error (but continues).
You can dump all of the output to a log file if you don't want to see it on
the command line. You can probably refine that if you need to.
If you have a post checkin trigger that forces you to enter a comment, then
change the -nc to -c 'some comment' instead.

Trying to undo a cleartool rm

I was trying to migrate a file from directory A to directory B in a branch, call it file.txt. What I did was:
cd A
cp file.txt ../B/
ct rm A
cd ../B
ct mkelem -ci -nc file.txt
Thereby losing all the history. I am trying to recover from this to do what I should have done which is simply ct mv file.txt ../B
I read that for this I should do something like this:
cd A
ct ln .##/main/?/file.txt ./file.txt
where luckily, from another view, I've figured out ? should be 27. Unfortunately when I try to do the above I get:
cleartool: Error: Entry named "file.txt" already exists.
cleartool: Error: Unable to create link: "./file.txt".
and I try to do:
ct rmelem file.txt
but got:
cleartool: Error: Element "file.txt" has branches not created by user
though presumably that's not what I should be doing anyway. How do I get back that file? It was simply a ct rm. I even get the entry already exists error if I do ct rm on the new copy file I added to directory B..
You are on the right track, but I would recommend a simple rmname, instead of a rmelem (which deletes the element with all its versions, branches and such).
That would remove file.txt from the latest version of the parent directory, and allows you to proceed with the symlink.
Next time, a cleartool mv might be easier, and keep the history of the file being moved.

symlink-copying a directory hierarchy

What's the simplest way on Linux to "copy" a directory hierarchy so that a new hierarchy of directories are created while all "files" are just symlinks pointing back to the actual files on the source hierarchy?
cp -s does not work recursively.
I just did a quick test on a linux box and cp -sR /orig /dest does exactly what you described: creates a directory hierarchy with symlinks for non-directories back to the original.
cp -as /root/absolute/path/name dest_dir
will do what you want. Note that the source name must be an absolute path, it cannot be relative. Else, you'll get this error: "xyz-file: can make relative symbolic links only in current directory."
Also, be careful as to what you're copying: if dest_dir already exists, you'll have to do something like:
cp -as /root/absolute/path/name/* dest_dir/
cp -as /root/absolute/path/name/.* dest_dir/
Starting from above the original & new directories, I think this pair of find(1) commands will do what you need:
find original -type d -exec mkdir new/{} \;
find original -type f -exec ln -s {} new/{} \;
The first instance sets up the directory structure by finding only directories in the original tree and recreating them in the new tree. The second creates the symlinks to the original files in the new tree.
There's also the "lndir" utility (from X) which does such a thing; I found it mentioned here: Debian Bug report #301030: can we move lndir to coreutils or debianutils? , and I'm now happily using it.
I googled around a little bit and found a command called lns, available from here.
If you feel like getting your hands dirty
Here is a trick that will automatically create the destination folder, subfolders and symlink all files recursively.
In the folder where the files you want to symlink and sub folders are:
create a file shell.sh:
nano shell.sh
copy and paste this charmer:
#!/bin/bash
export DESTINATION=/your/destination/folder/
export TARGET=/your/target/folder/
find . -type d -print0 | xargs -0 bash -c 'for DIR in "$#";
do
echo "${DESTINATION}${DIR}"
mkdir -p "${DESTINATION}${DIR}"
done' -
find . -type f -print0 | xargs -0 bash -c 'for file in "$#";
do
ln -s "${TARGET}${file}" "${DESTINATION}${file}"
done' -
save the file ctrl+O
close the file ctrl+X
Make your script executable chmod 777 shell.sh
Run your script ./shell.sh
Happy hacking!
I know the question was regarding shell, but since you can call perl from shell, I wrote a tool to do something very similar to this, and posted it on perlmonks a few years ago. In my case, I generally wanted directories to remain links until I decide otherwise. It'd be a fairly trivial change to do this automatically and recursively.

Recursive checkin using Clearcase

I want to check in a directory and all the sub-directories into the clear case.
Is there a specific command to achieve it?
Currently I am going into each directory and manually checking in each file.
I would recommend this question:
Now the problem is to checkin everything that has changed.
It is problematic since often not everything has changed, and ClearCase will trigger an error message when trying to check in an identical file. Meaning you will need 2 commands:
ct lsco -r -cvi -fmt "ci -nc \"%n\"\n" | ct
ct lsco -r -cvi -fmt "unco -rm %n\n" | ct
(with 'ct being 'cleartool' : type 'doskey ct=cleartool $*' on Windows to set that alias)
But if by "checkin" you mean:
"enter into source control for the first time"
"updating a large number of files which may have changed on an existing versionned directory"
I would recommend creating a dynamic view and clearfsimport your snapshot tree (with the new files) in the dynamic view.
See this question or this question.
the clearfsimport script is better equipped to import multiple times the same set of files, and automatically:
add new files,
make new version of existing files previously imported (but modified in the source set of files re-imported)
remove files already imported but no longer present in the source set of files.
make a clear log of all operations made during the import process.
:
clearfsimport -preview -rec -nset c:\sourceDir\* m:\MyView\MyVob\MyDestinationDirectory
did you used -recurse option in the clearfsimport command.
Example: clearfsimport -recurse source_dir .
This should help.
If you're using the Windows client, right-click on the parent folder, select Search, leave the file name field empty, click Search, select all the files in the result window (ctrl-A), right-click on them and select ClearCase -> Add to Source Control
If you are in windows you may try,
for /f "usebackq" %i in (`cleartool lsco -cview -me -r -s`) do cleartool ci -nc %i

In ClearCase, how can I view old version of a file in a static view, from the command line?

In a static view, how can I view an old version of a file?
Given an empty file (called empty in this example) I can subvert diff to show me the old version:
% cleartool diff -ser empty File##/main/28
This feels like a pretty ugly hack. Have I missed a more basic command? Is there a neater way to do this?
(I don't want to edit the config spec - that's pretty tedious, and I'm trying to look at a bunch of old versions.)
Clarification: I want to send the version of the file to stdout, so I can use it with the rest of Unix (grep, sed, and so on.) If you found this question because you're looking for a way to save a version of an element to a file, see Brian's answer.
I'm trying to look at a bunch of old versions
I am not sure if you are speaking about "a bunch of old versions" of one file, "a bunch of old versions" from several files.
To visualize several old versions of one file, the simplest mean is to display its version tree (ct lsvtree -graph File), and then select a version, right-click on it and 'Send To' an editor which accepts multiple files (like Notepad++). In a few click you will have a view of those old versions.
Note: you must have CC6.0 or 7.0.1 IFix01 (7.0.0 and 7.0.1 fail to 'sent to' a file with the following error message "Access to unnamed file was denied")
But to visualize several old versions of different files, I would recommend a dynamic view and editing the config spec of that view (and not the snapshot view you are currently working with), in order to quickly select all those old files (hopefully through a simple select rule like 'element * aLabel')
[From the comments:]
what's the idiomatic way to "cat" an earlier revision of a file?
The idiomatic way is through a dynamic view (that you configure with the exact same config spec than your existing snapshot view).
You can then browse (as in 'change directory to') the various extended paths of a file.
If you want to cat all versions of a branch of a file, you go in:
cd /view/MyView/vobs/myVobs/myPath/myFile##/main/[...]/maBranch
cat 1
cat 2
...
cat x
'1', '2', ... 'x' being the version 1, 2, ... x of your file within that branch.
For a snapshot view, the extended path is not accessible, so your "hack" is the way to go.
However, 2 remarks here:
to quickly display all previous revisions of a snapshot file in a given branch, you can type:
(one line version for copy-paste, Unix syntax:)
cleartool find addon.xml -ver 'brtype(aBranch) && !version(.../aBranch/LATEST) && ! version(.../aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'
(multi-line version for readability:)
cleartool find addon.xml -ver 'brtype(aBranch) &&
!version(.../aBranch/LATEST) &&
! version(.../aBranch/0)'
-exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'
you can quickly have an output a little nicer with
(one line version for copy-paste, Unix syntax:)
cleartool find addon.xml -ver 'brtype(aBranch) && !version(.../aBranch/LATEST) && ! version(.../aBranch/0)' -exec 'cleartool diff -ser empty "$CLEARCASE_XPN"' | ccperl -nle '$a=$_; $b = $a; $b =~ s/^>+\s(?:file\s+\d+:\s+)?//g;print $b if $a =~/^>/'
(multi-line version for readability:)
cleartool find addon.xml -ver 'brtype(aBranch) &&
!version(.../aBranch/LATEST) &&
! version(.../aBranch/0)'
-exec 'cleartool diff -ser empty "$CLEARCASE_XPN"'
| ccperl -nle '$a=$_; $b = $a;
$b =~ s/^>+\s(?:file\s+\d+:\s+)?//g;
print $b if $a =~/^>/'
That way, the output is nicer.
The "cleartool get" command (man page) mentioned below by Brian don't do stdout:
The get command copies only file elements into a view.
On a UNIX or Linux system, copy /dev/hello_world/foo.c##/main/2 into the current directory.
cmd-context get –to foo.c.temp /dev/hello_world/foo.c##/main/2
On a Windows system, copy \dev\hello_world\foo.c##\main\2 into the C:\build directory.
cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c##\main\2
So maybe than, by piping the result to a cat (or type in windows), you can then do something with the output of said cat (type) command.
cmd-context get –to C:\build\foo.c.temp \dev\hello_world\foo.c##\main\2 | type C:\build\foo.c.temp
I know this is an old thread...but I couldn't let this thrashing go by unresolved....
Static views have a "ct get" command that does exactly what you are looking for.
cleartool get -to ~/foo File##/main/28
will save this version of the file in ~/foo.
[ Rewritten based on the first comment ]
All files in Clearcase, including versions, are available in the virtual directory structure. I don't have a lot of familiarity with static views, but I believe they still go through a virtual fs; they just get updated differently.
In that case, you can just do:
cat File##/main/28
It can get ugly if you also have to find the right version of a directory that contained that file element. We have a PERL script at work that uses this approach to analyze historical changes made to files, and we quickly ran out of command-line space on Windows to actually run the commands!
If File is a Clearcase element, and cat File works, and the view is set correctly, then try:
cat File##/main/28
(note: without the ct shell-- you shouldn't need this if you're already in the view.)
Try typing:
ct ls -l File
If it shows the file with an extended name similar to the above, then you should be able to cat the file using an extended name.
ct shell cat File##version

Resources