Chocobo
Chocobo

Reputation: 69

How to use p4 trigger on client checkout?

When looking at the p4 trigger document, I can't find a trigger for when a client locks (checks out) and unlocks (reverts) a file. Is there anything similar to the change-content trigger but at the aforementioned stage?

My goal is to setup notifications of client activities using webhooks. I've also looked into p4review.py and it also doesn't look like it triggers on check out/check in. Thanks in advance.

Upvotes: 1

Views: 1187

Answers (1)

Samwise
Samwise

Reputation: 71454

You can run triggers on arbitrary commands via pre/post-user-<command> triggers:

https://www.perforce.com/manuals/v16.2/p4sag/chapter.scripting.html#scripting.triggers.order

Note that these are executed at the level of individual commands (e.g. p4 lock, p4 revert) and not at the level of specific file actions (e.g. locking a file or unlocking a file), so using command triggers to capture specific changes in file state is not as simple as using submit triggers to capture submits.

To take the specific example of locking a file (which is a subset of opening or "checking out" a file), a file may be locked when:

  • the user runs p4 lock (explicitly locking an open file)
  • the user runs p4 submit (which automatically locks the files at the start)

The file may be unlocked when:

  • the user runs p4 unlock (unlocking the file but leaving it open)
  • the user runs p4 revert
  • the user runs p4 submit (which unlocks the files once submit is successful)

There are also "exclusive open" (+l) files to consider, which constitute a different type of lock (preventing other opens rather than other submits).

Another strategy entirely for detecting changes in file lock status might be to scrape the journal file for updates to the db.locks table. Tailing the journal is a little more involved than setting up a trigger, and requires you to have a solid understanding of Perforce's database schema, but if you're able to clear those hurdles it has the advantage of giving you a single source of truth to monitor rather than having to reverse-engineer a bunch of different commands.

Upvotes: 1

Related Questions