The problem is usually one or more of:
- You have files missing from your workspace that need replaced.
- You have locally modified (i.e. not opened for edit) files that need replaced.
- These files are large in either size or number, and on a slow or remote server, so a complete force-sync is not an appealing option.
Normally this could easily be solved with something like p4 diff -sd/-se //depot/path/.. | p4 -x – sync -f, which finds all the missing/outdated files and then force-syncs them.
The problem with this approach comes when you need the files from a specific revision or label. While you can pass in a label/revision to ‘p4 diff’, the sync part will always retrieve the latest version of a file. To fix this we need to save the list of files we need to a temporary location, then postfix each line with the version we want, then feed that new list back to p4 sync.
But there’s one final catch. If your filenames are local paths instead of Perforce paths, you cannot specify a label, only revisions. E.g. c:tempfoo.dat@SOME_LABEL will not work, but c:tempfoo.dat#999 will. Fortunately we can use the pseudo revision ‘have’ for our purposes.
REM Could optionally pass these as %1 and %2 from the cmd line
set LABEL=@SOME_LABEL
set BASE_DIR=//depot/path/…
del p4sync.txt
echo Setting 'have' to %LABEL% for %BASE_DIR%
REM do a nop sync that sets our 'have' version to the label we want
p4 sync -k %BASE_DIR%%LABEL%
echo Finding modified files..
p4 diff -se %BASE_DIR%%LABEL% > p4diff.txt
echo Finding missing files..
p4 diff -sd %BASE_DIR%%LABEL% >> p4diff.txt
echo Building sync commands
REM Append #have to each filename and put them all in a list of files to sync
for /f %%i in (p4diff.txt) Do echo %%i#have>> p4sync.txt
REM Now sync everything
if exist p4sync.txt (
echo Syncing..
p4 -x p4sync.txt sync -f
)else (
echo It seems no files need updated!
)
Voila!
Hello,
I’ve read your very detailed answer to a guy in stackoverflow (http://stackoverflow.com/questions/664159) that asked about the game development industry.
I’m also interested in getting into the game development industry and I have a couple of follow up questions, I couldn’t find your email anywhere so I would be glad if you could contact me at zivpeleg.at.gmail com.
thx, Ziv
If you have followup questions then the best thing to do would be to post them as a new question on Stackoverflow and then send me the link. I’d be happy to answer them in a public forum where everyone can benefit.