11.07.2015 Views

Version Control with Subversion - Login

Version Control with Subversion - Login

Version Control with Subversion - Login

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Embedding <strong>Subversion</strong>against APR, must call apr_initialize() to initialize the APR subsystem, and thenmust create and manage pools for use <strong>with</strong> <strong>Subversion</strong> API calls, typically by usingsvn_pool_create(), svn_pool_clear(), and svn_pool_destroy().Programming <strong>with</strong> Memory PoolsAlmost every developer who has used the C programming language has at somepoint sighed at the daunting task of managing memory usage. Allocating enoughmemory to use, keeping track of those allocations, freeing the memory when you nolonger need it—these tasks can be quite complex. And of course, failure to do thosethings properly can result in a program that crashes itself, or worse, crashes the computer.Higher-level languages, on the other hand, either take the job of memory managementaway from you completely or make it something you toy <strong>with</strong> only when doingextremely tight program optimization. Languages such as Java and Python usegarbage collection, allocating memory for objects when needed, and automaticallyfreeing that memory when the object is no longer in use.APR provides a middle-ground approach called pool-based memory management. Itallows the developer to control memory usage at a lower resolution—per chunk (or“pool”) of memory, instead of per allocated object. Rather than using malloc() andfriends to allocate enough memory for a given object, you ask APR to allocate thememory from a memory pool. When you're finished using the objects you've createdin the pool, you destroy the entire pool, effectively de-allocating the memory consumedby all the objects you allocated from it. Thus, rather than keeping track of individualobjects that need to be de-allocated, your program simply considers the generallifetimes of those objects and allocates the objects in a pool whose lifetime (thetime between the pool's creation and its deletion) matches the object's needs.URL and Path RequirementsWith remote version control operation as the whole point of <strong>Subversion</strong>'s existence, itmakes sense that some attention has been paid to internationalization (i18n) support. Afterall, while “remote” might mean “across the office,” it could just as well mean “across theglobe.” To facilitate this, all of <strong>Subversion</strong>'s public interfaces that accept path argumentsexpect those paths to be canonicalized—which is most easily accomplished by passingthem through the svn_path_canonicalize() function—and encoded in UTF-8. Thismeans, for example, that any new client binary that drives the libsvn_client interfaceneeds to first convert paths from the locale-specific encoding to UTF-8 before passingthose paths to the <strong>Subversion</strong> libraries, and then reconvert any resultant output paths from<strong>Subversion</strong> back into the locale's encoding before using those paths for non-<strong>Subversion</strong>purposes. Fortunately, <strong>Subversion</strong> provides a suite of functions (see subversion/include/svn_utf.h)that any program can use to do these conversions.Also, <strong>Subversion</strong> APIs require all URL parameters to be properly URI-encoded. So, insteadof passing file:///home/username/My File.txt as the URL of a file named MyFile.txt, you need to pass file:///home/username/My%20File.txt. Again, <strong>Subversion</strong>supplies helper functions that your application canuse—svn_path_uri_encode() and svn_path_uri_decode(), for URI encoding anddecoding, respectively.Using Languages Other Than C and C++If you are interested in using the <strong>Subversion</strong> libraries in conjunction <strong>with</strong> something otherthan a C program—say, a Python or Perl script—<strong>Subversion</strong> has some support for this viathe Simplified Wrapper and Interface Generator (SWIG). The SWIG bindings for <strong>Subversion</strong>are located in subversion/bindings/swig. They are still maturing, but they areusable. These bindings allow you to call <strong>Subversion</strong> API functions indirectly, using wrap-215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!