Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perforce fast sync a directory to a clean state

Tags:

perforce

I want a fast solution that does not require force sync that will put a specified directory to its original repository state.

  • same files may be removed from disk
  • same files may be added from disk
  • some files may be modified on disk
  • some files may be marked for removal, addition or modification in perforce

All I want is to be sure that after if run the command I will have none of these.

p4 -f sync is not an option, I need a faster solution that does minimize networks usage.

Just in case someone asks, perforce proxy is out of discussion.

I do know that a partial solution is:

p4 diff -sd -se //clientspec/dir/... | p4 -x - revert

The problem is that this does not remove files added to the paths above that are not in perforce - files that I want to be removed from disk.

Also, I need a multi or cross platform solution - it has to work on Windows, OS X and Linux.

like image 944
sorin Avatar asked Sep 28 '10 16:09

sorin


2 Answers

Perforce has added a new command "p4 clean" in 2014.1 that does exactly what you are looking for, by resetting your workspace to its #have state:

  • New files not in Perforce will be deleted
  • Files modified outside of Perforce control will be reset
  • Files deleted outside of Perforce control will be restored

The command is an alias for "p4 reconcile -w" and uses the hashsum of the files to determine their state in your workspace.

like image 124
Sven Erik Knop Avatar answered Oct 13 '22 08:10

Sven Erik Knop


Another Unix/Linux snippet that should remove all files that have never been tracked by perforce:

find . -type f | p4 -x- files 2>&1 | sed -n -e 's/ - no such file(s).//p' | xargs -d '\n' rm

like image 25
rpetti Avatar answered Oct 13 '22 07:10

rpetti