p4-whodunit.py – a python script to display who changed each line of code in a perforce depot file

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.

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.

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 (@) that created the line. The third column is an ellipse (…) if there is a fourth column. The fourth column is the changelist and name of who deleted the line. The fifth column is the separator (“|” line is present, “-” line was deleted). The sixth column is the text of the line.

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:

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:

Enjoy!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.