9

Does someone have such a script to share?

  • takes a pending changelist number as input
  • outputs a unified diff (including files open for add)

I know from experience many people who work with perforce all day have these kicking around. I could really use help with the whole issue of "file(s) not in client view" when diffing newly added files via "p4 diff".

user675801
  • 275
  • 3
  • 7
  • I was looking for something like this: (http://confluence.atlassian.com/display/CRUCIBLE/Creating+a+Patch+Review#CreatingaPatchReview-PerforcePatchCreationViaTheCommandLine or this: https://answers.atlassian.com/questions/9522/automatic-patch-review-script-for-perforce – user675801 Mar 15 '12 at 23:43

3 Answers3

3

I didn't have the time to find a proper solution so I used this one liner:

p4 describe $CHANGELIST | sed -ne 's:^\.\.\. \(.*\)#[0-9][0-9]* [a-z][a-z]*$:\1:p' | xargs p4 diff -du

Here is how it works:

Since --

... Pending changelists are indicated as 'pending' and file diffs are not displayed.

p4 describe $CHANGELIST

by itself will not do, but you can use it as a starting point. It gets (among other things) a list of the files that was changed in your $CHANGELIST.

sed -ne 's:^\.\.\. \(.*\)#[0-9][0-9]* [a-z][a-z]*$:\1:p'

Prints the <depot-file> part of only the lines of the form ... <depot-file>#<revision> <action>

xargs p4 diff -du

Takes the list of depot files and run p4 diff -du on it. The -d flag passes u (unified format) to your $P4DIFF program (that should be diff).

Chen Levy
  • 15,438
  • 17
  • 74
  • 92
  • Does this work on windows, I get "sed" is not recognized command. How can I get a file diff (deletion and addition both included) in a colored format which i can send over via email to a peer for review? – codingbbq May 05 '15 at 11:13
  • `sed`, `xargs` and `diff` are typically present on a Unix-like systems. On Windows you can install 3rd party Unix-like utilities, or try to use the PowerShell. See: http://stackoverflow.com/q/127318/110488 – Chen Levy May 05 '15 at 15:13
0

This works for me:

p4 diff2 //depot/a/b/c/... //depot/a/b/c/...@=$CHANGELIST | grep -v '<none>'

The more specific the path, the faster the execution. You may also diff2 the changelist against a different branch.

MarcJ
  • 1
-1

Does p4 describe -du changelist not work for you?

randy-wandisco
  • 3,649
  • 16
  • 11
  • 1
    No, here is why: The script output would be a "diff" or "patch" (depending on your preferred terminology). The litmus test is "can it be fed to the unix patch utility to fully re-create the changes?" Notice that p4 describe does not include content of files "opened for add", so the patch would be missing all newly added files. – user675801 Mar 09 '12 at 18:41
  • Ah, I see - as a workaround you can run 'p4 add' on the entire dir, and ignore the files that already exist. A better solution (status command) is coming on the next release. Once you know which files are added, you can dump their content into the patch. So it will require a script I think. – randy-wandisco Mar 14 '12 at 20:25
  • `p4 describe` does not display any diff at all, even for modified files, if the changelist is pending. – sam hocevar Feb 14 '17 at 14:55