Clone wiki

hgsubversion / Design


This is a 20k feet view of the code right now. This may improve with time, or the clarity of the code may improve to a point where such things are less necessary.

This page is out of date; some of the modules mentioned here no longer exist.


Subcommands are created by using the util.register_subcommand decorator to add the function to the lookup table used in svncommand. The docstring is the help text that will be displayed by hg svn help.


demandimport is used by Mercurial to reduce startup time. This has the slight problem for hgsubversion that subcommands in files other than won't be found (because the decorator will not execute) until too late. The fix is code like this at the top of

# dirty trick to force demandimport to run my decorator anyway.
from utility_commands import print_wc_url

What happens here is that demandimport evaluates the utility_commands module during import of svncommand. This causes the decorator to run at the correct time, preventing missing commands.


This is where a special editor subclass lives. This is the editor that is driven by libsvn_ra when replay is used. If the server does not support replay, this code is still used in some places, which is probably a good candidate for a refactor at some point in the future.


A lot of the magic happens here. hgsubversion actually started out as an experiment playing around, and early versions were actually just this wrapper around the lower-level Subversion APIs. The goal is for this package to transparently work on both the ctypes bindings for Subversion (not merged to trunk as of this writing) and the SWIG bindings. This is the package with the best automated test coverage, provided by


Lots more could be used. Real automated tests of the actual conversion would be a great way to help the project. At present, the best way to test major changes are to use a local svnsynced mirror of a repository to convert from, and the verify_all_revisions command to double-check the results. Note that you can force hgsubversion to pretend there is no replay support by passing the --stupid flag to svnclone and pull, which allows testing of non-replay changes even locally.