The solutions I've seen (for example from IBM) aren't satisfactory since they perform the operation on every element, disregarding if they need merging or not. I want to have traceability so that only the files needed are merged, allowing me to easily find what changes have been done between merges.
Here's my solution, made as an MS-DOS batch. Note that it's currently only working for snapshot views, since this was one of my requirements. It should be easy to adapt for dynamic views as well (I might just do that in a "near future" myself).
:: Clear previous mergesetSome explanation needed: the %VERSION% is an input parameter holding the exact version merging from (e.g. /main/dev_branch/LATEST).
if exist %MERGESET% del /q %MERGESET%
::Automatically merge all directories
cleartool findmerge . -type d -fversion %VERSION% -merge -nc -log NUL
:: Find items eligible to merge, check these out and record them to file
echo Finding files to merge...
cleartool findmerge . -type f -fversion %VERSION% -log NUL -co -nc -exec "cmd /v:on /c echo !CLEARCASE_FXPN!;!CLEARCASE_PN! >>%MERGESET%"
:: Delete the target
echo Deleting targets...
for /f "tokens=2 delims=;" %%a in (%MERGESET%) do del /q "%%a"
:: Use cleartool get to copy contents from source
echo Copying from source to target...
for /f "tokens=1,2 delims=;" %%a in (%MERGESET%) do cleartool get -to "%%b" "%%a"
for /f "tokens=2 delims=;" %%a in (%MERGESET%) do attrib -R "%%a"
:: Create a merge arrow for the these items
echo Creating Merge arrows...
for /f "tokens=1,2 delims=;" %%a in (%MERGESET%) do cleartool mkhlink -unidir Merge "%%a" "%%b"
One "tough nut" for me was to find the /v:on-flag for calling cmd, in conjunction with the !-signs around environment variables. This is what makes them set at runtime, and not at time of calling the script (when it's empty).
No comments:
Post a Comment