Knowledge Base Administration Guide

Perforce (p4)

Some helpful commands for using Perforce and Simscope.

Command-line manual

The p4 command-line manual is available on perforce.com

Client info (workspace)

To get basic info on the Perforce client workspace and server version:

$ p4 info

User name: pdq
Client name: client
Client host: client.local
Client root: /home/pdq/perforce-workspace
Current directory: /home/pdq/perforce-workspace
Peer address: 127.0.0.1:53071
Client address: 127.0.0.1
Server address: localhost:1666
Server root: .
Server date: 2020/08/12 21:28:05 -0500 CDT
Server uptime: 00:04:03
Server version: P4D/MACOSX1010X86_64/2020.1/1953492 (2020/04/24)
Server license: none
Case Handling: insensitive

To change the client workspace settings, run:

$ p4 client

Perforce changelist

To get the Perforce changelist of the workspace:

$ p4 -ztag changes -m1
... change 4
... time 1595987401
... user pdq
... client client
... status submitted
... changeType public
... path //depot/*
... desc Another batch of changes

To get just the changelist number of the current workspace:

$ p4 -ztag changes -m1 | grep '... change ' | cut -d' ' -f3
4

Perforce changelist timestamp

To get the Perforce changelist Unix timestamp (model_timestamp) from within a workspace:

$ p4 -ztag changes -m1 | grep '... time ' | cut -d' ' -f3
1595987401

NOTE: you can convert the Unix timestamp to RFC3339

To get the Perforce timestamp for a specific changelist:

# Replace CHANGELIST
$ p4 -ztag describe CHANGELIST | grep '... time ' | cut -d' ' -f3

# Example
$ p4 -ztag describe 2000 | grep '... time ' | cut -d' ' -f3
1595964080

Dump changelist diff

To dump a single Perforce changelist diff:

# Replace CHANGELIST
$ p4 describe -S CHANGELIST

For example, to dump changelist 4:

$ p4 describe -S 4
Change 4 by pdq@client on 2020/07/28 20:50:01

        Another batch of changes

Affected files ...

... //depot/8349.txt#2 edit

Differences ...

==== //depot/8349.txt#2 (text) ====

9,15c9
< verops/simscope/admin.html                              EndpointAdminHome                       100.0%
< verops/simscope/admin.html                              EndpointAdmin                           92.1%
< verops/simscope/admin.html                              SimscopeDBStats                         100.0%
< verops/simscope/admin.html                              RestGet                                 96.4%
< verops/simscope/admin.html                              RestPost                                77.8%
< verops/simscope/api_assignments.html                    Error                                   100.0%
< verops/simscope/api_assignments.html                    init                                    100.0%
---
> verops/simscope/api_assignments.html2                   init                                    100.0%

File changes between a range of changelists (diff)

To see the files changed between two arbitrary changelists in Perforce:

$ p4 filelog DEPOT/...@REV1,REV2

For example, to diff between changelist 2 and 4:

$ p4 filelog //depot/...@2,4
//depot/8309.txt
... #2 change 2 delete on 2020/07/28 by pdq@client (text) 'Deleted a file'
//depot/8345.txt
... #2 change 3 edit on 2020/07/28 by pdq@client (text) 'Changed file'
//depot/8349.txt
... #2 change 4 edit on 2020/07/28 by pdq@client (text) 'Another batch of changes '

File log with ztag

NOTE: you can also use the -ztag modifier, to make consuming via scripts easier:

$ p4 -ztag filelog //depot/...@2,4

... depotFile //depot/8309.txt
... rev0 2
... change0 2
... action0 delete
... type0 text
... time0 1595963494
... user0 pdq
... client0 client
... desc0 Deleted a file

... depotFile //depot/8345.txt
... rev0 2
... change0 3
... action0 edit
... type0 text
... time0 1595964080
... user0 pdq
... client0 client
... fileSize0 90958
... digest0 321DF14492CCC9BAC4374ADBAB976101
... desc0 Changed file

... depotFile //depot/8349.txt
... rev0 2
... change0 4
... action0 edit
... type0 text
... time0 1595987401
... user0 pdq
... client0 client
... fileSize0 83848
... digest0 A91F1B7CA35F724C520206670E66B779
... desc0 Another batch of changes