/******************************************************************************* Copyright (c) 1997-2004, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTR IBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /******************************************************************************* * Name : p4clientapi.h * * Author : Tony Smith <tony@perforce.com> or <tony@smee.org> * * Description : Ruby bindings for the Perforce API. Definitions of our * main interface to Perforce * ******************************************************************************/ /******************************************************************************* * P4ClientApi class - where we register our Ruby classes and plumb together * the components ******************************************************************************/ class P4ClientApi { public: P4ClientApi(); ~P4ClientApi(); // Protocol options. Call before Connect() void ParseForms(); // Tagged mode - can be enabled/disabled on a per-command basis void Tagged(int enable ); // Returns bool, but may raise exception int SetCharset( const char *c ); // Set API level for backwards compatibility void SetApiLevel( int level ); void SetClient( const char *c ) { client.SetClient( c ); } void SetCwd( const char *c ) { client.SetCwd( c ); } void SetHost( const char *h ) { client.SetHost( h ); } void SetMaxResults( int v ) { maxResults = v; } void SetMaxScanRows( int v ) { maxScanRows = v; } void SetPassword( const char *p ) { client.SetPassword( p ); } void SetPort( const char *p ) { client.SetPort( p ); } void SetProg( const char *p ); void SetUser( const char *u ) { client.SetUser( u ); } const StrPtr &GetCharset() { return charset; } const StrPtr &GetClient() { return client.GetClient(); } const StrPtr &GetCwd() { return client.GetCwd(); } const StrPtr &GetHost() { return client.GetHost(); } const StrPtr &GetPassword() { return client.GetPassword(); } const StrPtr &GetPort() { return client.GetPort(); } const StrPtr &GetUser() { return client.GetUser(); } // Session management VALUE Connect(); // P4Exception on error VALUE Disconnect(); // Executing commands. VALUE Run( const char *cmd, int argc, char * const *argv ); VALUE SetInput( VALUE input ); // Result handling VALUE GetOutput() { return ui.GetResults().GetOutput();} VALUE GetErrors() { return ui.GetResults().GetErrors();} VALUE GetWarnings() { return ui.GetResults().GetWarnings();} // Spec parsing VALUE ParseSpec( const char * type, const char *form ); VALUE FormatSpec( const char *type, VALUE hash ); VALUE SpecFields( const char * type ); // Exception levels: // // 0 - No exceptions raised // 1 - Exceptions raised for errors // 2 - Exceptions raised for errors and warnings // void ExceptionLevel( int i ) { exceptionLevel = i; } int ExceptionLevel() { return exceptionLevel; } void Except( const char *func, Error *e ); void Except( const char *func, const char *msg ); void Except( const char *func, const char *msg, const char *cmd ); // // Debugging support. Debug levels are: // // 1: Debugs commands being executed // 2: Debug UI method calls // 3: Show garbage collection // void SetDebug( int d ); // Ruby garbage collection void GCMark(); private: void RunCmd(const char *cmd, ClientUser *ui, int argc, char * const *argv); StrPtr * FetchSpecDef( const char *type ); public: ClientApi client; private: ClientUserRuby ui; StrBufDict specDict; StrBuf prog; StrBuf charset; int depth; int initCount; int debug; int exceptionLevel; int server2; int mode; int maxResults; int maxScanRows; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#21 | 5791 | Tony Smith |
Add experimental support for passing a block to P4#run_resolve. The block is passed a P4::MergeData object encapsulating the context of each merge performed. The block should evaluate to a string indicating the desired result of the merge: 'ay', 'at', 'am', 's', etc. The P4::MergeData object contains information about the files involved in the merge and can invoke an external merge tool. This is still experimental at this stage so the interface may change as it evolves. |
||
#20 | 5311 | Tony Smith |
Add new P4#api= method to allow users to lock scripts to a particular API level. This helps when upgrading to new servers that extend support for tagged output to hitherto unsupported commands (2005.2 did a lot of that). See the C/C++ API Release Notes for the full details, but by way of example, to lock scripts to the 2005.1 interface use: p4.api = 57 |
||
#19 | 4942 | Tony Smith |
Add support for Unicode servers to P4Ruby. This change adds two new interfaces, P4#charset= and P4#charset? to set and get the charset respectively. |
||
#18 | 4940 | Tony Smith |
Add (undoc'd) support for enabling/disabling tagged mode on a per-command basis. Also fixed a minor typo which was rendering an error message less useful than intended. |
||
#17 | 4870 | Tony Smith |
Call ClientApi::SetProg() every time a command is run rather than only once. This makes the log entries correctly record the script name against every command that the script runs. |
||
#16 | 4809 | Tony Smith |
Add P4#maxresults= and P4#maxscanrows= methods to allow you to place explicit limits on the execution of individual commands. These limits remain in force for all subsequent commands until they are removed by setting them to zero. Port of new functionality from P4Perl. |
||
#15 | 4680 | Tony Smith |
Make P4Ruby return new P4::Spec objects instead of plain old hashes when parse_forms mode is in use. A P4::Spec object is derived from Hash so should be backwards compatible with previous code. P4::Spec provides limited fieldname validation on forms and accessor methods for quick and easy access to the fields in the form. The accessor methods are all prefixed with '_' to avoid colliding with methods from the Hash parent class. This is a little ugly, but deriving from hash is a big win, so it's worth it. This change also fixes a minor bug found along the way. Spec parsing and formatting wouldn't work with labels, branches, depots and groups unless you'd previously run a P4::fetch_label( <label> ), P4::fetch_branch( <branch> ) etc. etc. This is because the spec parsing code internally runs one of these commands in order to grab the specdef from the server but it wasn't providing a spec name. i.e. it was using 'p4 client -o' and assuming that this would work for other types of spec too. It does, but not for all spec types. So, now the spec parsing code will use a bogus name for the spec types that require it. |
||
#14 | 4651 | Tony Smith |
Add format_spec() method and format_* shortcuts to make it easy to convert a spec in a hash back to its string form without sending it to the server. |
||
#13 | 4589 | Tony Smith |
Update P4Ruby to support the new SetProg() method in the 2004.2 API. Whilst the new 'P4#prog=' method is always available, it's only functional if P4Ruby is built with a 2004.2 or later API. The build system got a bit of tidying up to support this change and the API version is now detected automatically if possible. I've also removed the --apilibdir and --apiincludedir flags as they complicate matters and I never use them and I don't believe anyone else does either. There are also some minor doc formatting tweaks to go along with the added documentation for prog=. |
||
#12 | 4261 | Tony Smith |
Add support for parsing arbitrary specs from strings in Ruby space. Useful with spec depots. You might obtain the spec by running a "p4 print -q" against a file in a spec depot, but want to parse it into a Ruby hash. i.e. p4 = P4.new p4.parse_forms # Required! p4.connect buf = p4.run_print( "-q", "//specs/client/myclient" ) spec = p4.parse_client( buf ) # Or equivalently spec = p4.parse_spec( "client", buf ) |
||
#11 | 4157 | Tony Smith |
Copyright notice update. No functional change |
||
#10 | 1869 | Tony Smith |
Build in workaround for 2000.[12] protocol bug with "p4 client -o" in tagged mode so script writers don't have to think about it |
||
#9 | 1426 | Tony Smith |
Cleaned up the debug output a little. Introduced some debug levels so you can decide (roughly) what output you want to see. Level 1 shows command execution, connect and disconnect. Level 2 includes Level 1 and also shows the RPC callbacks as they happen. Level 3 includes 1 and 2 and also shows when Ruby garbage collection takes place. Converted all the simple methods of the form P4#meth( arg ) to aliases for P4#meth=. Added P4#debug= to complete the scheme. The P4#meth( arg ) forms are now deprecated. i.e. you should use: p4.user = "tony" and not: p4.user( "tony" ) It's just more Ruby-like. |
||
#8 | 1391 | Tony Smith |
Bug fix. Garbage collection can apparently run at any time (i.e. when you're in C space and not just when you're in Ruby space) and it was occasionally running in between adjacent "delete" and "new" statements when the result set was being reset. This change removes this race condition by making the result member of ClientUserRuby a permanently instantiated variable and extending the P4Result class so that it can reset itself in a way that GC respects. Now the only dynamically allocated C++ object is the top level P4ClientApi object. No functional change. |
||
#7 | 1275 | Tony Smith |
Added synonym methods for: p4.cwd / p4.cwd= p4.client / p4.client= p4.host / p4.host= p4.password / p4.password= p4.port / p4.port= p4.user / p4.user= And for exceptions: p4.exception_level / p4.exception_level= and p4.exception_level? so you can test the current exception level p4.exception_level and p4.exception_level= now return the exception level rather than true. |
||
#6 | 1166 | Tony Smith |
Followup to previous change. Simplify the interface to getting results/errors and warnings. No need for the P4Result class anymore so that's gone (though it's still there as a C++ class because it's useful) and so is P4#result. Now you get your errors/warnings and results using P4#errors, P4#warnings and P4#output all of which return arrays. |
||
#5 | 1165 | Tony Smith |
Minor reshuffle. Added the ability to disable exceptions completely if you don't like them or to have them raised only for errors (and not for warnings). Removed P4#warnings interface and replaced it with P4#exception_level. Some minor doc tweaks to go with the above change |
||
#4 | 1164 | Tony Smith |
Reworked exception handling (hopefully for the last time) in P4/Ruby. Now exceptions are raised on completion of Perforce commands if any errors or warnings were received as part of executing the command. This change also adds documentation, and indexes the Ruby interface off my main page. Bad form to combine so many changes in one changelist, but it's getting late and I want to get them submitted! |
||
#3 | 1083 | Tony Smith |
Sweeping change to exception handling and garbage collection. Exceptions are no longer raised for errors encoutered during execution of Perforce commands as that was causing processing to abort at the first error when several success messages may have been close behind. Now exceptions are raised for events which are fatal to the execution of commands - such as failure to connect to the Perforce server for example. For other errors, the user must call "p4.errors? " to determine whether or not errors occured and "p4.errors" to get an array of error messages. You can of course then raise exceptions yourself if you want to: begin client = p4.fetch_client if p4.errors? raise P4Exception, "p4 client -o failed" end rescue P4Exception => m puts( m ) p4.errors.each { |e| puts( e ) } end version.h got renamed because it conflicts with ruby's own version.h file. We may need to look in there at some point for ruby's version so I'm getting it out of the way now. Added gc_hack.h to make sure that GC works properly on all platforms now so Ruby shouldn't nuke any objects we're holding now. |
||
#2 | 1081 | Tony Smith |
Debugging and identification support. Adds two new methods: P4#identify() P4#debug( int ) |
||
#1 | 1015 | Tony Smith |
First cut of Perforce bindings for the Ruby scripting language. Similar functionality to the Perl API stuff, but "rubyfied". Supports error reporting via exceptions, and presents tagged output and parsed forms as hash structures, with nested arrays where required. Still early days so the docs are thin on the ground. See the example.pl for a brief guide. Built with Ruby 1.6.4 on Linux. May still be some memory management issues as the Ruby Garbage Collection API has changed a little since the docs I've got and I've just dodged garbage collection for now. Not indexing this just yet. |