/******************************************************************************* Copyright (c) 2001-2008, 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 CONTRIBUTORS "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 : p4result.cc * * Author : Tony Smith <tony@perforce.com> or <tony@smee.org> * * Description : Ruby class for holding results of Perforce commands * ******************************************************************************/ #include <ruby.h> #include "undefdups.h" #include <clientapi.h> #include "gc_hack.h" #include "p4error.h" #include "p4result.h" P4Result::P4Result() { output = rb_ary_new(); warnings = rb_ary_new(); errors = rb_ary_new(); track = rb_ary_new(); apiLevel = atoi( P4Tag::l_client ); ID idP4 = rb_intern( "P4" ); ID idP4Msg = rb_intern( "Message" ); VALUE cP4 = rb_const_get_at( rb_cObject, idP4 ); cP4Msg = rb_const_get_at( cP4, idP4Msg ); } void P4Result::Reset() { output = rb_ary_new(); warnings = rb_ary_new(); errors = rb_ary_new(); track = rb_ary_new(); } void P4Result::AddOutput( const char *msg ) { rb_ary_push( output, rb_str_new2( msg ) ); // // Call the ruby thread scheduler to allow another thread to run // now. We should perhaps only call this every 'n' times, but I've // no idea what a good value for n might be; so for now at least, n=1 // rb_thread_schedule(); } void P4Result::AddOutput( VALUE out ) { rb_ary_push( output, out ); // // Call the ruby thread scheduler to allow another thread to run // now. We should perhaps only call this every 'n' times, but I've // no idea what a good value for n might be; so for now at least, n=1 // rb_thread_schedule(); } void P4Result::AddError( Error *e ) { int s; s = e->GetSeverity(); // // Empty and informational messages are pushed out as output as nothing // worthy of error handling has occurred. Warnings go into the warnings // list and the rest are lumped together as errors. // if ( s == E_EMPTY || s == E_INFO ) { StrBuf m; e->Fmt( &m, EF_PLAIN ); AddOutput( m.Text() ); return; } if ( s == E_WARN ) rb_ary_push( warnings, FmtMessage( e ) ); else rb_ary_push( errors, FmtMessage( e ) ); // // Call the ruby thread scheduler to allow another thread to run // now. We should perhaps only call this every 'n' times, but I've // no idea what a good value for n might be; so for now at least, n=1 // rb_thread_schedule(); } void P4Result::AddTrack( const char *msg ) { rb_ary_push( track, rb_str_new2( msg ) ); // // Call the ruby thread scheduler to allow another thread to run // now. We should perhaps only call this every 'n' times, but I've // no idea what a good value for n might be; so for now at least, n=1 // rb_thread_schedule(); } void P4Result::AddTrack( VALUE t ) { rb_ary_push( track, t ); // // Call the ruby thread scheduler to allow another thread to run // now. We should perhaps only call this every 'n' times, but I've // no idea what a good value for n might be; so for now at least, n=1 // rb_thread_schedule(); } int P4Result::ErrorCount() { return Length( errors ); } int P4Result::WarningCount() { return Length( warnings ); } void P4Result::FmtErrors( StrBuf &buf ) { Fmt( "[Error]: ", errors, buf ); } void P4Result::FmtWarnings( StrBuf &buf ) { Fmt( "[Warning]: ", warnings, buf ); } int P4Result::Length( VALUE ary ) { ID iLength; VALUE len; iLength = rb_intern( "length" ); len = rb_funcall( ary, iLength, 0 ); return NUM2INT( len ); } void P4Result::GCMark() { rb_gc_mark( output ); rb_gc_mark( errors ); rb_gc_mark( warnings ); rb_gc_mark( track ); } void P4Result::Fmt( const char *label, VALUE ary, StrBuf &buf ) { ID idJoin; VALUE s1; StrBuf csep; VALUE rsep; buf.Clear(); // If the array is empty, then we just return if( ! Length( ary ) ) return; // Not empty, so we'll format it. idJoin = rb_intern( "join" ); // This is the string we'll use to prefix each entry in the array csep << "\n\t" << label; rsep = rb_str_new2( csep.Text() ); // Since Array#join() won't prefix the first element with the separator // we'll have to do it manually. buf << csep; // Join the array elements together, and append the result to the buffer s1 = rb_funcall( ary, idJoin, 1, rsep ); buf << STR2CSTR( s1 ); return; } VALUE P4Result::FmtMessage( Error *e ) { if( apiLevel >= 68 ) // 2010.2 { P4Error *pe = new P4Error( *e ); return pe->Wrap( cP4Msg ); } // Otherwise, format it as a string StrBuf t; e->Fmt( t, EF_PLAIN ); return rb_str_new( t.Text(), t.Length() ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#10 | 14682 | Git Fusion |
Git Fusion branch management Imported from Git ghost-of-change-num: 960958 ghost-of-sha1: 005052ae424bd69f426f7209e741ca1c8c3253c7 ghost-precedes-sha1: ad052c71a568ef12165e143a6866ad9ceffbb4a1 parent-branch: None@960958 push-state: incomplete |
||
#9 | 14622 | jmistry |
Pull 10.2 changes to main Pick up missing changes in p10.2 and integrate to main. As part of the integrate I also moved the unit tests '16_streams.rb' and '17_streaming_handler.rb' because the integration introduced collisions with the unit test names. Updated MANIFEST with new names for unit tests and also added '98_unicode.rb', which was missing from it. |
||
#8 | 14608 | jmistry |
Add encoding to Strings As part of adding Ruby 1.9 support we need to associate the encoding for Ruby's strings from the server. This approach is similar to Sven's (in changelist 257263), where everything but the 'content' charset was set to 'utf8'. The content charset is picked up from P4CHARSET and this is used to translate any file content. Also disabled the Ruby 1.9 warning for each compile. User visible change to be documented in release notes. |
||
#7 | 14592 | Sven Erik Knop |
Enable P4-Ruby to compile and test with Ruby 1.9. The current solution is far from ideal because it is not possible to compile and test both Ruby 1.8 and Ruby 1.9 in parallel. The Makefile writes both artifacts and binaries to the same location. This means a user/tester/builder needs to choose on Ruby platform or ensure 'make clean' is called first. Many of the test cases also still fail in Ruby 1.9. We also need to investigate the Unicode story with Ruby 1.9 and see if the lessons learned from Python 3 can be applied somehow. Infrastructure change, no functional change yet. |
||
#6 | 14589 | Sven Erik Knop | Pulled P4Ruby p10.2 changes back to main. | ||
#5 | 14583 | psoccard | Added support for -Ztrack | ||
#4 | 14579 | tony |
Make new class P4::Message for returning Error objects to the user. Currently handles errors and warnings, but could potentially be used for output too (might bloat people's code though). Essentially, if you're using a 2010.2 or later client, or if you've set your api_level to 68 or higher, the P4#errors and P4#warnings arrays will be populated with P4::Message objects instead of strings. Users of older API's, or those who set their api_level to 67 or lower in their scripts will get the old behaviour. P4::Message objects have the following methods: severity() - returns the severity generic() - returns the generic code to_s() - converts the message to a string inspect() - returns a string showing the message details. User-visible enhancement documented in p4rubynotes.txt |
||
#3 | 14541 | tony |
Copyright notice housekeeping: update all notices to 2008, and correct start date from 1997 to 2001 when P4Ruby was first released from the public depot. No functional change |
||
#2 | 14521 | tony | Update copyright notices in all applicable P4Ruby files. | ||
#1 | 14480 | tony |
Add P4Ruby 1.5944 to main as start-point for the first productized release of P4Ruby |