Is there an equivalent of svn\'s blame for Perforce on the command line? p4 annotate
doesn\'t display usernames -- only changeset numbers (without ancestor history!
From the p4v client, you can get "Time-lapse View" context menu on all the view displaying file like Files, Changelist etc.
The time lapse view has quite a few options like Single Revision, Multiple Revision to analyze what was changed, when and by whom.
I'm not overly familiar with the blame command, but I assume that you are looking for who changes a particular line of code. The easiest way is to use Perforce's 'time lapse view' available from both p4win and p4v.
This tool uses annotate and some other commands to give you a view of the code line over time. You can see who modified what code, when it was inserted or removed from the codeline, etc.
It's not command line though. I checked briefly in the help and there doesnt' seem to be a way to launch the time lapse view directly from a p4win or p4v invocation. There might be though...I'll be checking further...
Edit: I checked with support, and you can launch the timelapse view through p4v as follows:
p4v.exe -cmd "annotate //<path/to/file>"
HTH.
@alanw123: p4pr is close to what I'm looking for, but it doesn't cross branch boundaries:
last if $type eq 'branch';
That was the main problem I had when I tried writing my own utility -- you can't (easily) tell how the lines map back to the file that was branched from.
The p4 annotate
command actually can follow merges/integrations and branching on the command line with the -I
and -i
commands (but it cannot do both at once :( ):
-I
Follow integrations into the file. If a line was introduced into the file by a merge, the source of the merge is indicated as the changelist that introduced the line. If that source was itself the result of an integration, that source will be used instead, and so on.
The use of the -I option implies the -c option. The -I option cannot be combined with -i.
-i
Follow file history across branches. If a file was created by branching, Perforce includes revisions up to the branch point.
The use of the -i option implies the -c option. The -i option cannot be combined with -I.
I use a small script for blaming
#!/bin/bash
FILE="$1"
LINE="$2"
p4 annotate -cq "${FILE}" | sed "${LINE}q;d" | cut -f1 -d: | xargs p4 describe -s | sed -e '/Affected files/,$d'
you can hook it to some of the editors that will pass the file name and line.
There's a little more complex version here.
Try taking a look at a couple of tools that I think could get you most of what you need:
1) p4pr Perl script by Bob Sidebotham and Jonathan Kamens.
2) Emacs Perforce interface has a command 'p4-print-with-rev-history' (bound to `C-x p V').