p4clientapi.cpp #46

  • //
  • guest/
  • perforce_software/
  • p4ruby/
  • main/
  • p4clientapi.cpp
  • Commits
# Change User Description Committed
#46 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
#45 14676 tony Rework P4Ruby unit tests so they they are actually units.
Now the
test order is irrelevant as all tests are standalone. Tidied up
the code formatting as well and removed all the tabs from the ruby
sources files. Added a modeline for vim users so consistent
indentation will be used.
#44 14659 tony Add ignore file support to P4Ruby.
This change adds
three new methods:

    P4#ignore_file        - Return current ignore file
    P4#ignore_file=        - Set ignore file name
    P4#ignored?        - Test if a path is ignored

It also removes the check which objected to the use of Ruby 2.0
since we now support it. Now we simply check that you're not
using 2.1 (still a development release).
#43 14656 tony Squelch annoying compiler warnings when building P4Ruby
#42 14650 jmistry Progress indicator for P4Ruby.

There is a new class P4::Progress that is set up to be subclassed by a user.
It has the following interface and P4Ruby expects the following class methods to
be defined by the user (even if it's an empty implementation):

    class Progress:
        def init(type)
        end

        def description(description, units )
        end

        def total( total )
        end

        def update( position )
        end

        def done( fail )
        end
    end

Users need to create a subclass of P4::Progress and assign an instance to P4
to enable the progress indicator:

class MyProgress < P4::Progress
    def update(pos):
       # do something with the value here

    # other methods

p4 = P4.new
p4.progress = MyProgress.new

New feature to be documented in the release notes.
#41 14626 jmistry raise exceptions in P4#run_resolve

Any exceptions raised during the block passed to P4#run_resolve were silently
swallowed.  We still use 'rb_protect()' to run the block in the user's script;
however, we now stash where the exception happened in 'rubyExcept' (a member of
'ClientUserRuby') instead of just a local variable.  After running a command, I
now run 'ClientUserRuby::RaiseRubyException()' - if an exception has been
caught by 'rb_protect()' we now run 'rb_jump_tag()' to jump to the exception
and raise it up.

User visible change to be documented in release notes.
#40 14624 jmistry Pull p11.1 changes back to main
#39 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.
#38 14611 jmistry Support setting values in the registry through P4Ruby.
The command P4.set_env( var, val ) will set a registry variably on platforms
that support this action or through an exception on Unix.
The command P4.set_env( var ) resets a registry variable.

Updated unit test '02_environment.rb' to include registry set/check.

User visible change to be documented in release notes.
#37 14609 jmistry Fix track error

P4Ruby now raises a P4Exception, instead of a Ruby warning if a user tries to
change track output after connecting. The test case has been updated to suppress
this because we expect the error.

Also removed debug message (accidently) left in streams test case.
#36 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.
#35 14594 jmistry [P4Ruby] enable streams by default

Fixed S_STREAMS bit mask to 0x0040 and changed the initial
state S_INITIAL_STATE bit 0x0041 to enable streams by default.

Added logic to set streams for API levels greater than 69

Add streams test case - tests the output of 'P4::run_depots' for different
settings of 'P4::streams' and 'P4::api_level'
#34 14593 Sven Erik Knop P4Ruby implementation of OutputHandler.
Also, debug is now treated as a normal attribute and can be read.

Test cases still missing.

New functionality, to be documented in release notes.
#33 14586 tony Streams method tidying.
Change P4#streams into P4#streams? as it
returns a boolean, and change the implementation to use
SetVar() instead of SetProtocol() now that Mark's made it work for
us.

Change to undocumented functionality
#32 14584 psoccard Added method to enable streams
#31 14583 psoccard Added support for -Ztrack
#30 14581 Sven Erik Knop Fixed error handling in P4Ruby.
The error message string did not get properly set in the exception and P4Message
object. This is because theP4API Error class does not have a proper copy
constructor. Since it has a decent assignment operator, I gave P4Error an Error
field and removed the superclass, which solved the problem and also made the
code more readable.
I also moved the Reset of the Result object in P4ClientAPI before the connection
check, so that 'not connected' can be shown in the exception instead of the
previous exception in case the connection is lost.

Bug fix to previously unreleased behaviour.
#29 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
#28 14571 tony Tidy P4Ruby's connection state management.
P4ClientApi was accumulating
a lot of 'int' flags. This change combines them all into a bitmask with some
methods to encapsulate the manipulation of the mask.

I've also removed the code which worked around a very old and obscure
protocol bug in 2000.1/2000.2 servers. Anyone using a server that old
doesn't deserve the modern P4Ruby.

To test P4#server_case_sensitive? I have adapted the test suite so that
the server it runs uses the -C1 flag - so it's case-folding on all
platforms. The reason for this is that it enables the tests to  succeed
on Windows and Mac OS where case-folding is the norm.

Infrastructure change only. No functional change.
#27 14570 tony Add new P4#server_unicode?
method to P4Ruby. This allows you to
test for unicode mode servers once you've executed at least one
Perforce command. That's because the server only sends the
protocol block in response to the first command these days, and
that's when we'll find out if unicode mode is enabled.
#26 14564 tony Revise change 214445 (bug fix for incorrectly handled disconnection
by the server). The previous change reduced the initCount but in
doing so, prevented ClientApi::Final() from being called. This change
calls the Disconnect() method instead, and that takes care of both
the ClientApi::Final() call, and the decrementing of the initCount

