Implementing new versioning schemes

The first versioning scheme is “Simple File Versioning”. It’s useful on its own but also serves as a template for how to implement new versioning schemes. The versioning stuff is modular and can be extended simply by adding new types that implement the Versioner interface.

To start out, simply copy the file to a new file in the same directory. You will need to rename the type and constructor functions and modify the code in init() to register the new constructor function with a unique name.

The constructor function is passed a map[string]string containing parameters from the configuration. Assuming you named your type Custom and registered it with the name custom, it could be activated on a repository with the following elements in config.xml:

 <repository id="wt2" directory="~/wt2">
    <versioning type="custom">
        <param key="foo" value="bar" />

The constructor would receive a map[string]string{"foo": "bar"} object.

The Archive() method is called each time before a file would be replaced or deleted. It is expected to move the file to an archive of some sort (or deleted if the relevant versioning algorithm decides it is not to be saved). After a successfull run of Archive() the file name given as the parameter should no longer exist.