Need p4python commands to sync code from Perforce

4.8k Views Asked by At

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)
1

There are 1 best solutions below

4
On

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)