@ECHO OFF
SET VERSION=1.0.5
:: Author: Tom Tyler <ttyler@perforce.com>
:: This EXPERIMENTAL script is intended to simplify the process of submitting a
:: large pending changelist as a single atomic commit. The intent is to reduce
:: the impact of a very large changelist by using shelving to incrementally
:: shelve files from the client to the server, and then execute the submit
:: using the 'submit -e' option to submit from the shelf directly on the P4D
:: server. This method reduces database locking times associated with
:: the submit operation, as the operation starts on the Helix Core server only
:: after all files have been transferred to it and eliminating long file
:: transfer times from the duration of locking.
::
:: LICENSE: See: https://swarm.workshop.perforce.com/projects/perforce-software-sdp/files/main/LICENSE
::
:: USAGE SYNOPSYS
::
:: Usage: chunk_shelve_submit.bat P4USER P4CLIENT PendingCL
::
:: EXAMPLE
::
:: Sample Usage:
::
:: chunk_shelve_submit.bat bruno bruno_ws 51252 > chunk.51252.log 2>&1
::
:: where:
:: * bruno is the current user
:: * bruno_ws is the current workspace
:: * 51252 is a pending changelist bruno would like submitted as an atomic change
::
:: When this script starts, the changelist must be a numbered pending changelist
:: with no files shelved. This script shelves each file, and then does a
:: 'revert -k' on each file as it is shelved. With '-k', the file is reverted but
:: contains remain what they were. So each shelved file is removed from the pending
:: changelist. After the last file is shelved, a 'p4 submit -e' is done
:: from the shelved changelist, creating new versions on the server. If this is
:: successful, a 'p4 flush @newCL,@newCL' is done at the end, to update the
:: workspace state.
::
:: LIMITATIONS:
::
:: This script does not consider exclusive locks.
::
:: If another user submits a file immediately after this change submits, there is a
:: window of opportunity for the flush at the to get the wrong version, confsuing
:: workspace state.
::
:: This is optimized for minimizing impact of a large commit on the server. It is
:: not optimized for making the submit operation as efficient as possible (as it
:: is coded in simple batch shell and the algorithm is simple).
::
:: INTEGRATIONS:
::
:: Thus can be configured as a Custom Tool in P4V.
:: See: https://www.perforce.com/manuals/p4v/Content/P4V/advanced_options.custom.html
IF %1x == x (
ECHO Usage: chunk_shelve_submit.bat P4USER P4CLIENT BigPendingCL
EXIT /B 0
) ELSE (
SET P4USER=%1
)
IF %2x == x (
ECHO Usage: chunk_shelve_submit.bat P4USER P4CLIENT BigPendingCL
EXIT /B 0
) ELSE (
SET P4CLIENT=%2
)
IF %3x == x (
ECHO Usage: chunk_shelve_submit.bat P4USER P4CLIENT BigPendingCL
EXIT /B 0
) ELSE (
SET BPCL=%3
)
GOTO START
:BAIL
EXIT /B 1
:START
ECHO Started chunk_shelve_submit.bat v%VERSION%
ECHO Pending CL: %BPCL%
SET TF1=%TEMP%\%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%%RANDOM%%RANDOM%
p4 -ztag -F %%depotFile%% opened -c %BPCL%>%TF1%
FOR /F %%F IN (%TF1%) DO (
p4 shelve -c %BPCL% %%F
IF ERRORLEVEL 0 (
p4 revert -k -c %BPCL% %%F
IF ERRORLEVEL 1 (
ECHO Aborting after failure to revert shelved file: %%F
GOTO BAIL
)
) ELSE (
ECHO Aborting after failure to shelve file: %%F
GOTO BAIL
)
)
p4 -s submit -e %BPCL%
FOR /F %%C IN ('p4 -ztag -F %%change%% changes -s submitted -u %P4USER% -c %P4CLIENT% -m 1') DO (
SET NEWCL=%%C
)
IF ERRORLEVEL 0 (
ECHO Submit completed. Updating workspace with: Running: p4 flush @%NEWCL%,@%NEWCL%
p4 flush @%NEWCL%,@%NEWCL%
) ELSE (
ECHO Aborting after failure to submit shelved CL %BPCL%.
GOTO BAIL
)