Search code examples
perforcep4v

P4V How Clobber file during sync but only if it has not changed


I work with P4V/Perforce. Due to all of the automatic solutions to checking out files being just awfully slow my workflow looks like this: I Edit the file I want in visual studio, save it, VS automatically clears the read-only flag on the file. Then I Reconcile Offline Changes in P4V (if I remember to do so) and finally sync to latest/commit/whatever.

This works for 90% of the cases, the problem is any files that I edited, but then undone the change are not recognized by the Reconcile Offline Changes, so it never finds them, but they still have the "read-only" flag cleared, so the sync refuses to clobber them.

So here's my question: How do I make perforce clobber writeable files but only if the contents have changed, but without doing a full digest on all of the files?

Ideally here's how it'd work: During sync, for each file that it needs to update, it would first check if it has the read only flag, and if it does, it just updates that file. If the file is writeable only then does it do the digest, and if the digest is the same, it just updates that file, and if not, it just tells me there's files there it can't clobber.

Alternatively if the "reconcile offline changes" flagging up any file that has the read-only flag cleared but isn't checked out would also fix my issue.

But from the workspace and sync flags I've seen so far my only options are the "clobber" flag on the workspace, which would clobber ALL writeable files, potentially destroying my work, or using the "safe" sync which would force a digest on all updated files, which is horribly slow since I'm working on a pretty large repo with hundreds of people updating it. So my only current option is to just go through all the popups about unclobbered files, check them out each one by one, and then sync again.

Is this possible? Am I maybe just misunderstanding how the "clobber" or "safe" flags work? Is there some combination of flags capable of doing what I want?

Thanks for the help in advance!


Solution

  • The ideal fix IMO would be getting an IDE plugin that does a p4 edit on save rather than just unsetting the read-only bit -- that way you don't need to run p4 reconcile, and a p4 revert -a will take care of unmodified files. I use https://marketplace.visualstudio.com/items?itemName=callegustafsson.vscode-perforce-simple rather than the standard Perforce plugin; it doesn't have the performance problems of the more full-featured plugins because all it does is the p4 edit.

    Failing that, though, I suggest taking advantage of the fact that after a reconcile there should be no modified files in your workspace that aren't open for edit, which protects them from sync regardless of whether clobber is set. Given that at that particular moment clobber is perfectly safe (and is the exact behavior you want for your sync) you could put all this together in a simple script:

    p4 reconcile ...
    p4 client -o | sed s/noclobber/clobber/ | p4 client -i
    p4 sync ...
    p4 client -o | sed s/clobber/noclobber/ | p4 client -i
    

    and run that whenever you're ready to reconcile your "offline" changes (including writable-but-unmodified files) with Perforce.