1

I'm writing a script to sync code from Perforce. I'm using P4Python. Im very new to this. i need P4Python commands for below.

  1. How to find latest Changelist number of a directory in Perforce.
    e.g. Want to find latest CL of //cbuDepot/cpe/foo/...
  2. How to sync the code from Perforce with latest CL e.g. Want to sync latest code from //cbuDepot/cpe/foo/...
  3. How to sync the code from Perforce to older CL(Not latest)
phiver
  • 23,048
  • 14
  • 44
  • 56
user1734852
  • 11
  • 1
  • 4

1 Answers1

0

Find latest changelist number of a directory:

p4.run("changes", "-s", "submitted", "-m", "1", "//cbuDepot/cpe/foo/..."  )

Sync to latest changelist:

p4.run("sync", "//cbuDepot/cpe/foo/...")

Sync to older changelist:

p4.run("sync", "//cbuDepot/cpe/foo/...@123")

To use a variable "changelist":

p4.run("sync", "//cbuDepot/cpe/foo/...@"+ changelist)
tkosinski
  • 1,631
  • 13
  • 17
  • HI, Thanks for the reply. In third answer, how to specify variable? i want to sync to a older CL & CL number is in var1. tried below: p4.run("sync", "//cbuDepot/cpe/foo/...@var1"). it didnt work. kindly help me. – user1734852 Feb 26 '16 at 07:18
  • HI, Thanks a lot for the response. i need some more info. 1)How to specify clientspec? e.g: i want to sync code at //cbuDepot/cpe/foo/... into my local machine at: D:/abc/foo/... i did this. p4.run_login() client = p4.fetch_client(CLIENT). Then, to know, latest CL, i ran: p4.run("changes", "-s", "submitted", "-m", "1", "//cbuDepot/cpe/foo/..." ). it gave incorrect CL. it was giving CL latest check-in in complete P4 server. Thanks in advance :) – user1734852 Feb 28 '16 at 10:55
  • To specify a clientspec (aka workspace), add this line before running any commands: p4.client = "MyClient" – tkosinski Feb 29 '16 at 15:06
  • @tkosinski Hi, I want to find latest changelist number using the Perforce plugin (P4) for jenkins. So In my jenkins pipeline (which is Pipeline script from SCM running in groovy sandbox), I do sync the perforce using p4.run("sync"). I want to get changelist number here. is there any way?? – Shubham Gaikwad Nov 13 '20 at 13:01