This script (p4-whodunit.py) will analyze a perforce depot file to determine and report who changed each line of code. It is useful for tracking down recent changes that might have caused a problem. It is covered by the MIT license. You can download it here.
Acknowledgements
The script was inspired by a shell script developed by my colleague: Kris Kozminski to combine the “p4 describe
” and “p4 annotate
” commands.
Download and Install
Here is how you download and install the tool from the command line. Note that you must have “p4” in your path for it to work.
1 2 3 4 5 6 |
$ wget http://projects.joelinoff.com/p4tools/p4-whodunit.py # download $ chmod a+x p4-whodunit.py # make executable $ mv p4-whodunit.py /opt/local/bin # move to common area $ which p4-whodunit.py # test /opt/local/bin/p4-whodunit.py $ p4-whodunit.py -h # test |
You may need to change the first line of the script to make it work properly in your environment.
Running the Tool
You run the tool on a set of 1 or more perforce depot files. For each file it outputs information about each line of the file. Here is an example the shows two lines.
1 2 3 4 5 6 7 8 9 10 11 12 |
$ p4-whodunit.py //depot/dev/proj1/lib1/src/file1.cc . . 275 11547@bigbob | auto up1 = make_unique(Thing); - 11547@bigbob ... 363442@jlinoff - # ^ ^ ^ ^ ^ ^ ^ # | | | | | | +--- col 6 - source line # | | | | | +-------- col 5 -separator (|, -) # | | | | +------------------------- col 4 - who deleted it # | | | +----------------------------- col 3 - ellipses # | +------------------------------------------ col 2 - who deleted it # +---------------------------------------------- col 1 - line number or dash (deleted) |
The first one is currently present in the file. It was created by bigbob. The second one has been deleted. It was created by bigbob and deleted by jlinoff.
Format
The format of the output is each line of the file. The first column is the line number. The second column is the changelist and person (
Use Patterns
You can use the tool in conjunction with other tools like grep to find information about a specific line. Here is an example:
1 2 |
$ p4-whodunit.py //depot/dev/proj1/lib1/src/file1.cc \ grep -B 2 -A 5 'make_unique' |
Note that you do not have to specify the absolute depot path. If you are in a sandbox you can specify the relative path. Here is an example:
1 |
$ p4-whodunit.py proj1/lib1/src/file1.cc | grep -B 2 -A 5 'make_unique' |
Enjoy!