pythonpython-3.xsubprocessperforceperforce-helix-core

How to add a long list of files to a changelist in Perforce using python's subprocess module and the Helix Core API?


I have 1,000 files that I want to add/move to a single changelist. In other commands such as "add" you can create a list of file paths in a text document and add a "-x" parameter before the file path, creating something like this: p4 -x path/to/text/file/with/paths.txt add.

With "p4 change" however, you have to add your list of files as a field parameter specifically, which as far as I know can't read from an external list: p4 --field "Description={description}" --field "Files=path/to/individual/file.txt" change -o. I can't put them all in a long list since that'd go over the character limit for the command, and inputting each path in to a separate "subprocess.run" command would take a really long time to run through.


Solution

  • You don't need to use the p4 change command to move all the files to a different changelist.

    If you create the change before the files are opened for add in the first place, you can open the files in that changelist directly with the -c flag on the p4 add command:

    p4 -x path/to/text/file/with/paths.txt add -c CHANGE
    

    If the files are already opened for add and you want to move them to another changelist, use the p4 reopen command:

    p4 -x path/to/text/file/with/paths.txt reopen -c CHANGE