Author: rschupp
Date: Thu Jan  1 15:27:22 2015
New Revision: 1648853

URL: http://svn.apache.org/r1648853
Log:
Perl bindings: document cancel callbacks and add some tests.

[in subversion/bindings/swig/perl/native]

* Client.pm: Move POD paragraphs about cancel calbacks into their own
  chapter so that we can refer to them from other PODs.
  Also fix the cancel arguments in an example.

* Repos.pm: Document cancel callbacks for dump_fs() and dump_fs2().

* t/1repos.t, t/3client.t: Add some tests for cancel callbacks.

Modified:
    subversion/trunk/subversion/bindings/swig/perl/native/Client.pm
    subversion/trunk/subversion/bindings/swig/perl/native/Repos.pm
    subversion/trunk/subversion/bindings/swig/perl/native/t/1repos.t
    subversion/trunk/subversion/bindings/swig/perl/native/t/3client.t

Modified: subversion/trunk/subversion/bindings/swig/perl/native/Client.pm
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/perl/native/Client.pm?rev=1648853&r1=1648852&r2=1648853&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/perl/native/Client.pm (original)
+++ subversion/trunk/subversion/bindings/swig/perl/native/Client.pm Thu Jan  1 
15:27:22 2015
@@ -55,8 +55,7 @@ SVN::Client - Subversion client function
                                            0,           #no_auth_cache
                                            0,           #trust_server_cert
                                            $config_category,
-                                           undef,       #cancel_func
-                                           undef)       #cancel_baton
+                                           undef)       #cancel_callback
     );
 
     # Use first argument as target and canonicalize it before using
@@ -1286,24 +1285,8 @@ sub log_msg {
 =item $client-E<gt>cancel(\&cancel)
 
 Sets the cancellation callback for the client context to a code reference that 
you
-pass.  It always returns the current codereference set.
-
-The subroutine pointed to by this value will be called to see if the operation
-should be canceled.  If the operation should be canceled, the function may
-return one of the following values:
-
-An svn_error_t object made with SVN::Error::create.
-
-Any true value, in which case the bindings will generate an svn_error_t object
-for you with the error code of SVN_ERR_CANCELLED and the string set to "By
-cancel callback".
-
-A string, in which case the bindings will generate an svn_error_t object for 
you
-with the error code of SVN_ERR_CANCELLED and the string set to the string you
-returned.
-
-Any other value will be interpreted as wanting to continue the operation.
-Generally, it's best to return 0 to continue the operation.
+pass. See L<"CANCELLATION CALLBACK"> below for details.
+It always returns the current codereference set.
 
 =cut
 
@@ -1489,6 +1472,25 @@ may_save.
 
 =back
 
+=head1 CANCELLATION CALLBACK
+
+This callback will be called periodically to see if the operation
+should be canceled.  If the operation should be canceled, the function may
+return one of the following values:
+
+An svn_error_t object made with SVN::Error::create.
+
+Any true value, in which case the bindings will generate an svn_error_t object
+for you with the error code of SVN_ERR_CANCELLED and the string set to "By
+cancel callback".
+
+A string, in which case the bindings will generate an svn_error_t object for 
you
+with the error code of SVN_ERR_CANCELLED and the string set to the string you
+returned.
+
+Any other value will be interpreted as wanting to continue the operation.
+Generally, it's best to return 0 to continue the operation.
+
 =head1 OBJECTS
 
 These are some of the object types that are returned from the methods

Modified: subversion/trunk/subversion/bindings/swig/perl/native/Repos.pm
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/perl/native/Repos.pm?rev=1648853&r1=1648852&r2=1648853&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/perl/native/Repos.pm (original)
+++ subversion/trunk/subversion/bindings/swig/perl/native/Repos.pm Thu Jan  1 
15:27:22 2015
@@ -42,9 +42,9 @@ object.
 
 =over
 
-=item $repos-E<gt>dump_fs($dump_fh, $feedback_fh, $start_rev, $end_rev, 
$incremental, $cancel_func, $cancel_baton)
+=item $repos-E<gt>dump_fs($dump_fh, $feedback_fh, $start_rev, $end_rev, 
$incremental, $cancel_callback)
 
-=item $repos-E<gt>dump_fs2($dump_fh, $feedback_fh, $start_rev, $end_rev, 
$incremental, $deltify, $cancel_func, $cancel_baton)
+=item $repos-E<gt>dump_fs2($dump_fh, $feedback_fh, $start_rev, $end_rev, 
$incremental, $deltify, $cancel_callback)
 
 Create a dump file of the repository from revision C<$start_rev> to C<$end_rev>
 , store it into the filehandle C<$dump_fh>, and write feedback on the progress
@@ -61,10 +61,9 @@ this flag is set, the first revision of
 be done with full plain text.  A dump with @a use_deltas set cannot
 be loaded by Subversion 1.0.x.
 
-According to svn_repos.h, the C<$cancel_func> is a function that is called
-periodically and given C<$cancel_baton> as a parameter to determine whether
-the client wishes to cancel the dump.  You must supply C<undef> at the very
-least.
+If C<$cancel_callback> is not C<undef>, it must be a code reference
+that is called periodically to determine whether the client wishes 
+to cancel the dump.  See L<SVN::Client/"CANCELLATION CALLBACK"> for details.
 
 Example:
 
@@ -83,13 +82,13 @@ Example:
     $repos->dump_fs2($fh, \*STDOUT,          # Dump file => $fh, Feedback => 
STDOUT
                      $start_rev, $end_rev,   # Revision Range
                      $incremental, $deltify, # Options
-                     undef, undef);          # Cancel Function
+                     undef);                 # Cancel Callback
 
     close $fh;
 
