ClearCase: Copy old versions with Snapshot Views under Windows - clearcase

Using IBM Rational ClearCase:
- I have only access to Snapshot Views so NO dynamic Views
I want to copy ALL versions from a certain changeset to c:\temp. I have already listed the changeset versions in a file (couple of hundred of versions, I only need the latest one), I do not have a baseline over this older set.
What I now have and does not work:
#!/usr/bin/perl -w
#
# PROGRAM: copytest.pl
$filename = "Design test123.doc";
$view = "D:\\AdminViews\\ABC_R1_READ_2\\ABCD002\\ABC_DESIGN\\BLA Framework\\P0\\";
$version = "\\main\\ABC_R1_READ\\1";
$printhet = 'cleartool find . -name "' . $filename . '" -version version(' . $version. ') -exec "cmd /c copy %CLEARCASE_XPN% D:\temp\%CLEARCASE_PN%"';
system($printhet);
Basically because: http://www-01.ibm.com/support/docview.wss?uid=swg21150317 (XPN)
update: I read In ClearCase, how can I view old version of a file in a static view, from the command line? again and I see that a diff with an empty file is the /hack for having no XPN. ok... but a diff with empty and a doc in the above gives me "0"

I am not sure what this IBM article (you mention in your question) can mean in your situation since it only works for dynamic view (if the view does not directly select the version you need).
And my old answer for accessing an extended path file content in a snapshot view is not trivial to adapt here.
So why not aim at something equivalent but simpler?
Why not create another snapshot view directly within c:\temp (c:\temp\myview_snap), with a config spec along the lines of (you can keep '/' instead of '\'):
element * CHECKEDOUT
element "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework/P0/..." /main/ABC_R1_READ/1
element -directory "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework/P0/..." /main/ABC_R1_READ/LATEST
element -directory "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework/P0/..." /main/LATEST
element "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework/P0/..." -none
element /ABC_R1_READ_2/ABCD002 /main/ABC_R1_READ/1
element /ABC_R1_READ_2/ABCD002 /main/LATEST
element /ABC_R1_READ_2/ABCD002/ABC_DESIGN /main/ABC_R1_READ/1
element /ABC_R1_READ_2/ABCD002/ABC_DESIGN /main/LATEST
element "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework" /main/ABC_R1_READ/1
element "/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework" /main/LATEST
element * -none
load /ABC_R1_READ_2
That way, you should select:
any element under /ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework/P0 (P0 included) with the right version
any directory which had not the exact version will try first to load itself as the LATEST on ABC_R1_READ, else as /main/LATEST as fallback (always exists)
if an element (file) has not that version, it won't be selected at all and not loaded.
any parent element (/ABC_R1_READ_2/ABCD002/ABC_DESIGN/BLA Framework), if it has not the right version, will be selected as /main/LATEST (always exist)
any other element (outside of the relevant tree) will be ignored, non-selected
Just tested it: it works fine.
Notes:
"BLA Framework" is a directory with a space in it, so you need to add the double quotes where it is used.
the load rule can just load the vob ABC_R1_READ_2: since the '-none' rules will not select what you don't need, they won't be loaded anyway.

Related

How to set view element baseline from command line or script in UCM ClearCase?

How can I select an element with a specific baseline in a UCM ClearCase snapshot view config spec from a script?
I'm writing a script which will create a snapshot view of a given stream and should select a specific baseline version of the stream contents. I would prefer to set the element baseline in the same manner I'm setting the load rules but can't find a way to do that.
Here's what I'm doing so far:
...
cleartool mkview -snapshot -tag ${cc_view} -ptime -stream ${cc_stream}#\\myVob -vws ${cc_dir}/${cc_view}.vws ${cc_dir}/${cc_view} || die "Failed to create view. Exiting."
cd ${cc_dir}/${cc_view}
# Set the element baselines
cleartool edcs -overwrite
cleartool update -overwrite -add_loadrules ${components} || die "Failed to update view. Exiting."
...
Another issue might be that I can't set the element version in the config spec in the custom block - I have to do it in the component selection rules instead! Overwriting UCM's "Component selection rules" section feels a bit dangerous. I do this in the edcs phase:
ucm
identity UCM.Stream <...id...>
# ONLY EDIT THIS CONFIG SPEC IN THE INDICATED "CUSTOM" AREAS
# This config spec was automatically generated by the UCM stream
# "myStream" at 2017-06-01T07:43:33+02:00.
# Select checked out versions
element * CHECKEDOUT
# Component selection rules...
element "[ee5a<...id...>=\MYCOMPONENT]/..." my-component-1.0 -nocheckout
end ucm
#UCMCustomElemBegin - DO NOT REMOVE - ADD CUSTOM ELEMENT RULES AFTER THIS LINE
#UCMCustomElemEnd - DO NOT REMOVE - END CUSTOM ELEMENT RULES
# Non-included component backstop rule: no checkouts
element * /main/0 -ucm -nocheckout
#UCMCustomLoadBegin - DO NOT REMOVE - ADD CUSTOM LOAD RULES AFTER THIS LINE
load \MYCOMPONENT
Related questions:
UCM: How to create dynamic view (base clearcase) on arbitrary incremental baseline
Snapshot from old baseline
As VonC suggested I moved to base CC:
...
cleartool mkview -snapshot -tag ${cc_view} -ptime -vws ${cc_dir}/${cc_view}.vws ${cc_dir}/${cc_view} || die "Failed to create view. Exiting."
cd ${cc_dir}/${cc_view}
cat << EOF > config_spec
element * CHECKEDOUT
element * ${baseline} -nocheckout
element * /main/LATEST
EOF
cleartool setcs -force -overwrite config_spec || die "Failed to set config spec. Exiting."
cleartool update -overwrite -add_loadrules ${components} || die "Failed to update view. Exiting."
...
First, that will only work if the baseline is full.
If it is an incremental one, you have the risk of selecting an element with a label (associated to the baseline) which is not set on the parent folder, making that element inaccessible.
Second, that kind of custom selection is best done with a non-UCM base ClearCase snapshot view into which you have:
the same load rules as your UCM snapshot view
but a simpler set of selection rules:
element * yourBaselineId
element * /main/LATEST

text_file_delta failed create_version operation in clearcase

Continuing my previous post: Provide version to independent files in clearcase. Now I able to execute clear case import command but with some errors. Following are some errors occurred while import:
clearfsimport: Error: Could not checkin "E:\CC_Work\FromCC\santosh_view57\Temp_TEST\AspNET\Scripts\WebForms\MSAjax\MicrosoftAjax.js".
clearfsimport: Warning: Trouble importing element "E:\CC_Work\FromCC\santosh_view57\Temp_TEST\AspNET\Scripts\WebForms\MSAjax\MicrosoftAjax.js".
Creating element "E:\CC_Work\FromCC\santosh_view57\Temp_TEST\AspNET\Scripts\WebForms\MSAjax\MicrosoftAjaxApplicationServices.js".
Created branch "TEST_TEMP" from "E:\CC_Work\FromCC\santosh_view57\Temp_TEST\AspNET\Scripts\WebForms\MSAjax\MicrosoftAjaxApplicationServices.js" version "\main\0".
clearfsimport: Error: Type manager "text_file_delta" failed create_version operation.
Following is my import command:
clearfsimport -rec -nset -comment "Commit test" F:\abc\ASPNET* E:\CC_Work\FromCC\santosh_view57\Temp_TEST\ASPNET
And config spec is following:
element * CHECKEDOUT
element * .../TEST_TEMP/LATEST
element * /main/LATEST -mkbranch TEST_TEMP
element * /main/LATEST
load \Temp_TEST
Same file is able to check out and check in using "ClearCase Expoler" GUI.
You might need to change the type manager associated to js files, as their content could not always be compatible with what a text_file_delta manager expects.
See "Type manager text_file_delta failed create_version operation" for concrete examples.
This technote lists the limitations which makes a text file fail:
Type manager size limitation - File too large
Text files that contain binary data - Contains a '\000'
Line exceeding 8000 bytes
Corrupt source container - not the highest on its branch
I have seen issue with the first 3.
If you have to change its type, see this technote.

Clearcase error adding file

I cannot add a new file to the VOB. I tried both UI context menu on windows as well as cleartool command line utility.
cleartool> checkout .
Checkout comments for ".":
Created branch "BRANCH_NAME" from "." version "\main\BASE_BRANCH_NAME\1".
Checked out "." from version "\main\BASE_BRANCH_NAME\BRANCH_NAME\0".
cleartool> mkelem -ci -nc NewFile.h
Created element "NewFile.h" (type "text_file").
cleartool: Error: Unable to check out "NewFile.h".
cleartool> uncheckout .
describe -l . shows me that the folder has rwx permissions. What am I doing wrong? Why I can't add file?
As mentioned in this thread (and already commented):
You'll need a rule that selects /main/0 or /main/LATEST
/main/0 is the placeholder version created for any new element added to source control.
See for instance "how to create a branch in ClearCase" or "How best to branch in Clearcase?" for an example of a config spec allowing to add to source control in a branch.
element * CHECKEDOUT
element * .../aBranch/LATEST
element * STARTING_LABEL -mkbranch aBranch
# selection rule for new "added to source control" file
element * /main/0 -mkbranch aBranch
element * /main/LATEST

full clearcase history for gource

I have tried to get the full history of a clearcase vob to parse it and use it with gource to get a visual representation of the changes, but I do not find the right commands to get an easy log history to parse with clearcase2gource python script. I do not use UCM, there are no streams, just plain cleacase.
With this command I get elements with ## in the middle of a path:
cleartool lshistory -fmt "Element: %n| Date: %d| User:%u| Operation: %e| Object:%[type]p| SimpleType: %m| OperationKind: %o\n" -all /vobs/vob_name
With this command I get elements like this (deleted at some point):
Element: /vobs/vob_name/dir1##/main/branch_dev/2/dir2/main/branch_pilot/1/file##/main/branch_pilot/1| Date: 2008-04-15T16:58:28+02:00| User:reeasjp| Operation: create version| Object:compressed_file| SimpleType: version| OperationKind: checkin
That makes more difficult to parse for gource because of several branch names in the middle.
Is there any way to get a full history of all the elements with just plain directories and file names?
Thanks in advance.
NOTE: In the config Spec I have just "/main/LATEST".
The issues are:
clearcase2gource.py processed the extended paths (see "About the version-extended path") found by cleartool lshistory with some hard-coded assumptions.
e = d['Element']
splitElement = e.split("##")
d['FileName'] = splitElement[0]
d['StreamName'] = splitElement[1]
# StreamName starts with /main/ which we aren't interested in.
# Remove the /main/ (slice on 5 because there are 5 chars in /main/)
d['StreamName'] = d['StreamName'][5:]
the cleartool lshistory --all will list history of deleted elements (non-visible anymore in the current ClearCase view), hence the multiple branch names.
The easiest solution would be to:
redirect the cleartool lshistory output to a file, and
then filter out all the extended paths which don't conform to clearcase2gource.py expectation: for instance, just for testing, keep only the ones in a specific branch or in /main only, just to see if that works better.
finally feed that file as input to clearcase2gource.py

How to open a dynamic view in clear case with a given config spects using command prompt?

I have config spects for a view and I need to create a view in Clear Case using command prompt.
Please let me about the commands I can use with some example.
Thanks in Advance!
That would be using:
cleartool mkview
followed by cleartool setcs -tag yourDynView pname, with pname being "a text file whose contents are to become the view's new config spec".
For creating a dynamic view:
cleartool mkview -tag yourDynView \\shared\path\to\viewStorage\yourDynView.vws
That will create a dynamic view with a default config spec:
element * CHECKEDOUT
element * /main/LATEST
You will then be able to replace that config spec with any other config spec stored in a file, with the setcs command.

Resources