[p4] P4 scripting with -ztag
Calman, Kevin
Kevin.Calman at acs-inc.com
Fri Jun 25 09:21:25 PDT 2010
I frequently script once-off mass changes to P4 objects with -o/-i
options, such as
p4 client -o foo | sed -e 's/foo/bar/g' | p4 client -i
which, in a single pipeline, does the following:
- dumps the contents of an existing to a flat text form
- edits that form (in this case, changing all instances of the
client name "foo" to a new value, "bar")
- reads that form in as the definition of a new client object
Obviously, this example is pretty broad and dangerous, I am usually a
bit more specific.
I was trying to use this method to find the clients that had no "Host"
value defined, and assign one, and I discovered that when you dump the
client form for a client specification with no host defined, you do not
get a line beginning with "Host:" with no value after that (as I would
expect), but that there is simply no "Host:" line in the form at all.
This implies that to use this method, I would not be able to simply do a
substitution on a known value (like, 's/^Host:\t*$/&\thostname/'), but
that I would need to scan the form contents, and if no "Host:" line
existed, then add one. The solution I tried was this:
p4 -ztag client -o clientname | awk '{print $0};/^\.\.\.
Host/{X=1};END{if (!X) print "... Host hostname"}' | p4 -ztag client -i
which does the following:
- dumps the existing client as a ztag list of name/value pairs,
rather than as a form
- reads the entire ztag list, passing the lines through unchanged,
and setting a variable if a "Host" line is found
- at then end of the filter process (awk invocation), if no Host
line was found, then explicitly outputting one
- reading all that input into the client command with the intent of
modifying the existing definition
However, this fails with the message,
Error in client specification.
Error detected at line 1.
Syntax error in '...'.
The same happens in the simplest case,
p4 -ztag client -o clientname | p4 -ztag client -i
So apparently, the client command cannot parse ztag-style input as a
definition. The syntax would seem to be supported by the command
descriptions (p4 help client, p4 help undoc). This is observed with P4
Server version: P4D/LINUX26X86/2007.3/143793 (2008/01/09), and client
Rev. P4/CYGWINX86/2008.2/189013 (2009/02/18) on Windows XP/Pro/SP3.
This is a large omission in functionality, and should be easy to
implement. Perforce support, please consider this a feature request.
Thank you.
--
Kevin Calman, Sr. Software Engineer
Austin, TX
More information about the perforce-user
mailing list