p4 counter
Synopsis
Access, set, increment, or delete a persistent variable.
Syntax
p4 [g-opts
] counter countername
p4 [g-opts
] counter [-f] countername
value
p4 [g-opts
] counter [-f] -d countername
p4 [g-opts
] counter [-f] -i countername
p4 [g-opts
] counter [-f] -m [pair list
]
Description
Counters provide long-term variable storage for scripts that access
Perforce. For example, the Perforce review daemon uses a counter
(review
) that stores the number of the last processed
changelist. Counters can be assigned textual values as well as numeric
ones.
The command includes the following variants:
-
The variant p4 counter
countername
returns the value of variablecountername
. -
The variant p4 counter
countername value
sets the value of variablecountername
set tovalue
. Ifcountername
does not already exist, it is created. -
The variant p4 counter -d
countername
deletes the countercountername
. -
The variant p4 counter -i
countername
increments the counter by one and returns the new value. -
The variant p4 counter -m
pair list
defines multiple operations to be performed. Each operation is defined by a value pair in the pair list. To set a counter use a name and value; to delete a counter use a-
(hyphen) followed by the name. See Examples.This variant is useful in distributed environments where running individual commands is likely to introduce unwanted latency.
Perforce uses four counters in the course of its regular operations:
change
, maxCommitChange
,
job
, and journal
. Superusers can use
the -f
option to force changes to these counters.
Changes to these counters are not without risk; see the
Release
Notes for examples of the types of situations in
which manually resetting these counters might be appropriate.
Options
|
Delete variable |
|
Increment variable |
|
Set or delete counters that are reserved for use by Perforce (listed in p4 help counters).
Never set the
|
|
Specify a list of operations to be performed. Each operation is
defined by a value pair in the pair list. To set a counter, use
a name and value; to delete a counter use a |
|
See “Global Options”. |
Usage Notes
Can File Arguments Use Revision Specifier? |
Can File Arguments Use Revision Range? |
Minimal Access Level Required |
---|---|---|
N/A |
N/A |
|
-
If a counter does not exist, its value is returned as zero; counter names are not stored in the database until set to a nonzero value.
-
The last changelist number known to the Perforce service (the output of p4 counter change) includes pending changelists created by users, but not yet submitted to the depot. If you're writing change review daemons, you might also want to know the changelist number of the last submitted changelist, which is the second field of the output of the command:
p4 changes -m 1 -s submitted
-
The last changelist number successfully submitted (that is, no longer pending) to the Perforce service is held in the
maxCommitChange
counter.
Examples
p4 counter mycounter 123 |
Set the value of a counter
Requires |
p4 counter mycounter |
Display the value of
Requires |
p4 counter -m firstcounter 5 second counter 4 |
Set two counters. |
p4 counter -m - xset - yset |
Delete two counters. |
p4 counter -m firstcounter 6 - secondcounter |
Set one counter; delete one counter. |