Edgewall Software

Version 59 (modified by edward.king@…, 16 years ago) ( diff )

Added to current solution to help OS X users.

Trac and Subversion

Trac has supported the Subversion VersioningSystemBackend since day one. Actually, Trac was even named svntrac back then!

This page is intended to collect all the specific tips and tricks about Subversion support in Trac. This is not the place for general Subversion help. You can get more support options elsewhere.

Getting Subversion

From subversion.tigris.org, in the download area:

  • Source archives.
  • Pre-built binaries for Windows. With Subversion 1.4.6, there are pre-built installers for Python 2.3, 2.4, and 2.5.
  • On the various BSDs use ports or pkgsrc to install Subversion complete with Python bindings. For FreeBSD see make config in /usr/ports/devel/subversion or use /usr/ports/devel/subversion-python. For pkgsrc use the devel/py*-subversion package for getting the bindings.

Building Subversion

The point is not to repeat the excellent build instructions found elsewhere, but rather to clarify the general approach: Trac actually needs the SWIG bindings for Subversion that are bundled with the Subversion distribution. In order to build them, you (obviously) need to build first Subversion, then the bindings.

  • Read the INSTALL file that sits at top level of the Subversion source distribution
  • Do ./configure ...; make; make install; if you intend to use Subversion together with Apache, be sure to configure Subversion so that it will use a compatible version of apr and apr-utils, ideally those of Apache. If not, you'll be able to build Subversion and the bindings, but you most certainly have issues later on, when using mod_python (e.g. #2920).
  • Read ./subversion/bindings/swig/INSTALL in order to build the bindings. In particular, pay attention to the version of SWIG which can be required (1.3.0 comes with pre-generated wrappers, though). Do not install swig 1.3.28 or 1.3.29. Version 1.3.27 seems to works fine (Although not in all cases. The subversion users mailing lists suggest going back to 1.3.25, which may be necessary).
  • In your subversion source root, do make swig-py; make install-swig-py (NOTE: there is a dash between 'install' and 'swig'!)
  • Adapt your PYTHONPATH so that it contains the svn-python folder (the one containing the svn and libsvn packages).
    e.g. if svn is installed in /opt/subversion-1.4.4:
    # export PYTHONPATH=$PYTHONPATH:/opt/subversion-1.4.4/lib/svn-python`
    
    If you're using TracModPython, be sure that Apache will also see this environment variable, or alternatively use the PythonPath mod_python directive.

    You may also just copy the libsvn/ and svn/ directories in the resulting installation directories, e.g. /usr/local/lib/svn-python/, to the site-packages/ directory in your /usr/lib/python2.x/ directory. Python will then find them without having to adapt your PYTHONPATH.

Getting Subversion working

(this is a cite from TracOnDebianSarge as this is extremely useful for first time user setting up subversion repository)

To create a Subversion project at /var/svn/project, issue these commands to get SVN up and running:

  $ mkdir /var/svn
  $ mkdir /var/svn/project
  $ mkdir /tmp/project
  $ mkdir /tmp/project/branches
  $ mkdir /tmp/project/tags
  $ mkdir /tmp/project/trunk
  $ svnadmin create /var/svn/project
  $ svn import /tmp/project file:///var/svn/project -m "initial import"
  $ rm -rf /tmp/project

Fix permissions to the repository:

  $ find /var/svn/project -type f -exec chmod 660 {} \;
  $ find /var/svn/project -type d -exec chmod 2770 {} \;
  $ chown -R root.www-data /var/svn/project

Trac and specific Subversion versions

Trac and Subversion 1.0

This is the oldest supported Subversion version.

Trac and Subversion 1.1

