using p4python module create a patch between two changelist

162 views Asked by At

I am trying to create a patch between two changelist using p4python. I am not getting any success. Below is my attempt:

$ vi patchp4.py

from P4 import P4,P4Exception
p4 = p4()
#Performed P4 Connection
if p4.connected():

     p4.run('diff2','-u','//depot/ran/y/...@changelist1 //depot/ran/x/...@changelist2')
else:
     print("Not Connected")

I am getting the below error: $ python3 patchp4.py

[Error]: 'Usage: diff2 [-d<flags> -Od -q -t -u ] file file2'
Missing/wrong number of arguments

On command line same options are working fine, while with python script it is throwing wrong argument error.

On Command Line:

$p4 diff2 -u //depot/ran/y/...@changelist1 //depot/ran/x/...@changelist2

Help me out with better guidance.

1

There are 1 answers

0
Samwise On

Each argument to the p4 command needs to be a separate argument to p4.run. You're only passing a single file argument here (with a space in the middle):

p4.run('diff2', '-u', '//depot/ran/y/...@changelist1 //depot/ran/x/...@changelist2')

Instead do:

p4.run('diff2', '-u', '//depot/ran/y/...@changelist1', '//depot/ran/x/...@changelist2')

FWIW, while Perforce does make it possible to create patch files, most of the things you'd do with a patch file in other systems are much more easily accomplished natively in Perforce by either p4 integrate or p4 shelve.