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>svn.client.svn_client_status2(wc_path, revision, _status_callback,svn.core.svn_depth_infinity, verbose,0, 0, 1, ctx)def usage_and_exit(errorcode):"""Print usage message, and exit <strong>with</strong> ERRORCODE."""stream = errorcode and sys.stderr or sys.stdoutstream.write("""Usage: %s OPTIONS WC-PATHOptions:--help, -h : Show this usage message--verbose, -v : Show all statuses, even uninteresting ones""" % (os.path.basename(sys.argv[0])))sys.exit(errorcode)if __name__ == '__main__':# Parse command-line options.try:opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"])except getopt.GetoptError:usage_and_exit(1)verbose = 0for opt, arg in opts:if opt in ("-h", "--help"):usage_and_exit(0)if opt in ("-v", "--verbose"):verbose = 1if len(args) != 1:usage_and_exit(2)# Canonicalize the repository path.wc_path = svn.core.svn_path_canonicalize(args[0])# Do the real work.try:do_status(wc_path, verbose)except svn.core.<strong>Subversion</strong>Exception, e:sys.stderr.write("Error (%d): %s\n" % (e.apr_err, e.message))sys.exit(1)As was the case in Example 8.2, “Using the Repository layer <strong>with</strong> Python”, this program ispool-free and uses, for the most part, normal Python datatypes. The call tosvn_client_ctx_t() is deceiving because the public <strong>Subversion</strong> API has no such function—thisjust happens to be a case where SWIG's automatic language generation bleedsthrough a little bit (the function is a sort of factory function for Python's version of the correspondingcomplex C structure). Also note that the path passed to this program (like thelast one) gets run through svn_path_canonicalize(), because to not do so runs therisk of triggering the underlying <strong>Subversion</strong> C library's assertions about such things, whichtranslates into rather immediate and unceremonious program abortion.SummaryOne of <strong>Subversion</strong>'s greatest features isn't something you get from running its commandlineclient or other tools. It's the fact that <strong>Subversion</strong> was designed modularly and providesa stable, public API so that others—like yourself, perhaps—can write custom software thatdrives <strong>Subversion</strong>'s core logic.In this chapter, we took a closer look at <strong>Subversion</strong>'s architecture, examining its logical layersand describing that public API, the very same API that <strong>Subversion</strong>'s own layers use tocommunicate <strong>with</strong> each other. Many developers have found interesting uses for the <strong>Subversion</strong>API, from simple repository hook scripts, to integrations between <strong>Subversion</strong> andsome other application, to completely different version control systems. What unique itchwill you scratch <strong>with</strong> it?221

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

Saved successfully!

Ooh no, something went wrong!