Edgewall Software

Version 1 (modified by anonymous, 18 years ago) ( diff )

HOWTO: Trac and WebSVN Integration

How to Integrate Trac and WebSVN - Under Construction

This is a rather ad-hoc guide and I take no responsibility if it does not work in your config I'm sure that there are many improvements that I can make

Trac Is an integrated bug tracking system using Python, and WebSVN is a web front end for multiple projects under SVN running under PHP.

Trac works well for single repositories holding single projects, it can also be used to manage multiple projects using some tricks.

The downside of these tricks are that they are statically configured, if a new project or repository is created, then apache has to be configured to show the change.

WebSVN is completly dynamic, it imediately lists a new repository (as far as Trac is concerned a project) when it is created.

Trac does have a solution to this, modPythonHandler, but I've had no success in getting this working.

My solution works under Apache 2.0 under Windows 2000, but I can see no reason why it should not work under Linux/Unix with Apache 2.0.

Step 1

First get Trac and WebSVN working in isolation, the section in my apache.conf looks like this:-

### SVN Config
LoadModule dav_fs_module	modules/mod_dav_fs.so
LoadModule dav_module		modules/mod_dav.so
LoadModule dav_svn_module	modules/mod_dav_svn.so

#A single repository root with multiple repositories within
<Location  /svn>
  DAV svn
  SVNParentPath /SVN_ROOT
#  AuthType Basic
#  AuthName "Subversion repository"
#  AuthUserFile /svn/svn-auth-file
#  Satisfy Any
#  Require valid-user

## If the user access /svn_root then send them to WebSVN
## index.php is added to the DirectoryIndex above
alias /svn_root "c:\svn_root\WebSVN"

## If the user tries to access /svn then send them to WebSVN
## See the <Directory> section for the server root

## Allow access to the SVN Root
<Directory "c:\svn_root">
    AllowOverride None
    Order allow,deny
    Allow from all

## Generic permissions on the shared trac system
<Directory "C:\Program Files\Python23\share\trac\htdocs">
  Options Indexes MultiViews
  AllowOverride None
  Order allow,deny
  Allow from all

#Trac basic configuration used for testing calle TestTrac1
# use http://localhost/TestTrac1/... to access trac, trac is pointed at one single project
ScriptAlias /TestTrac1 "c:\program files\python23\share\trac\cgi-bin\trac.cgi"
<Location /TestTrac1>
  SetEnv TRAC_ENV "c:\svn_root\test\trac.db"

<Location "/TestTrac1/login">
  AuthType Basic
  AuthName "Welcome To Test Trac 1"
  AuthUserFile c:\svn_root\tracpassword
  Require valid-user

My WebSVN wsvn.php is modified thus:

// Note that wsvn.php need not be in the /websvn directory (and normally isn't).
$locwebsvnhttp = "/svn_root/WebSVN";

// Physical location of websvn directory
$locwebsvnreal = "C:/svn_root/WebSVN";

My WebSVN config.inc is modified thus:


My setup has the following locations for Trac, Python, Apache, WebSVN and the SVN repository.

Trac:      C:\Program Files\Python23\share\trac                [common files]
Trac:      C:\Program Files\Python23\Scripts                   [install and CGI scripts]
Trac:      C:\Program Files\Python23\Lib\site-packages\trac    [Program]  
Python:    C:\Program Files\Python23
Apache:    C:\Program Files\Apache Group\Apache2.0
WebSVN:    C:\svn_root\WebSVN

Step 2

Apply these changes to WebSVN index.php

//remove the ++ from
$listing[$i++]["projlink"] = "<a href=\"${url}sc=0\">".$project->name."</a>";

//Then add these three lines
$listing[$i]["projlink"]=$listing[$i]["projlink"]."        ";
$listing[$i]["projlink"]=$listing[$i]["projlink"]."<a href=\\Wiki\\".$project->name."> Wiki</a>";

above there should be about 6 <ampersand>nbsp in between the quotes, but Trac decides to remove them !!

Step 3

Apply these settings to Apache (Needs a lot of cleaning up)

#### Integrate WebSVN With Trac
###  Rewrite access to projects in the wiki to the correct project handler
#Turn on Rewrite if its not already on here
RewriteEngine On

# Rewrite access to http://localhost/Wiki/Project to http://localhost/Wiki/Project/trac.cgi setting TRAC_ENV & PATH_INFO, skipping next
RewriteRule /Wiki/([[:alnum:]]+)$	"/Wiki/$1/trac.cgi"   [PT,S,E=Trac_Env:c:\\svn_root\\$1\\trac.db,E=PATH_INFO:$2]

# For some reason, the virtual path, PATH_INFO is not set automatically by the CGI handler below, so it tries to find the file in the path info location
# L=don't execute any more rules, PT=pass through, don't actually forward, S=skip the next rule (should not be required)
# WebSVN is modified to access the repository using an automatically generated pane listing projects, this is modified with the Trac path and detected here
# Rewrite access to http://localhost/Wiki/Project/... to http://localhost/Wiki/Project/trac.cgi..., setting TRAC_ENV and PATH_INFO
RewriteRule /Wiki/([[:alnum:]]+)(/?.*)	"/Wiki/$1$2"   [PT,E=Trac_Env:c:\\svn_root\\$1\\trac.db,E=PATH_INFO:$2]

## Tell apache that any access to the ...trac.cgi... should be treated as a script, regardless of path
ScriptAliasMatch /Wiki/(.+)/trac.cgi(/?.*) "c:\program files\python23\share\trac\cgi-bin\trac.cgi$2"

###This line uses a script to debug the enviroment sent to Trac
#RewriteRule /Wiki/([[:alnum:]]+)(/?.*)	"/cgi-bin/pythonenv.cgi"   [PT,E=Trac_Env:c:\\svn_root\\$1\\trac.db,E=TRAC_DEBUG_ENV1:$1,E=TRAC_DEBUG_ENV2:$2]
#Failure to use PT here results in a file name mapping that does not exist.
#Using R results in no env passed
#using P results in no valid URL (needs an HTTP prefix??)

#Any access to the login virtual path even under a project path results in a login box
<LocationMatch "^.*Wiki.*trac.cgi/login">
  AuthType Basic
  AuthName "Welcome To CITEL Trac"
  AuthUserFile c:\svn_root\tracpassword
  Require valid-user

These changes to apache will 'standardise' the URLs used to access the various systems '(Needs work)'

<Directory <where your htdocs live>
#Enable the re-write engine
#For some reason, re-write rules only work in this <directory> section
RewriteEngine On

##  Re-write svn or svn/ to /svn_root
RewriteRule ^svn/?$ /svn_root  [R]

##Rewrite access to /Wiki or /Wiki/ to /svn_root as no project is specified
RewriteRule ^Wiki/?$ /svn
RewriteRule ^wiki/?$ /svn

Step 4

Tortoise (or whatever) will use http://server/svn/ProjectRepository/SubProject

To access a Project Repository list use http://server/svn or http://server/Wiki

To directly access a Project Trac use http://server/Wiki/ProjectRepository


I've not understood if the following are due to Trac or my setup and changes:-

  • After logging in, a refresh is needed to show the correct user
  • Log-ins are sticky, so if I'm managing one project and forget to log out, I'll be using the same user for the next project. This would cause problems if multiple people have access to the same machines.
  • Probably due more to a lack of forethought I've got my WebSVN installation in the same place as my repositories, so its listed as a repository, WebSVN should check that a folder is a repository anyway, but ideally it needs moving. Initial attempts at this resulted in a mess.
Note: See TracWiki for help on using the wiki.