Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a Perforce patch?

I generated a patch some time ago using the p4 diff command.

However, now that I want to apply it, I realize that there is no way to apply a patch in Perforce.

Since I did not use the -du option, the patch is in that obscure perforce format and can't be applied with patch(1). The original changes have been lost. Also, that patch is over 300kb long so manual editing isn't really an option.

What are my options ? Are there patch converters, or some Perforce extension allowing the application of these kind of patchs ?

like image 715
slaphappy Avatar asked Feb 24 '12 10:02

slaphappy


People also ask

What does the patch command do?

The patch command reads a source file's instructions on how to change a file, then applies the changes. The source file contains difference listings (or diff listings) produced by the diff -c or -u command, and one or more sets of diff command output, customarily called hunks.


Video Answer


1 Answers

Perhaps Perforce's diff output format has changed, but @RumburaK's answer didn't work for me.

I had to modify it to convert the ==== header to diff's +++ and --- header format.

sed -Ee 's|==== (//.*)#[0-9]+(.*)|+++ \1\n--- \1|' < infile.txt > outfile.txt

infile.txt was generated with the following command (where 12335 was a shelved changelist): p4 describe -du -S 12345

outfile.txt was applied with the following command: patch -p3 -l < outfile.txt

like image 113
Jason Spangler Avatar answered Oct 30 '22 10:10

Jason Spangler