The svn-post-commit-hooks egg uses the svn-client egg to provide high-level functions useful for the creation of programs meant to run as post-commit hooks for Subversion repositories (such as svnwiki or svnblog).
The post-commit-update function checks out a copy of the repository to a local directory and checks to see if there are new unprocessed commits. The proposed model for post-commit hooks is to store the last revision that the post-commit application has been able to process in a file; when executed, the first thing the application should do is call post-commit-update to check what is the last revision it has processed and process any new.
(use svn-post-commit-hooks) (post-commit-update ; URL of the repository "https://svn.afc.no-ip.info/svn/chicken-eggs/wiki" ; Login to authenticate "anonymous" ; Password "" ; Local path where a copy should be checked-out/updated "/tmp/repository-wiki" ; Data file where the post-commit program stores the last commit it has ; successfully processed "/tmp/data-wiki/last-revision.txt" ; Function to call if the repository has indeed changed. It receives ; two parameters, the last processed revision and the current revision. (lambda (old-revision new-revision) ...))
List all commits after a certain one
post-commit-get-log returns the log with all changes after a given revision (which will usually correspond to the last revision that the post-commit hook has processed).
(use stream-ext svn-post-commit-hooks) (stream->list (post-commit-get-log ; Directory with the copy (check-out) of the repository: "/tmp/repository-wiki" ; Initial revision (return the log *after* the revision number specified): 0 ; Login to authenticate as: "anonymous" ; Password: ""))
List files that changed after a revision
The post-commit-changed-files function returns an entry with the files that have changed after a certain revision.
This is similar to post-commit-get-log (indeed it is implemented on top of it), but provides a more convenient interface (it tends to be more interesting for post-commit hooks to detect what files have changed rather than just getting a raw list with all commits).
(use svn-post-commit-hooks format-modular) ; Function to process the entry objects returned by list-changed files. Each ; object is an entry record corresponding to a position in the file system (a ; file or a directory). Entry records have a changes field with a list of the ; commits that affected them and a subs record with a hash-table for files in ; the current directory. (define (process-entry entry name) (format #t "Location: ~A~%" name) (format #t " Changes:~%") (for-each show-change (entry-changes entry)) ; Recursively process sub-entries (for directories): (hash-table-walk (entry-subs entry) (lambda (sub-name sub-entry) (process-entry sub-entry (string-append name "/" sub-name))))) ; Function to show one specific change, as returned by list-changed-files in ; the subs field of the entry record. (define (show-change change) (format #t " Revision: ~A~%" (change-rev change)) (format #t " Seconds (date): ~A~%" (change-seconds change)) (format #t " Data: ~A~%" (change-data change))) ; And now lets get the entry for all changes to a repository: (process-entry (post-commit-changed-files ; The URL of the repository or a directory with a local copy: "/tmp/repository-wiki" ; A subdirectory from the repository if we only want reports for commits ; affecting that directory: "" ; Login to authenticate with: "anonymous" ; Password: "" ; Initial revision (post-commit-changed-files will only return ; reports for commits after the one we specify). Usually, in ; programs meant to run as post-commit hooks, instead of a 0, ; you'll pass the number of the last revision your post-commit ; hook processed. 0) "")
This egg is made by Alejandro Forero Cuervo <firstname.lastname@example.org>.
Copyright (C) 2006 Alejandro Forero Cuervo <email@example.com>
The svn-post-commit-hooks egg is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
The svn-post-commit-hooks egg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the svn-post-commit-hooks egg; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- First release.