| 75 | Prior to 0.12, Trac synchronized its cache with the repository on every request. This approach is not practical anymore with multiple repositories. For this reason, explicit synchronization through post-commit hooks was added. This also provides new functionality in the form of a repository listener extension point that is called when a changeset is added or modified, and can be used by plugins to perform actions on commit. |
| 76 | |
| 77 | === Explicit synchronization === |
| 78 | This is the preferred method of repository synchronization. It requires setting the `[trac] repository_sync_per_request` option in [wiki:TracIni#trac-section trac.ini] to an empty value, and adding a call to `trac-admin` in the post-commit hook of each repository. Additionally, if a repository allows changing revision metadata, a call to `trac-admin` must be added to the post-revprop-change hook as well. |
| 79 | |
| 80 | `changeset added <repos> <rev> [...]`:: |
| 81 | Notify Trac that one or more changesets have been added to a repository. |
| 82 | |
| 83 | `changeset modified <repos> <rev> [...]`:: |
| 84 | Notify Trac that metadata on one or more changesets in a repository has been modified. |
| 85 | |
| 86 | The `<repos>` argument can be either a repository name (use "`(default)`" for the default repository) or the path to the repository. |
| 87 | |
| 88 | The following example is a complete post-commit script for Subversion on Unix. It should marked executable and placed in the `hooks` directory of the repository, with the file name `post-commit`. |
| 89 | {{{ |
| 90 | #!sh |
| 91 | #!/bin/sh |
| 92 | /usr/bin/trac-admin /path/to/env changeset added "$1" "$2" |
| 93 | }}} |
| 94 | On Windows (`post-commit.cmd`): |
| 95 | {{{ |
| 96 | #!application/x-dos-batch |
| 97 | @C:\Python26\Scripts\trac-admin.exe C:\path\to\env changeset added "%1" "%2" |
| 98 | }}} |
| 99 | |
| 100 | The post-revprop-change hook for Subversion is very similar. On Unix: |
| 101 | {{{ |
| 102 | #!sh |
| 103 | #!/bin/sh |
| 104 | /usr/bin/trac-admin /path/to/env changeset modified "$1" "$2" |
| 105 | }}} |
| 106 | On Windows (`post-revprop-change.cmd`): |
| 107 | {{{ |
| 108 | #!application/x-dos-batch |
| 109 | @C:\Python26\Scripts\trac-admin.exe C:\path\to\env changeset modified "%1" "%2" |
| 110 | }}} |
| 111 | |
| 112 | See the [http://svnbook.red-bean.com/en/1.5/svn.reposadmin.create.html#svn.reposadmin.create.hooks section about hooks] in the Subversion book for more information. Other repository types will require different hook setups. Please see the plugin documentation for specific instructions. |
| 113 | |
| 114 | === Per-request synchronization === |
| 115 | If the post-commit hooks are not available, the environment can be set up for per-request synchronization. In that case, the `[trac] repository_sync_per_request` option in [wiki:TracIni#trac-section trac.ini] must be set to a comma-separated list of repository names to be synchronized. |
| 116 | |
| 117 | Note that in this case, the changeset listener extension point is not called, and therefore plugins using it will not work correctly. |