Monday, February 22, 2010

Stupid perforce trick #517


p4 fstat //depot/mycode/myfile.html | grep clientFile | awk '{print $3}'


Perforce command line often spits out filenames in the 'depot' format. You will need to translate these 'depot' names into local paths in order to work with the files in your favorite editors and GNU utilities.


p4 fstat

p4 fstat is a very useful command that can access all sorts of fun information about a file under perforce control. Do yourself a favour and look it up right now by typing
p4 help fstat
into your terminal. Then try out as many options as you can before screaming 'i hate perforce and what is so f@#$king wrong with SVN..' but i digress

the output of p4 fstat filename is something like this
... depotFile //depot/mycode/myfile.html
... clientFile /home/username/mycode/myfile.html
... isMapped 
... headAction integrate
... headType text
... headTime 1253307019
... headRev 2
... headChange 73363
... haveRev 2

grep clientFile

Filter out the line containing the filename on the local filesystem
... clientFile /home/username/mycode/myfile.html

awk '{print $3}'

print the 3rd field which contains the actual file name

Tuesday, February 9, 2010

Stupid Perforce Trick #87 - show my last 100 submits

the trick

command: p4 changes -u myusername | head -100 | awk '{print $2}' | p4 -x- describe


Perforce on the unix command line to search through last 100 changes you made


any command line perforce with gnu tools available


Every once in a while someone asks me what i did to some code a month ago. Okay maybe it's more like 'what did you screw up 10 minutes ago?!?!' If you're anything like me - once you commit your changes you forget all about the task and move on (note to self eclipse mylyn is a great enabler of this attitude)

The easy answer to the question 'what did you do to this code somewhere in the recent past' is to check the perforce history for your checkins. Pipe this to your trusty GNU tools and you can easily weed out all the crap and find exactly what you're looking for.

So lets say I remember my bug had something to do with the class. I want to review that changeset and make further modifications to some of the files.. i just don't remember what the changes were or what files were affected.

the command

step 1 - list changes

the following command gives you a printout of all the changes submitted to your perforce server

command: p4 changes

step 2 - list your changes only

You really just want to see your changes

command: p4 changes -u myusername

this gives you several rows of information that look like this

Change 9991 on '2010/01/01' by myusername@myclientname 'FIX horrible bug i am unsung hero'

Change 9995 on '2010/01/02' by myusername@myclientname 'oops fix 9991 again because i was drunk yesterday'

step 3 - extract only the changeset id from the output

We'll pull out just the changeset id so that we can investigate those changesets further

command: p4 changes -u myusername | awk '{ print $2 }'

step 4 - dig deeper into those changeset

take our list of changesets and ask perforce to describe each of those in detail
command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe

the final 'p4 -x- describe' means 'take stdin and perform the p4 command on it'

'cat blah.txt | p4 -x- describe' is equivalent to 'cat blah.txt | xargs -I {} p4 describe {}'

if that helps

the output of this command can be quite large. it contains the the files you have changed and the diffs of each changed file.

step 5 - use our favorite editor to search through the changes

Now you have an output stream that you can use with grep or less or whatever to find filenames and lines of code. Remember that i was looking for a change that had something to do with

command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe | grep -n

or my favorite
command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe | less

PGP key verification


Notes on how to check a PGP signature.


Ubuntu 8.x

note: gpg is the open version of pgp.. once you install pgp or gpg the commands will be the same.. use pgp and gpg interchangeably

install pgp

command: sudo apt-get install pgp

download your software and key

command: wget
command: wget

first pass at verifying

will probably fail because you don't have the signer's public key yet

command: pgp blah.tar.gz.asc

this will print out a message that you dont have the public key for some key id like
No signature found for AC487ADC

get the signers key from a store

gpg --keyserver --recv-key AC487ADC

second pass at verifying

command: pgp blah.tar.gz.asc

this should show that the binary blah.tar.gz was signed by the author

it might print some messages that nobody else trusts this signature because the author has not built a web of trust