;; ;; qwiki-post-commit-hook - updater script for the quick wiki ;; ;; Copyright (c) 2009-2012 Peter Bex and Ivan Raikov ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; - Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; - Redistributions in binary form must reproduce the above ;; copyright notice, this list of conditions and the following ;; disclaimer in the documentation and/or other materials provided ;; with the distribution. ;; ;; - Neither name of the copyright holders nor the names of its ;; contributors may be used to endorse or promote products derived ;; from this software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THE ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR THE ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ;; USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ;; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ;; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ;; POSSIBILITY OF SUCH DAMAGE. (module qwiki-post-commit-hook (qwiki-post-commit-hook!) (import scheme chicken data-structures files) (use srfi-13 posix svn-client qwiki-svn qwiki-sxml qwiki uri-common) (define (string-drop-prefix s p) (if (string-prefix? p s) (string-drop s (string-length p)) s)) ;; TODO: ;; * How do we clean up directories in the html cache? This is a problem ;; when someone removes a dir and then creates a file to replace it. ;; * This sometimes updates files twice or more: This has something to ;; to with the fact that creating a new revision of a file causes ;; that file's version to be bumped, but when the toplevel dir ;; is updated, we're still looking at the history from the the ;; toplevel dir's current revision up to the head revision. ;; * How to handle locking? The checkout could be locked when someone is ;; performing a local commit at the same time someone else is editing ;; the wiki through the web interface. (define (qwiki-post-commit-hook!) (and-let* (((directory? (qwiki-source-path))) (info (svn-client-info (qwiki-source-path) svn-opt-revision-head svn-opt-revision-head #t (qwiki-repos-username) (qwiki-repos-password))) ((pair? info)) (revision (svn-info-rev (cadar info))) (path-prefix (conc "/" (caar info)))) ;; First, get the files up to date. We use this as a guide to see what ;; to do with the generated information. If the file is missing, we can ;; delete it. If was added or modified it will exist, and we can update it. (update-sources! (qwiki-source-path)) (for-each (lambda (log-entry) (for-each (lambda (change) (let* ((path (svn-log-change-path change)) (relpath (string-drop-prefix path path-prefix)) (source-path (make-pathname (qwiki-source-path) relpath))) (if (file-exists? source-path) (begin (print "EXIST: " source-path " - " (string-split relpath "/")) (unless (symbolic-link? source-path) ;; Assume the VCS backend won't hand us paths with non-leaf ;; symlink components! (qwiki-update-file! (string-split relpath "/")))) (begin (print "DELETING: " source-path " - " (string-split relpath "/")) (qwiki-delete-file! (string-split relpath "/")))))) (svn-log-changes log-entry))) (svn-client-log (qwiki-repos-uri) (make-svn-opt-revision-number revision) svn-opt-revision-head 0 #t #f (qwiki-repos-username) (qwiki-repos-password))))) ); end module