You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Jim Mahoney <ma...@marlboro.edu> on 2005/11/28 02:22:52 UTC

my experience with SWIG and a Perl module that came out of it

I'm in the process of writing a web application that's
using subversion, and as part of that project have been
calling some of the svn client routines from within Perl.

Since the documentation on how to do so felt a bit spotty,
and since I had to do some tweaking to get it to work at all,
others trying to do the same might find the attached Perl
module helpful.  It only does a few basic tasks, but it
does include some installation notes and comments on
encountered problems.

So, for what they're worth, attached is

 SVN_Client_Simple.pm
 test.pl

Regards,

 Jim Mahoney
 (mahoney@marlboro.edu)

---- installation of Perl, SWIG, and Subversion under linux ----

 $ tar zxf perl-5.8.7.tar.gz
 $ cd perl-5.8.7
 $ ./configure.gnu; make && make test && make install
 $ cd ..

 $ tar zxf swig-1.3.27.tar.gz
 $ cd swig-1.3.27
 $ ./configure --with-perl5=/usr/bin/perl; make && make install
 $ cd ..

 $ tar zxf subversion-1.1.4.tar.gz
 $ cd subversion-1.1.4
 $ ./configure PERL=/usr/bin/perl
 $ make && make install
 # This puts PATH_MAX and APR_PATH_MAX into subversion's SWIG bindings
 # manually; "make swig-pl" crashed otherwise.
 # I found my system's values in /user/include/linux/limits.h.
 $ perl -pi -e 's{(%include apr.h)}{#define PATH_MAX 4096\n#define
APR_PATH_MAX PATH_MAX\n$1}' subversion/bindings/swig/apr.i
 make swig-pl;
 # make check-swig-pl  (1 of 144 tests failed.)
 make install-swig-pl
 $ cd ..

---- use of SVN_Client_Simple.pm from within perl code -----

 use SVN_Client_Simple qw( svn_log svn_cat svn_commit);

 my $filename = '/path/to/working/copy/of/file.txt';
 my $revision = 123;        # or 'HEAD' or '{2005-03-12}';

 # Fetch a file's version history from the repository.
 # Alternate form : $history=svn_log($filename,$from,$to);
 my $history   = svn_log($filename);
 print "Revision history for file '$filename':\n";
 foreach my $record (@$history){
   for my $key qw(revision date author message){
     print "  $key: '" . $record->{$key} . "'\n";
   }
 }

 # Fetch an old revision of a file's text from the repository.
 # If an error occurs (eg that file doesn't exist in that revision)
 # then the empty string is returned.
 my $text = svn_cat($filename, $revision);

 # Put changes to a (possibly new) file into the repository.
 # Equivalent to
 #   $ svn add $filename
 #   $ svn commit $filename -m $message
 # If $message is omitted, it defaults to 'from SVN_Client_Simple'.
 my $error_msg = svn_commit($filename, $message);
 if ($error_msg){
   die("Error during subversion commit : '$error_msg'.\n");
 }

------------------------------------------------------------