Using Subversion to manage Office files
Because Subversion works best (and can track) plain text files, it is not well adapted for versioning normal Microsoft Office or LibreOffice/OpenOffice documents. However, both are actually zipped XML files. Therefore, it is possible both directly (binary) and using flat XML text (full version control/merge support).
Microsoft Office
For Microsoft Office, there are extensions for Subversion: Msofficesvnf, OfficeSVN and MagnetSVN.
Also, TortoiseSVN can use native Microsoft Word
"compare versions" tool to check for differences between versions. Check out
the Diff-Scripts
in the TortoiseSVN installation directory. Note that these
scripts are js and can be blocked by corporate or university security policy:
ask the IT!
Subversion keywords
Subversion keywords (properties) can be managed in Microsoft Word files using SvnProperties4MSOffice.
For more information see https://gotomation.info/2019/01/svn-version-control-office-documents/.
If special software for adapting Office files is not used, it is recommended to use Microsoft uncompressed XML formats for all outputs. While they take more disk space (because it is unzipped), these are plain text XML, so Subversion treats them very efficiently. Also, svn keywords/tags can be used within the text without any additional tools.
LibreOffice or OpenOffice
For LibreOffice, the easiest way is to use .fodt format for saving the document (instead of .odt or .docx), FODT is a flat XML format. A drawback is that it is unzipped and takes much more disk space. But Subversion does not store all versions of the whole file, it saves effectively differences between the versions. Therefore, there is little or no overhead within the version control system of working with fodt files.
Quite importantly, it is then trivial to add keywords to the fodt
file on the svn system. Then, it is easy to include normal svn
keywords/tags] such as $Revision 1234$
into whenever needed into
the fodt file and it will autoupdate on every commit without any
additional tools. But note that the whole tag $Revision 1234$
must have the same formatting (i.e. no bold/italic/other font within
and including the $ $
delimiters).
For more information see https://wiki.documentfoundation.org/Libreoffice_and_subversion and https://wiki.documentfoundation.org/Svn:keywords.
Conflicts
To avoid conflicts when several people are working concurrently with svn-tracked files, use svn locks. This is because the files are like binary and cannot be easily merged, unlike normal plain text code. In fact, they could be merged, but do not always expect merge to work as expected because the text file includes complex tags and these may be broken at merge.
It is also difficult to resolve conflicts visually. A useful trick is
to set this property on the file: svn propset svn:needs-lock "true"
file_name.fodt
. Then, any svn update
will result this file becoming
read-only. To allow editing, file lock must be enabled. This ensures that
only one user can edit the file at a time.
How differences between versions can be checked?
Because the Libreoffice files are not just text, checking differences is not trivial. Normal diff tool will result in lots of messy XML differences.
But there is a Linux bash script that helps comparing the files through converting FODT to PDF and then running diffpdf utility:
There is also a Windows/DOS batch script that does this trick:
The script requires diffpdf
program that is found in most Linux
distributions. A Windows version is open source but id not normally distributed
in the binary ".exe" form
How to use diffodt script
-
Compare working copy with the latest revision from svn:
diffodt paper.fodt
-
Compare the working document with r9925:
diffodt 9925 paper.fodt
-
Compare two specific versions of the document:
diffodt 9925 9987 paper.fodt
Integrating Subversion into LibreOffice User Interface
Lo_SVN is a LibreOffice extension that adds a basic Subversion functionality into the LibreOffice interface. Then, basic svn commands are available from the LibreOffice menu.
-
Source code: https://git.app.uib.no/Sergey.Budaev/lo_svn.
-
Official LibreOffice extension repository: https://extensions.libreoffice.org/en/extensions/show/4071
-
User manual for Lo_SVN is here: https://budaev.info/pub/doc/Lo_SVN.pdf.