Syncing missing/modified files to a specific version in Perforce

I think this is the 5th time I've had to figure this out in the past few years, so this time I'm going to preserve it here for posterity :)

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:\temp\foo.dat@SOME_LABEL will not work, but c:\temp\foo.dat#999 will. Fortunately we can use the pseudo revision 'have' for our purposes.

@echo off

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!

Comments [0]

I should just get this now for when the day comes...

Posted from San Francisco, CA

Comments [0]

Media companies STILL don't get the internet?

Last night Liz and I discovered that for some reason the first episode of the new Bing Bang Theory, our premium "watch together" show, hadn't been recorded. No problem, we just flicked on AppleTV, went to the TV section and.... couldn't find it anywhere.

Infact there was no sign of season two either, just season one. Very odd. (next-day googling reveals that Warner Bros are withholding it from online distribution to try and increase the value of the show for syndication).

This of course led to a small dilemma. Missed show, no scheduled repeats, no way to buy it online or watch it in Hulu/CBS.com. Hmm. In this day and age do content providers REALLY think people will wait for the repeats/syndication/dvd? I mean really?

No of course not. Instead they* head over to somewhere like The Pirate Bay or the other zillion torrent sites and grab the episode for free. The content owners lose out on the money people were willing to pay (or advertisements to watch), and viewers have to go through a bit of hassle to obtain a copy of variable quality (although one that's almost always better than SDTV).

Nobody wins, aside from the torrent sites with all the advertising. It's quite sad really.

*(by they I mean everyone else, and this is not at all what I did...)

Comments [0]

Just up the street from the Scumm bar...

Posted from San Francisco, CA

Comments [0]

Testing email..

Posted from San Francisco, CA

Comments [0]

Test from posterous..

Posted from San Francisco, CA

Comments [0]