[p4] p4 submit w/o an editor

Jason Williams streak at narus.com
Fri Jul 14 14:59:29 PDT 2006


Weintraub, David wrote:
> The problem is I WANT to script Perforce, but Perforce seems to do
> almost everything in its power to prevent me from easily writing
> scripts.

Maybe it's just me, but Perforce DOES allow you to script with the 
command line client.  It just doesn't allow you to script in the format 
you prefer.

Now...if Perforce didn't use "-i" to accept input and forced you to 
always bring up a text form, then there'd be problems.

> I don't mind the text forms. All I ask is an
> alternative way to get the information into the command via command line
> parameters.

There's many ways to handle automation.

One person may prefer passing command line parameters.  Another person 
may prefer passing in environment variables.  Another person may prefer 
passing in created objects in their favorite language (Ruby, Python, 
etc.).  The nice thing is all of this is possible without too much 
effort.  The big question everyone seems to passing back and forth is 
which paradigm should Perforce support natively?

I'd think command line parameters are great for one line submissions, 
but would prevent people from easily giving more details in their 
submissions.  In fact, it'd discourage lengthy comments.

A command line like the following hardly seems ideal:
"p4 submit -description "This is some detail \
this is more \
this is yet more"

Not to mention, it's useful to have the limited formatting that text 
forms allow for.

> I shouldn't have to go through temp files or pipes to do basic commands.

How about this...No temp files or pipes :)
------------------------------------------
#!/bin/sh
p4 change -i << DONE
Change: new
Description: A changelist
DONE
------------------------------------------

> Here's a common example, I want to find all clients for a particular
> user. The "p4 clients" command doesn't list the user's name in the
> output. I could use "p4 -ztag clients", but then the Owner field is on a
> separate line from the client's name.

Assuming clients and usernames can't have spaces, have you tried 
something like this to search for clients owned by "username"

$ p4 -ztag clients | egrep "^... client|^... Owner" | awk '{print $3}' | 
xargs -n2 | grep " username"

> Look, I like Perforce. It is fast and powerful. However, I've found
> scripting it to be a big pain.

Perhaps some of this is just a matter of choosing the right tools for 
the job.  Why would you ever need Perl/Ruby/Python when you have sed, 
awk, and grep? :)

I've heard lots of good things about the Python and Ruby interfaces to 
Perforce that I believe make some of the problems like forms go away.

Other problems with the exit value not being consistent are still a mess 
though.

--Jason


This email and attachments may contain Narus, Inc. confidential material. If you are not the intended recipient, contact the sender immediately and delete all instances of this email and attachments.



More information about the perforce-user mailing list