Here’s a fun little bit about Perforce that I discovered today.
Let’s say you “open” (a.k.a: check out) a file because you’re going to edit it. Now let’s say you’re suspecting that your tree is a little messed up so you move it aside and sync another copy of your “client” (a.k.a.: workspace). You don’t get any of your opened files. Now clearly Perforce is trying to be nice to you to prevent you from overwriting checked out files, because they could have changes and it doesn’t want to overwrite them. Of course you don’t even have the file so there is no danger of overwriting anything, but Perforce doesn’t know this as it trusts everything you tell it about which files are checked out and potentially changed, even though this information may not be consistent with what’s in your local files. If you do a sync or even a sync -f, Perforce will say your file is “up to date” and it will not emit any kind of warning or notice about the fact that the file is checked out and therefore will not be clobbered. Suckitude.
% ls -l LoginDialog.html ls: cannot access LoginDialog.html: No such file or directory % p4 sync File(s) up-to-date. % ls -l LoginDialog.html ls: cannot access LoginDialog.html: No such file or directory % p4 sync -f LoginDialog.html LoginDialog.html - file(s) up-to-date. % ls -l LoginDialog.html ls: cannot access LoginDialog.html: No such file or directory % p4 revert LoginDialog.html //depot/foo/bar/LoginDialog.html#1 - was edit, reverted % ls -l LoginDialog.html -r--r--r-- 1 mabramow None 1246 Oct 3 17:53 LoginDialog.html
Doing a p4 revert
is the way to get out of this situation. It’s bizarre to think of reverting something that isn’t there, but in the Perforce model it makes sense.
Perforce has a lot of surprising behaviors that all stem from the fact that it tries to keep track of the state of client workspaces on the server and therefore relies on you telling it everything that you’re doing with your files. This is good for performance but pretty bad for usability. If you start doing file management on your own and don’t keep it in the loop, things are going to get weird fast.
I opened a file with my editor, and then erased a line by doing a direct write of white pixels to the screen using a graphic-driver utility. My editor did not notice the change! I suppose for performance reasons the editor relies on my telling it everything I am doing to the window.