User-visible bug fix, documented in p4rubynotes.txt
#25 14562 tony Followup to 21449: reset server2 variable on connect too, to ensure
that old values aren't used between connect and the first command
executed. Well spotted Sven!
#24 14560 tony Add a P4#server_case_sensitive?
method that returns true if the server
is base sensitive, and false otherwise. Raises a P4Exception if it's
used before a command has been executed.

User-visible enhancement documented in p4rubynotes.txt
#23 14559 tony Previously the initCount variable was not being decremented properly
when the server disconnects and P4#connected? was called. Now
P4#connected will correctly decrement the variable once it sees that
the connection has been dropped.

User-visible bug fix documented in p4rubynotes.txt
#22 14558 tony Add undoc'd P4#protocol( var, val) method for calling ClientApi::SetProtocol().

I would prefer to have named methods for the important protocol variables,
or to wrap their use in other ways (see tag and specstring), but for
tunables and other ad-hoc settings, sometimes direct access is required.

User-visible change, not documented anywhere.
#21 14543 tony Pull P4CHARSET initialization fix from p08.2

Integration-only change
#20 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
#19 14539 tony Make sure P4Ruby picks up P4CHARSET from the environment.

Previously, our cached copy of the charset was not being
initialised, and that's why it wasn't being picked up. Rather
than initialise it, I've chosen to simply eliminate the cached
copy, and use ClientApi to store it. Simpler, and more reliable.

User-visible bug fix documented in p4rubynotes.txt

Note, as the job contains another request, it stays open for now.
#18 14531 tony Add P4#env() method to allow users to read the P4 object's environment
using the same rules that P4 does. This allows values from P4CONFIG
files to be picked up automatically.

P4#cwd=() now calls Enviro::Config() to reload any config file when
the user changes directory.

User-visible enhancement documented in p4rubynotes.txt
#17 14526 tony Make P4#charset=( aString ) always raise an exception if the charset
specified is invalid. Since the '=' methods always return their
arguments, we don't have better way to say no than raising an
exception.
#16 14521 tony Update copyright notices in all applicable P4Ruby files.
#15 14513 tony Remove all compatibility code with versions of the API older
than 2006.2 from both P4Perl and P4Ruby. We're insisting that
people use a 2006.2 or later API for this first release, and will
support the current API, and the previous two releases going forward.

Also stripped out some reference Ruby code that was still lurking
in P4Perl (commented out, obviously).

Also ensured that both Makefile.PL and p4conf.rb insist on the
minimum API level, and warn the user if they're attempting to
build with an even newer release of the API.
#14 14512 tony Pass debug down to spec manager.
Re-enables spec debugging.

No functional change
#13 14511 tony Add P4#api_level method to get the current API level.

User-visible new feature to be documented in Scripting Interfaces
Guide.
#12 14505 tony Clear the specMgr on Disconnect() so that if they disconnect, and
then switch to a different server and connect again using the
same P4 instance (probably not a good idea), then at least we
won't cache spec definitions across server connections.
#11 14504 tony Disambiguate my specs: rename AddSpec() to AddSpecDef() and
HaveSpec() to HaveSpecDef() since those methods deal with
manipulating the specdef cache rather than producing specs
themselves.
#10 14502 tony Rework spec handling somewhat so that:

(a) P4Ruby knows about the default spec types for 2007.2 so it
    doesn't have to connect to the server to parse and format specs,
    and nor does it have to do the ugly hack of running a 'p4 xxx -o'
    and discarding the result just to get the specDef.

(b) If a user's got a custom spec then the spec cache will be updated
    if they fetch an object of that type. So basically, if the
    server's given us a specdef for a class of spec, we use it.
    Otherwise, we fall back on the builtin defaults

This reworks SpecMgr quite a bit - renaming methods so it's clearer
what they do, and making it own the spec cache. We also pass the
SpecMgr object created by P4ClientApi down to ClientUserRuby now,
so that whenever the server sends us a spec, we can update the cache.
#9 14501 tony Followup to change 138913: load the default ticket file, or the
one specified in P4TICKETS at construction so that value is
right from the start.  I thought this wasn't possible in the
current API because it's not in ClientApi, but using HostEnv
and Enviro, it can be done easily.
#8 14500 tony Add P4#version= and P4#version methods to get/set the version of
the program.

User-visible change to be documented in Scripting Interface Guide
#7 14498 tony Add P4#ticket_file and P4#ticket_file= methods to get and set the
ticket file. Note that P4#ticket_file will only return something if
a value has been previously set using P4#ticket_file=(). There's
no way, in the existing P4 API to get the current ticket file.

User-visible change to be documented in Scripting Interfaces Guide
#6 14494 tony Add P4#maxlocktime=( int ) method to allow users to specify the
maximum number of milliseconds for which locks may be held.
#5 14493 tony Turn on tagged mode by default, and make parse_forms mode
always on (it only works when tagged mode is on too). Now
users can turn tagged mode off if they want to by calling:

    p4.tagged = false

and turn it back on by calling:

    p4.tagged = true

You can test the current state of affairs using:

    p4.tagged?

User-visible change to be documented in Scripting Interface Guide
#4 14487 tony Add P4#connected?
to test whether or not the session (a) has been
connected and (b) has not been dropped.

Functional change to unreleased code.
#3 14483 tony Method name rationalisation, part 1.
All the methods with names ending
with '?' that do not return booleans now have the '?' dropped. This
will be used to ensure consistency across the scripting interfaces.

Added P4#prog() -> <string> to partner P4#prog=( <string> )

Removed some redundant aliases that we're dropping support for in
future versions
#2 14481 tony Update P4Ruby in main with fixes made to public depot
#1 14480 tony Add P4Ruby 1.5944 to main as start-point for the first
productized release of P4Ruby