{"id":1623,"date":"2015-01-31T11:52:59","date_gmt":"2015-01-31T19:52:59","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=1623"},"modified":"2015-01-31T12:06:34","modified_gmt":"2015-01-31T20:06:34","slug":"p4-whodunit-py-a-python-script-to-display-who-changed-each-line-of-code-in-a-perforce-depot-file","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=1623","title":{"rendered":"p4-whodunit.py &#8211; a python script to display who changed each line of code in a perforce depot file"},"content":{"rendered":"<p>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 <a href=\"http:\/\/projects.joelinoff.com\/p4tools\/p4-whodunit.py\">here<\/a>.<br \/>\n<!--more--><\/p>\n<p><strong>Acknowledgements<\/strong><br \/>\nThe script was inspired by a shell script developed by my colleague: Kris Kozminski to combine the &#8220;<code>p4 describe<\/code>&#8221; and &#8220;<code>p4 annotate<\/code>&#8221; commands.<\/p>\n<p><strong>Download and Install<\/strong><br \/>\nHere is how you download and install the tool from the command line. Note that you must have &#8220;p4&#8221; in your path for it to work.<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:bash decode:true\">\r\n$ wget http:\/\/projects.joelinoff.com\/p4tools\/p4-whodunit.py  # download\r\n$ chmod a+x p4-whodunit.py                                   # make executable\r\n$ mv p4-whodunit.py \/opt\/local\/bin                           # move to common area\r\n$ which p4-whodunit.py                                       # test\r\n\/opt\/local\/bin\/p4-whodunit.py\r\n$ p4-whodunit.py -h                                          # test\r\n<\/pre>\n<p>You may need to change the first line of the script to make it work properly in your environment.<\/p>\n<p><strong>Running the Tool<\/strong><br \/>\nYou 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. <\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:bash decode:true\">\r\n$ p4-whodunit.py \/\/depot\/dev\/proj1\/lib1\/src\/file1.cc\r\n  .\r\n  .\r\n  275 11547@bigbob                      |    auto up1 = make_unique(Thing);\r\n    - 11547@bigbob ... 363442@jlinoff   - \r\n# ^   ^     ^      ^   ^                ^    ^\r\n# |   |     |      |   |                |    +--- col 6 - source line\r\n# |   |     |      |   |                +-------- col 5 -separator (|, -)\r\n# |   |     |      |   +------------------------- col 4 - who deleted it\r\n# |   |     |      +----------------------------- col 3 - ellipses\r\n# |   +------------------------------------------ col 2 - who deleted it\r\n# +---------------------------------------------- col 1 - line number or dash (deleted)\r\n<\/pre>\n<p>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.<\/p>\n<p><strong>Format<\/strong><br \/>\nThe 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 (<cl>@<name>) that created the line. The third column is an ellipse (&#8230;) 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 (&#8220;|&#8221; line is present, &#8220;-&#8221; line was deleted). The sixth column is the text of the line.<\/p>\n<p><strong>Use Patterns<\/strong><br \/>\nYou can use the tool in conjunction with other tools like grep to find information about a specific line. Here is an example:<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:bash decode:true\">\r\n$ p4-whodunit.py \/\/depot\/dev\/proj1\/lib1\/src\/file1.cc \\\r\n    grep -B 2 -A 5 'make_unique'\r\n<\/pre>\n<p>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:<\/p>\n<pre class=\"theme:vs2012-black font-size:14 line-height:17 lang:bash decode:true\">\r\n$ p4-whodunit.py proj1\/lib1\/src\/file1.cc | grep -B 2 -A 5 'make_unique'\r\n<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[5,16],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1623"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1623"}],"version-history":[{"count":15,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":1638,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1623\/revisions\/1638"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}