Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest Perforce changelist in the depot for the current client spec

Tags:

perforce

I want to get the latest changelist in the depot for my current client spec. This would effectively be the change that would by synced to if I did a p4 sync in my workspace.

I tried doing p4 changes -s submitted -m1 -c [client-name], but that returns the most recent change that was submitted via my client.

Doing p4 changes -s submitted -m1 //depot/path/... will work, but I don't want to have to query the client spec to figure out what the depot path is. Plus if there were more than one mapping I wouldn't know how to make sense of that.

It seems there must be a simple way to do this which I am missing.

EDIT

I did have to query the client spec, but as pointed out in the accepted answer, I could use the client spec root as the file path and didn't need to look at the view mappings.

Final solution using P4Python:

# Get client
clientspec = p4.fetch_client()
root = clientspec["Root"]

# Get latest changenum in client mapping
changes = p4.run("changes", "-s", "submitted", "-m1", root + "/...")
changenum = changes[0]['change']
like image 814
dwikle Avatar asked Nov 13 '22 11:11

dwikle


1 Answers

I think you're going to have to query your client spec to find its local root. If you don't need to worry about AltRoots, then this could be:

p4 changes -s submitted -m 1 "$(p4 client -o | grep "^Root:" | cut -f 2)/..."

in bash. Using your local client root instead of the depot path avoids the problem with multiple mappings.

like image 170
jamesdlin Avatar answered Dec 28 '22 07:12

jamesdlin