@echo off

rem ***************************************************************************
rem * Use this cmd file to pin an entire VSS tree recursively to a specific   *
rem * label.                                                                  *
rem *                                                                         *
rem * Should be called from a clean directory, but that is not a requirement. *
rem *                                                                         *
rem * Parameters:                                                             *
rem *                                                                         *
rem *    %1 - VSS project root to start pinning at                            *
rem *    %2 - VSS label to pin to (must exist prior to call this cmd file)    *
rem *                                                                         *
rem ***************************************************************************

rem ***************************************************************************
rem * Validate parameters                                                     *
rem ***************************************************************************
if (%1)==() goto :Usage
if (%2)==() goto :Usage

@echo.
@echo Pinning project %1 to label %2 ...

rem ***************************************************************************
rem * Create a text file containing all of the project names in it            *
rem ***************************************************************************
@echo.
@echo Creating project listing ...
@echo on
ss get %1 -i- -r -g- -o@projs.txt
@echo off

rem ***************************************************************************
rem * NOTE: The output file from the above operation looks something like:    *
rem *                                                                         *
rem *          $/proj1/proj11/proj12:                                         *
rem *          file1                                                          *
rem *          file2                                                          *
rem *          ...                                                            *
rem *          $/proj2/proj21/proj22:                                         *
rem *          ...                                                            *
rem *                                                                         *
rem *       So, you'll need to use findstr to grep out the strings that       *
rem *       end with a ':', and then strip off the ':'.                       *
rem ***************************************************************************

rem ***************************************************************************
rem * Now loop through the project names, and call ss pin                     *
rem ***************************************************************************
@echo.
@echo Pinning files...
@echo on
for /f "delims=:" %%i in ('findstr /e : projs.txt') do ss pin %%i/*.* -g- -vl%2
@echo off

@echo.
@echo Done!

goto :Done

:Usage
@echo Recursively pins VSS project to specific label.
@echo.
@echo %0 proj label
@echo.
@echo    proj    VSS project to start pinning recursively at
@echo    label   Label previously applied to project to pin files at
@echo.

:Done
