I want to get diffs on files in a specific pending changelist. I wish I could do this:
p4 diff -c 999
Can someone help me string together some csh magic to make this happen?
Maybe take the output of p4 opened -c 999 and piping it to p4 diff?
I want to get diffs on files in a specific pending changelist. I wish I could do this:
p4 diff -c 999
Can someone help me string together some csh magic to make this happen?
Maybe take the output of p4 opened -c 999 and piping it to p4 diff?
Shelve the changes in the pending changelist, then run
p4 describe -S -du 999
The easiest way is in p4v or p4win, but that's not what you were asking about.
Try this:
p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | csh
You, of course, need to make sure that the sub shell has p4 in its path, and $P4CLIENT, etc... are all set up.
p4 opened -c 999 | sed -e 's/#.*//' | p4 -x - diff
p4 -x gives you xargs like ability without having to use xargs. From p4 help utils:
The -x flag instructs p4 to read arguments, one per line, from the specified file. If you specify '-', standard input is read.
So you can almost just "take the output of p4 opened -c 999 and pipe it to p4 diff" as suggested in the question. The one tricky part is that the output of p4 opened contains revision numbers and explanatory text after the name of each open file e.g.
//depot/example#123 - edit change 999 (text) by day@office
//depot/new-example#1 - add change 999 (text) by day@office
But we can run this through a simple sed -e 's/#.*//' to strip off everything from the # onwards to leave just the paths:
//depot/example
//depot/new-example
which can then be consumed from standard input and fed to p4 diff thanks to p4 -x -.
If you have # in the names of any files then you'll need to get more clever with the sed command. And see a psychiatrist.
p4 describe 999 | grep '#' | cut -d"#" -f1|cut -d" " -f2 | xargs p4 diff
You can use shell script like this:
#!/bin/sh
list=`p4 opened -c $1 | cut -d# -f1`
for file in $list ;
do
p4 diff -dwbu $file
done
call it with changelist number and you'll get patch in stdout.
For a one-liner that works from the Windows cmd shell, try this:
for /f "usebackq delims=#" %F in (`p4 opened -c 999`) do @p4 diff %F
To do this in a batch file you need to use %%F instead of just %F.
Note that some of the solution above will work under Windows if you have installed a unix-like utilities package such as cygwin or unixutils, but this one-liner has no external dependencies.
I used a similar approach as Mark, but I used Perl instead of Awk, and a shell function (in zsh):
p4dc() { p4 opened -c $* | perl -ne 's/#.*//; system("p4", "diff", $_)' }
Note that you can provide a file path too, in addition to just the changelist name/number:
p4dc default | less
p4dc default ... | less
The above answers your question but, if tile is read as diffing a directory on a change list it can be answered with the following:
p4 filelog ... | awk '
BEGIN {FS="[ /]";tc=999}
/^\/\// {fn=$NF;o=1;if (system("test -w " fn)) h=0; else h=""}
/^\.\.\.\ \#/ {if (h==0) h=$2;
if ($4<=tc && o==1) {print "p4 diff -db -dw " fn h " " fn $2 " ;#" $4;o=0}}' \
| sh
This will diff all the files in the directory against the changelist 999 it uses the "have" version if it has be checked out otherwise it uses the latest version.
this was tested with GNU Awk 3.1.3
For Unshelved Changes( Changes still not in depot)
p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | bash
For Shelved Changes( Changes that in depot ( p4 shelve -c 999)
p4 describe -S -du3 -O 999