Moshe Goren asked this question · 61 karma · Sep 01 '11 at 08:26 AM
How can I automaitcally create a patch review for a certain changelist in perforce, including newly added files?
You can use these DOS scripts I wrote.
The solution is comprised of a main script and a helper script. The main script receives the changelist number and calls the second script to handle newly added files.
You can call the first script anything you like but the second script has to be called CreateNewPatch.bat (or you can change the relevant line in the first script).
Any comments are welcome.
Script 1 (main script):
REM Create date and time tokens to use in the output patch file name
REM time will be HHMM
REM date will be the month date and year all together depending on your locality settings.
REM you might need to change the script to handle a long date format if thats what your
REM system shows when echoing %date%
FOR /F "delims=:. tokens=1-2" %%A IN ("%time%") DO set now=%%A%%B
FOR /F "delims=/ tokens=1-3" %%A IN ("%date%") DO set today=%%A%%B%%C
REM The outputted patch file will be called: patch_#(changelist number)_(date)_(time).txt
REM You can change the output file format to your liking
REM Make sure we don't add files to a previous patch
IF EXIST %patchname% del %patchname%
REM For each file that is opened we either call the helper batch file for added files or the 'P4 diff' for edited files
set command=p4 opened -c %1
set command2=FOR /f "usebackq delims=# tokens=1-2" %%I IN (`%command%`) DO FOR /f "tokens=3" %%A IN ("%%J") DO IF %%A==add (call CreateNewPatch %%I %patchname%) ELSE (p4 diff -dcu "%%I")
%command2% >> %patchname%
Script no. 2 (the helper script):
REM Find local filename using the current directory (depot root path) as the base
FOR /F "tokens=2* delims=/" %%A in ("%1") do set localFileNameBase=%cd%\%%A\%%B
REM Change front slashes to back slashes in local file name
REM Count the number of lines in the file
set /a lines=0
FOR /F "usebackq tokens=1* delims=" %%A IN (`findstr /R /N "^" "%localFileName%"`) DO set /a lines+=1
REM Output the file in unified diff format into the patch file (given as parameter 2)
@echo ==== %1#1 - %localFileName% ====>>%2
@echo @@ -1,0 +1,%lines% @@>>%2
FOR /F "usebackq tokens=1,2* delims=:" %%A IN (`findstr /R /N "^" "%localFileName%"`) DO @echo +%%B %%C>>%2