-=item $repos-E<gt>load_fs($dumpfile_fh, $feedback_fh, $uuid_action, 
$parent_dir, $cancel_func, $cancel_baton);
+=item $repos-E<gt>load_fs($dumpfile_fh, $feedback_fh, $uuid_action, 
$parent_dir, $cancel_callback);
 
-=item $repos-E<gt>load_fs2($dumpfile_fh, $feedback_fh, $uuid_action, 
$parent_dir, $use_pre_commit_hook, $use_post_commit_hook, $cancel_func, 
$cancel_baton);
+=item $repos-E<gt>load_fs2($dumpfile_fh, $feedback_fh, $uuid_action, 
$parent_dir, $use_pre_commit_hook, $use_post_commit_hook, $cancel_callback);
 
 Loads a dumpfile specified by the C<$dumpfile_fh> filehandle into the 
repository.
 If the dumpstream contains copy history that is unavailable in the repository,
@@ -113,11 +112,11 @@ hook before committing each loaded revis
 If C<$use_post_commit_hook> is set, call the repository's
 post-commit hook after committing each loaded revision.
 
-If C<$cancel_func> is not NULL, it is called periodically with
-C<$cancel_baton> as argument to see if the client wishes to cancel
-the load.
+If C<$cancel_callback> is not C<undef>, it must be a code reference 
+that is called periodically to determine whether the client wishes
+to cancel the load.  See L<SVN::Client/"CANCELLATION CALLBACK"> for details.
 
-You must at least provide undef for these parameters for the method call
+You must at least provide C<undef> for these parameters for the method call
 to work.
 
 Example:

Modified: subversion/trunk/subversion/bindings/swig/perl/native/t/1repos.t
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/perl/native/t/1repos.t?rev=1648853&r1=1648852&r2=1648853&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/perl/native/t/1repos.t (original)
+++ subversion/trunk/subversion/bindings/swig/perl/native/t/1repos.t Thu Jan  1 
15:27:22 2015
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
@@ -20,16 +20,18 @@
 #
 #
 
-use Test::More tests => 6;
+use strict;
+use warnings;
+
+use Test::More tests => 8;
 use File::Temp qw(tempdir);
 use File::Path qw(rmtree);
-use strict;
+use File::Spec;
 
-require SVN::Core;
-require SVN::Repos;
-require SVN::Fs;
-require SVN::Delta;
-use File::Path;
+use SVN::Core;
+use SVN::Repos;
+use SVN::Fs;
+use SVN::Delta;
 
 my $repospath = tempdir('svn-perl-test-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 
@@ -107,6 +109,26 @@ ok($main::something_destroyed, 'callback
 # TEST
 cmp_ok($fs->youngest_rev, '==', 3);
 
+open my $dump_fh, ">", File::Spec->devnull or die "open file sink: $!";
+
+my $feedback;
+open my $feedback_fh, ">", \$feedback or die "open string: $!";
+
+my $cancel_cb_called = 0;
+$repos->dump_fs2($dump_fh, $feedback_fh,
+                 0, $SVN::Core::INVALID_REVNUM,     # start_rev, end_rev
+                 0, 0,                              # incremental, deltify
+                 sub { $cancel_cb_called++; 0 });
+# TEST
+ok($cancel_cb_called, 'cancel callback was called');
+# TEST
+is($feedback, <<'...', 'dump feedback');
+* Dumped revision 0.
+* Dumped revision 1.
+* Dumped revision 2.
+* Dumped revision 3.
+...
+
 END {
 diag "cleanup";
 rmtree($repospath);

Modified: subversion/trunk/subversion/bindings/swig/perl/native/t/3client.t
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/perl/native/t/3client.t?rev=1648853&r1=1648852&r2=1648853&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/perl/native/t/3client.t (original)
+++ subversion/trunk/subversion/bindings/swig/perl/native/t/3client.t Thu Jan  
1 15:27:22 2015
@@ -20,7 +20,7 @@
 #
 #
 
-use Test::More tests => 297;
+use Test::More tests => 301;
 use strict;
 
 # shut up about variables that are only used once.
@@ -1119,6 +1119,35 @@ isa_ok($ph2,'HASH','propget returns HASH
 is(scalar(keys %$ph2),0,
    'No properties after deleting a property');
 
+# test cancel callback
+my $cancel_cb_called = 0;
+$ctx->cancel(sub { $cancel_cb_called++; 0 });
+my $log_entries_received = 0;
+$ctx->log5($reposurl,
+              'HEAD',['HEAD',1],0, # peg rev, rev ranges, limit
+              1,1,0, # discover_changed_paths, strict_node_history, 
include_merged_revisions
+              undef, # revprops
+              sub { $log_entries_received++ });
+# TEST
+ok($cancel_cb_called, 'cancel callback was called');
+# TEST
+is($log_entries_received, $current_rev, 'log entries received');
+
+my $cancel_msg = "stop the presses";
+$ctx->cancel(sub { $cancel_msg });
+$svn_error = $ctx->log5($reposurl,
+              'HEAD',['HEAD',1],0, # peg rev, rev ranges, limit
+              1,1,0, # discover_changed_paths, strict_node_history, 
include_merged_revisions
+              undef, # revprops
+              sub { });
+# TEST
+isa_ok($svn_error, '_p_svn_error_t');
+# TEST
+is($svn_error->message, $cancel_msg, 'operation was cancelled');
+$svn_error->clear(); # don't leak this
+$ctx->cancel(undef); # reset callback
+
+
 SKIP: {
     # This is ugly.  It is included here as an aide to understand how
     # to test this and because it makes my life easier as I only have


Reply via email to