Noel Yap
Noel Yap

Reputation: 19758

How to create numbered changelist using P4Python?

P4.fetch_change() creates a change spec with Change equal to 'new'. I need to create a change spec with an actual number (that won't collide with any other changes). IOW, I need to be able to reserve a changelist number.

How can this be done with P4Python?

Context: My script takes in an already-existing changelist number. I need to be able to test that the script works correctly.

Upvotes: 6

Views: 5503

Answers (3)

ewerybody
ewerybody

Reputation: 1580

Note that p4.fetch_change() gives you the dict of the current default changelist!

You might already have files in there! So to really create an empty one you can just pass a dict with 'Change': 'new' and a 'Description'.

I couldn't find a way to make save_change return the actual changelist integer. So one can split the result and have the nr that way:

from P4 import P4

def create_empty_changelist(desc='some description'):
    p4 = P4()
    p4.connect()
    result = p4.save_change({'Change': 'new', 'Description': desc})[0]
    return int(result.split()[1])

Upvotes: 6

user1054341
user1054341

Reputation: 3289

P4.save_change() generates a changelist number -- that is, it creates a numbered, pending changelist. Try something like:

changespec = P4.fetch_change()
changespec[ "Description" ] = "placeholder"
P4.save_change( changespec )

Upvotes: 6

spinlok
spinlok

Reputation: 3661

Perforce doesn't allow you to reserve changelist numbers. If you want to submit an existing (pending) changelist using P4Python, do: p4.run_submit("-c", changelist)

Upvotes: 0

Related Questions