1.4k likes | 1.54k Views
Automating Subversion with Bindings. @ BenReser http:// svn.ms / autosvnslides. About Ben. Subversion Committer working at WANdisco since 2012.
E N D
Automating Subversion with Bindings @BenReser http://svn.ms/autosvnslides
About Ben Automating Subversion with Bindings Subversion Committer working at WANdisco since 2012. Started working on Perl Bindings in 2003 to automate Subversion as a replacement for CVS. Never finished the project that inspired the work and ended up working on Subversion itself. My work isn’t limited to bindings anymore and has expanded across the different parts of Subversion including acting as the Release Manager.
What is Subversion… Automating Subversion with Bindings An implementation of a Version Control System?
What is Subversion… Automating Subversion with Bindings An implementation of a Version Control System? Libraries that implement a Version Control System.
What is Subversion… Automating Subversion with Bindings • An implementation of a Version Control System? • Libraries that implement a Version Control System. • Written in C
Layered Library Design Automating Subversion with Bindings
Layered Library Design - Client Automating Subversion with Bindings • Client • Implements the basic functions of a client. Knows about working copies and uses the…
Layered Library Design - Client Automating Subversion with Bindings • Client • Implements the basic functions of a client. Knows about working copies and uses the… • WC (Working Copy) • Implements the working copy
Layered Library Design - Client Automating Subversion with Bindings • Client • Implements the basic functions of a client. Knows about working copies and uses the… • WC (Working Copy) • Implements the working copy • RA (Repository Access) • Implements protocol to talk to (possibly remote) repository • Local (file://) • Neon (http(s):// 1.7.x and older was called DAV in 1.4.x and older, gone in 1.8.x) • Serf (http(s):// 1.5.x and newer) • SVN (svn://)
Layered Library Design - Server Automating Subversion with Bindings • Repos • Repository interface which implements high level repository functionality and uses…
Layered Library Design - Server Automating Subversion with Bindings • Repos • Repository interface which implements high level repository functionality and uses… • FS • File system implementation to store a repository • FS_Base (Berkeley DB) • FS_FS (non database implementation)
Layered Library Design – Misc. Automating Subversion with Bindings • Subr • Miscellaneous subroutines
Layered Library Design – Misc. Automating Subversion with Bindings • Subr • Miscellaneous subroutines • Delta • Tree and byte-stream differencing routines
Layered Library Design – Misc. Automating Subversion with Bindings • Subr • Miscellaneous subroutines • Delta • Tree and byte-stream differencing routines • Diff • Contextual differencing and merge routines
What are Bindings? Automating Subversion with Bindings • Access Subversion C APIs from other Higher Level Programming Languages
What are Bindings? Automating Subversion with Bindings • Access Subversion C APIs from other Higher Level Programming Languages • Somewhat easier to use than C
What are Bindings? Automating Subversion with Bindings • Access Subversion C APIs from other Higher Level Programming Languages • Somewhat easier to use than C • Provide an interface that somewhat matches the Higher Level Language’s idioms
What are Bindings? Automating Subversion with Bindings • Access Subversion C APIs from other Higher Level Programming Languages • Somewhat easier to use than C • Provide an interface that somewhat matches the Higher Level Language’s idioms • May even hide some annoying details from using the libraries
Can’t I Just Script The Client? Automating Subversion with Bindings • The client tries to have machine readable formats
Can’t I Just Script The Client? Automating Subversion with Bindings • The client tries to have machine readable formats • I recently used something like this to try and find a bug in diff –summarize: (svn log $URL | grep -Eo '^r[0-9]+ \| ' | sed 's/[^0-9]//g') | while read rev; do svn diff --summarize $URL -c $rev; done
Can’t I Just Script The Client? Automating Subversion with Bindings • It worked great until it ran into this output: svn log –c 933481 https://svn.apache.org/repos/asf/subversion/trunk ------------------------------------------------------------------------ r933481 | gstein | 2010-04-12 21:20:50 -0700 (Mon, 12 Apr 2010) | 27 lines Add some new methods to the Sandbox class for performing simple, unverified operations. Also introduce deep magic with svntest.main.make_log_msg() to produce log messages that show the source of the command invocation. These automated log messages look like: ---- r2 | jrandom | 2010-04-12 23:57:10 -0400 (Mon, 12 Apr 2010) | 1 line File './schedule_tests.py', line 543, in status_add_deleted_directory ----
What about XML? Automating Subversion with Bindings • The client supports XML output with --xml on most commands.
What about XML? Automating Subversion with Bindings • The client supports XML output with --xml on most commands. • XML is hard to parse correctly • Regexps aren’t reliable • XSLT is a pain to write • XML parsers are far from easy to drive
Command behavior changes Automating Subversion with Bindings • We try to avoid changing the output and behavior of commands.
Command behavior changes Automating Subversion with Bindings • We try to avoid changing the output and behavior of commands.
Command behavior changes Automating Subversion with Bindings • We try to avoid changing the output and behavior of commands. • svnmergeinfo prior to 1.8.0 behaved as though --show-revs=merged was passed if no --show-revs option was passed. In 1.8.x this shows a graph.
Greater capabilities Automating Subversion with Bindings • We can implement functionality that the command line client doesn’t have. • Examples: • ViewVC • Subclipse • control-chars.py hook-script
Why not use Bindings? Automating Subversion with Bindings • Poor documentation
Why not use Bindings? Automating Subversion with Bindings • Poor documentation • Need to install them
Why not use Bindings? Automating Subversion with Bindings • Poor documentation • Need to install them • Expose internal details that may be hard to understand
Why not use Bindings? Automating Subversion with Bindings • Poor documentation • Need to install them • Expose internal details that may be hard to understand • Not always updated for the latest features
What Bindings Are Available Automating Subversion with Bindings • SWIG • Python • Perl • Ruby • JavaHL • ctypes-python • SVNKit • pySVN
What is SWIG? Automating Subversion with Bindings • Simplified Wrapper and Interface Generator
What is SWIG? Automating Subversion with Bindings • Simplified Wrapper and Interface Generator • Partly automated generator
What is SWIG? Automating Subversion with Bindings • Simplified Wrapper and Interface Generator • Partly automated generator • Acts like a specialized C compiler
What is SWIG? Automating Subversion with Bindings • Simplified Wrapper and Interface Generator • Partly automated generator • Acts like a specialized C compiler • Only needed at interface generation time
How To Install Bindings Automating Subversion with Bindings Windows Mac RedHat based Linux Debian based Linux Other
Windows Automating Subversion with Bindings • WANdisco installer • Provides swig-python (for Python 2.7.2) and JavaHL • Alagazam.net • Provides swig-python, swig-perl, swig-ruby, and JavaHL
RedHat based Linux Automating Subversion with Bindings • WANdisco packages • subversion-python (SWIG) • subversion-ruby (subversion 1.8.x only) • subversion-perl • subversion-javahl • OS Packages • Older but usually available and named same as above.
Debian based Linux Automating Subversion with Bindings • WANdisco packages • python-subversion (SWIG) • libsvn-ruby (and libsvn-ruby1.8 for Ruby 1.8) • libsvn-perl • libsvn-java (JavaHL) • OS Packages • Older but usually available and named same as above.
Mac Automating Subversion with Bindings • WANdisco installer • Provides swig-python, swig-perl, swig-ruby and JavaHL • MacPorts • subversion-javahlbindings • subversion-perlbindings-5.16 (number is perl version) • subversion-python27bindings (number is python version) • subversion-rubybindings • Homebrew • can provide JavaHL, swig-perl, swig-python, and swig-ruby • Xcode • Command line tools • old but includes swig-python, swig-perl and swig-ruby
Other Automating Subversion with Bindings • WANdisco packages should have Bindings for most OSes • *NIX platforms build it yourself by: • [usual Subversion build instructions] • make $binding • make check-$binding • make install-$binding where $binding can be: javahl swig-pl swig-py swig-rb Don’t use do parallel builds of bindings (-j option to make)
Build It Yourself - SWIG Automating Subversion with Bindings • On the Mac you need to do this before the normal Subversion instructions due to a bug in our API that makes the bindings fail to compile (requires SWIG, libtool and autoconf): • make extraclean • ./autogen.sh
Build It Yourself - SWIG Automating Subversion with Bindings • On the Mac you need to do this before the normal Subversion instructions due to a bug in our API that makes the bindings fail to compile (requires SWIG, libtool and autoconf): • make extraclean • ./autogen.sh • May need the same instructions on other platforms if you get an error about an undeclared symbol starting with SVN_AUTH
Build It Yourself - SWIG Automating Subversion with Bindings • On the Mac you need to do this before the normal Subversion instructions due to a bug in our API that makes the bindings fail to compile (requires SWIG, libtool and autoconf): • make extraclean • ./autogen.sh • May need the same instructions on other platforms if you get an error about an undeclared symbol starting with SVN_AUTH • To use Ruby 1.9 need Subversion 1.8.x
Build It Yourself - SWIG Automating Subversion with Bindings • On the Mac you need to do this before the normal Subversion instructions due to a bug in our API that makes the bindings fail to compile (requires SWIG, libtool and autoconf): • make extraclean • ./autogen.sh • May need the same instructions on other platforms if you get an error about an undeclared symbol starting with SVN_AUTH • To use Ruby 1.9 need Subversion 1.8.x • Python 3 doesn’t work
Build It Yourself - JavaHL Automating Subversion with Bindings • Need --enable-javahl passed to configure