This release introduced the fsfs repository backend, which is to be preferred over the bdb one (see #571 for example). When creating a repository with this Subversion version, take care of using the --fs-type fsfs switch with the svnadmin create command. Version 1.1.4 is the last stable one for that maintenance branch.

Trac and Subversion 1.2

This release makes the fsfs storage the default. Version 1.2.3 is the last stable one for that maintenance branch.

If you switched from a previous version to this one, chances are that you had a Berkeley DB repository. It would be a good idea to switch that repository to the FSFS backend. google:svn+convert+bdb+to+fsfs.

Trac and Subversion 1.3

This is the newest major release for Subversion, and it is currently support by Trac 0.9.x and beyond, with a few caveats.

Trac and Subversion 1.3.0

There are a few known issues with the stock 1.3.0 version:

  • Issue #2472 (spurious exception)
    which can be fixed by applying this patch to subversion/bindings/swig/python/svn/core.py
    Should be fixed in Subversion 1.3.1 (r17992).
  • Issue #2620 (memory leak)
    which can be fixed by applying this patch to subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c.
    Should be fixed in Subversion 1.3.1 (r18230).

With those fixes, I've been able to use the Subversion backend flawlessly "in production", since end of January 2006.

However, some people are seeing yet another problem, which requires one more fix:

  • Issue #2611 (intermittent fatal error, manifesting itself with "argument number 0: a 'apr_pool_t *' is expected" messages in the log and segfault of the apache server)
    was supposedly fixed by applying this patch to subversion/bindings/swig/include/proxy_apr.swg. Note that after applying this patch, the SWIG bindings would have to be regenerated, as explained here. It should be emphasized that a compatible version of SWIG must be used (1.3.24, 1.3.25).
    The issue was supposed to be fixed in Subversion 1.3.1, as the above patch was integrated as r18721, but actually the patch was not enough to solve the issue. See below.

Trac and Subversion 1.3.1

As mentioned above, the issues found with 1.3.0 should be fixed by 1.3.1. This is mostly true, except for #2611.

Issue #2611 was confirmed to still exists in Subversion 1.3.1 and also in the stock 1.3.2, when compiled using the pre-generated bindings that were produced using SWIG 1.3.25
So it seems the patch discussed above was not enough to solve the problem. Also, the issue is most certainly related to the use of multiple python sub-interpreters, either because those are created by default when different virtual hosts are used (#2965, #3455) or because different "PythonInterpreter" directives are used in different <Location> sections (#2713). A workaround consists to force the use of a single Python interpreter, using the "PythonInterpreter" directive with the same argument for all the virtual hosts, as explained here.

Trac and Subversion 1.3.2

This version adds support for SWIG 1.3.28.

See also: release notes for 1.3.2

Trac and Subversion 1.4

Trac works well with Subversion 1.4.

I've noticed that there has been some improvements to the ra layer … unfortunately not available yet for the Python bindings

Also, that version supports SWIG 1.3.29, but so far I used the 1.3.25 pre-generated wrappers that are bundled with the tarball.

Same remark as above concerning #2611, if I have some time, I'll try to reproduce the issue. Update: according to comment:ticket:2965:14, the problem is still there for 1.4.

See also: release notes for 1.4.0

Troubleshooting

RuntimeError: instance.__dict__ not accessible in restricted mode

This is becoming one of the most frequently reported issues for Trac and the Subversion backend, when the TracModPython web front-end is used. The problem happen when Trac is running outside of the "main_interpreter" Python interpreter and can be fixed as explained in #3371:

<Location>
...
PythonInterpreter main_interpreter
...
</Location>

TypeError: argument number 0: a 'apr_pool_t *' is expected, 'instance(<libsvn.core.GenericSWIGWrapper instance at 0x...>)' is received

Use the same fix as above. See #2611 for more information if needed.

ImportError: /usr/local/lib/libsvn_ra_dav-1.so.0: undefined symbol: ...

This error manifests itself quite frequently with Subversion 1.4, the undefined symbol in question may differ (gss_delete_sec_context, SSL_shutdown, etc.) See the advices of Garrett McGrath in googlegroups:trac-users:1ec307bef7552e5e and also #3706.

SubversionException: ("Expected version '3' of repository; found version '5'", ...

The bindings used are older than the Subversion version used to create the repository (#3943).

SubversionException: ('No such revision XY', 160006)

This kind of error seems to happen frequently. Sometimes it seems to be related to the Trac cache being out-of-sync and needing a manual resync (#2739, #3301, #3728); this can happen if the repository was rebuilt and its UUID hasn't changed. Sometimes it seems to be because the repository is temporarily unavailable (#2346), and sometimes, we simply don't know yet (#3773, #3861, #3875).

Unsupported version control system "svn"

By far one of our most commonly reported installation issue (search:'"Unsupported version control system"'), this simply means that the Python bindings for Subversion can't be loaded by Trac.

If you use Debian an try this: TracOnDebianSarge

This can be due to a variety of reasons, and you should go through the following check list to find out.

Check list

When there's some trouble using the Subversion bindings, it usually helps to perform the following checks:

  1. Verify that you can load the bindings using the Python interactive interpreter
$ python
Python ...
>>> from svn import core

If this succeeds, that's a good start.

If it doesn't, it usually means that your bindings are located in a place they can't be loaded from. So either move the svn and libsvn found in the /opt/subversion-xxx/lib/svn-python folder into your site-packages folder, or add the above folder to your PYTHONPATH, or create a svn.pth file in your Python site-packages folder with the above folder path as its single line content (an example on a FreeBSD installation, again: /usr/local/lib/pythonN.N/site-packages/). One simple solution for rpm-based operating systems, is to install the subversion-python bindings rpm. The official subversion site points here to download those packages.

  1. Check the version
    >>> (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO, core.SVN_VER_PATCH)
    (1, 4, 3, 3)
    

Verify that the version given back matches your expectation.

  1. Check that you're using the right binaries (Linux)

Get the pid of the above running Python interpreter (i.e. once the binding is loaded), and get the list of the libraries used by looking at the corresponding map file.

e.g.

cat /proc/10213/maps | grep .so | cut -d/ -f2- | sort -u

In particular, pay attention to the .../lib/svn-python/libsvn/_core.so file and see if it's location seems to be consistent with both those of the other svn libraries (.../lib/*.so) and the location of the Python code part of the bindings (.../lib/svn-python/svn/core.py).

(Mac OS X) Subversion 1.5.X defaults installs in /opt/subversion/. The svn.pth solution works up to this point, but Trac will still be unhappy: you will need to copy /opt/subversion/lib/svn-python/svn & /opt/subversion/lib/svn-python/libsvn on top of /System/Library/Frameworks/Python.framework/Versions/Current/Extras/lib/python/libsvn and /System/Library/Frameworks/Python.framework/Versions/Current/Extras/lib/python/svn.

  1. If you're using Apache / mod_python (Linux) (first tip)

Get a similar list of libraries, but this time for one of your httpd process. Then compare the two, and pay attention to any difference between the svn libraries and the apr libraries. You have to have compatible APR libraries between Apache and Subversion, otherwise you risk to get a wide variety of subtle errors (e.g. #4985).

  1. If you're using Apache / mod_python (Linux) (second tip)

If you have installed the Subversion .so-Files in some "remote" location, Apache may be unable to find them (and thus unable to pass them on to Python/Trac, such that Trac cannot find Subversion). To check if this is the case, do the following:

/etc/init.d/apache2 stop
$export LD_LIBRARY_PATH=/usr/lib/python/site-packages/libsvn/:$LD_LIBRARY_PATH
/etc/init.d/apache2 restart

If this works, you need to add the library path permanently. There are two options for this. Either add it in the Apache configuration file (http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv) or at the system level by adding the path to /etc/ld.so.conf, and then run ldconfig. More information on shared libraries can be found here: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Tip for Debian Linux

Try to install the Subversion Bindings using apt

apt-get install python-subversion

Works for Subversion 1.4.

Known Issues

#2611
Problem with SVN bindings (SVN 1.3.0, Trac r2771)
#3470
improve handling of scoped repositories with copy history
#4474
diffing two large trees results in a massive list with a lot of empty links
#6615
svn:externals not correctly displayed in browser
#7687
Add support for svn:externals "1.5" style
#7744
source:path@rev targeting a file below a copied dir may fail
#8813
next_rev is slow, particularly in the direct-svnfs case
#9208
Support for SVN repository on a UNC path on Windows
#10079
improper rendering of svn:externals when not configured
#10421
RuntimeError: instance.__dict__ not accessible in restricted mode
#10547
glitch with mergeinfo (recreation of merge source shown as eligible)
#11205
"repository sync" fails for Subversion repository with unicode path
#12121
Subversion copies could show peg revision in browser view
#13624
svn-browser generates wrong links directly after renaming/moving files

Asking for More Support About Subversion

Note: See TracWiki for help on using the wiki.