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

purpose

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

platform

any command line perforce with gnu tools available

introduction

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 Person.java 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

output:
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 }'
output:
9991
9995

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 Person.java

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



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

No comments:

Post a Comment