Emulating 'bzr | svn | hg' status in perforce.
Posted 2010-10-05 11:25:25 by .

I'd like to see a list of files I have not checked in using perforce. I would also like to exclude files from this. In other revision control systems I've used (bazaar, mercurial, subversion, git) they have a 'status' command. In bazaar I would do 'bzr st' and it would list files I haven't added. I could then edit .bzrignore to exclude specific files I wish to ignore.

There is no command line to do this easily using perforce's p4 command. After looking around I came across a partial answer to this on stackoverflow. I extended this after experimentation to filter the output. This then allowed me to come up with the following bash function I could use:

function p4st() {
   EXCLUDES=`cat ~/.p4ignore`
   find . -type f -print0 | xargs -0 p4 fstat >/dev/null 2> /tmp/o && \
   cat /tmp/o | awk "{print \$1}" | grep -vE "$EXCLUDES"
}

This uses the p4 fstat command and filters the error messages about unknown files. I then add a filter to this to exlude a list of file extensions I wish to ignore. My ~/.p4ignore contains a single line of regex file extensions:

\.pyc$|~$|\.tgz$|\.rpm$|*egg-info/*|\.pyo$

This solution is a bit ugly and I'd welcome a more elegant approach. It would be nice if I could add a .p4ignore to specific folders on disk.

Update:

 

 

References:

 

Comments

On 2010-11-30 17:00:38 Rob Collins () wrote:
Makes me glad I can use Mercurial instead of Perforce!

New Comment

Your email is never published nor shared.
Required fields are marked *
*
*