Juv
Juv

Reputation: 874

ClearCase can't merge from a snapshot view

I am using IBM Rational Clear Case, I have a snapshot view, with some checked-out files. This view is about to be obsolete, and I need these checked-out files to be merge to a new version (New view).

My problem: I am using ClearCase Version Tree Browser (clearvtree.exe) to do my merge. I opened the Version Tree for one of the checked-out files, on the view to which I want to merge the file. Now when ever I try to select the checked out file: right click -> and select "Merge to" I get the following error: "The selected version is not accessible from this view".

Note that when doing the same procedure on Dynamic View it works fine.

I know I can copy these files manually, but I am trying to find a way to do this, using the ClearCase tools (such as the Merge Tool and off-course the Version Tree).

Upvotes: 1

Views: 416

Answers (3)

Juv
Juv

Reputation: 874

OK, I have written a script (Actually two - which might be merged to one) that do what I need: To automatically merge from a snapshot view into a dynamic view. I assume it will also work with any other combination - but dynamic to dynamic or dynamic to snapshot is already supported by the IBM ClearCase "Merge Manager" tool.

First Scrip will find all checkouts and format them accordingly, while adding them to files.txt:

@echo off
REM ------------------------------- synopsis ----------------------------------
REM This script creates a list of all checked out into files.txt under the 
REM batch-file directory.
REM files in the following format:
REM \VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
REM \VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
REM \VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
REM ------------------------------- synopsis ----------------------------------

set source_view_path=C:\Snapshot\some-snapshot-john
set currentDirectory=%~dp0
set chekedOutOutputFile=%currentDirectory%find_co.txt
set resultFile=%currentDirectory%files.txt

@echo Getting checkouts of %source_view_path%
@echo %currentDirectory%

REM ---------------------------------------------------------------------------
REM The next code produces a find_co.txt intermediate file with the following 
REM format of checkouts:
REM <File Full Path>@@<Version ID>@@<File Comment>
REM    %n  - for file Name (With full path)
REM    %Vn - for file Version ID.
REM    %c  - for file Comment
REM
REM Example:
REM C:\MY_VIEW_PATH\VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
REM C:\MY_VIEW_PATH\VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
REM C:\MY_VIEW_PATH\VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
REM --------------------------------------------------------------------------- 
pushd %source_view_path%
cleartool lsco -cview -avobs -fmt "%%n@@%%Vn@@%%c" > "%chekedOutOutputFile%"
popd

del /q "%resultFile%"

REM ---------------------------------------------------------------------------
REM The following code formats the find_co.txt into files.txt with the desired 
REM result - <File VOB Path>@@<Version ID>@@<File Comment>
REM Example:
REM From -
REM C:\MY_VIEW_PATH\VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
REM C:\MY_VIEW_PATH\VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
REM C:\MY_VIEW_PATH\VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
REM To 
REM \VOB1\file1.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file1
REM \VOB2\file2.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file2
REM \VOB2\file3.txt@@\main\branch_v111\CHECKEDOUT@@Comment for file3
REM ---------------------------------------------------------------------------
for /F "usebackq tokens=*" %%A in ("%chekedOutOutputFile%") do (
    call ::removeSourceViewPath "%%%A"
)
goto endOfScript

REM ---------------------------------------------------------------------------
REM Manipulate the path of each file to exclude the view from it e.g:
REM C:\MY_VIEW_PATH\MY_VOB\file.txt -> \MY_VOB\file.txt
REM >>>-----------------> start of :removeSourceViewPath 
:removeSourceViewPath
    set str=%1
    call set "resultStr=%%str:%source_view_path%=%%"
    set resultStr=%resultStr:~1,-1%
    @echo %resultStr%
    @echo.%resultStr%>>"%resultFile%"
    exit /b

REM <<<-----------------< end of :removeSourceViewPath
REM ---------------------------------------------------------------------------

:endOfScript

pause
@echo ------------------------------------------------------------------

The second script takes the files.txt and merges them from a source view to a target view:

@echo off
REM ------------------------------- synopsis ----------------------------------
REM This script takes a list of all files from the files.txt which is under 
REM this batch-file directory and merges them from TARGET to SOURCES views
REM files in the following format:
REM <File VOB Path>@@<Version ID>@@<File Comment>
REM are merged from <SOURCE_VIEW>\<File VOB Path> to 
REM <TARGET_VIEW>\<File VOB Path> with the <File Comment> as comment.
REM ------------------------------- synopsis ----------------------------------
setlocal

set TARGET_VIEW=V:\v11-john-local-nt
set SOURCE_VIEW=C:\Snapshot\some-snapshot-john

REM ---------------------------------------------------------------------------
REM The following takes the line:
REM <File VOB Path>@@<Version ID>@@<File Comment> and checks out the target 
REM file, then it automatically merges the file from source to target.
REM Note that the version is not required here (it might be required if we
REM want to merged from a version which is not the latest one in the branch).
REM ---------------------------------------------------------------------------
for /f "tokens=1,2,3 delims=@@" %%i in (files.txt) do (
    cleartool co -unreserved -c "%%k" %TARGET_VIEW%%%i
    cleartool merge -to %TARGET_VIEW%%%i %SOURCE_VIEW%%%i 
)

endlocal

pause

Both of this scripts merged all the file I needed from the source View to the target View.

Notes:

  • You can create a batch file that get the SOURCE_VIEW and TARGET_VIEW in the command line as %1 and %2,
  • I splittend this into two scripts so I can remove some files from the list, before actually doing the merge.
  • The scripts will preserve the original comment of the file.
  • %~dp0 - This is how I can force working in the current batch file directory.
  • Feel free to comment. If you have a better solution I will be glad to move my V to yours :-)

Upvotes: 1

Brian Cowan
Brian Cowan

Reputation: 1073

The description seems to contradict itself. Are you in ONE snapshot view and attempting to merge FROM a checked out version in another one? That generally will not work for the reason @VonC mentioned. The ClearCase core doesn't officially "know" where the most recent snapshot view workspace is for that other view, so it can't access the view-private copy. This could also fail for a dynamic view depending on view permissions.

If you are trying to merge TO an arbitrary version FROM your checked out version, you should be getting "element already checked out in this view" (Or words to that effect) since only one version of an element can be checked out in a given view.

Upvotes: 0

VonC
VonC

Reputation: 1323573

Since it is a snapshot view, its checked out files are only accessible in the actual view path, not in its view storage (like a dynamic view)

If you have access to the snapshot view path, you can use clearfsimport in order to automatically import the modified/new files from said snapshot view to your current view.

See a clearfsimport example here.

Upvotes: 0

Related Questions