build html only when HEAD branch changes; cleanup:
post-receive commit hooks receive on standard input lines of the form: old-commit new-commit ref old-commit new-commit ref old-commit new-commit ref so we can inspect those lines to determine whether or not the current branch (aka HEAD) has been changed. because there's no reason to rebuild the html representation of other branches. in future we might even use the git tree-diff between old-commit and new-commit to determine the set of files that have been added, removed, or changed, and regenerate the html representation for only those files, instead of deleting and rebuilding all files every time.
This commit is contained in:
parent
aac42ed7b2
commit
b3719a005d
1 changed files with 26 additions and 8 deletions
34
main.scm
34
main.scm
|
@ -152,15 +152,33 @@ string-block
|
|||
(generate-files-page (make-pathname REPOSITORY-DIRECTORY "files.html") source-files-list)
|
||||
(generate-source-files source-files-list)))
|
||||
|
||||
(define (if-git-directory-generate-html-files)
|
||||
(if (in-git-directory?)
|
||||
(generate-html-files)
|
||||
(print "woops that's not a git directory")))
|
||||
(define (bail . args)
|
||||
(let-optionals args ((status 1) (msg ""))
|
||||
(unless (equal? "" msg) (print msg))
|
||||
(exit status)))
|
||||
|
||||
(define (main args)
|
||||
(if (null? args)
|
||||
(if-git-directory-generate-html-files)
|
||||
(print "woops, i dont take args")))
|
||||
|
||||
(unless (null? args)
|
||||
(bail 1 "woops, i dont take args"))
|
||||
|
||||
(unless (in-git-directory?)
|
||||
(bail 1 "woops that's not a bare git directory"))
|
||||
|
||||
(let ((head-ref (call-with-input-pipe "git symbolic-ref -q HEAD" read-line)))
|
||||
|
||||
(when (null? head-ref)
|
||||
(bail 1 "no HEAD reference is set"))
|
||||
|
||||
;; loop over the changed refs
|
||||
;; if the HEAD ref is changed, generate html for it
|
||||
((flip for-each)
|
||||
(read-lines)
|
||||
(lambda (line)
|
||||
;; isn't there a better way to destructure a list?
|
||||
;; egg 'matchable' has match-let
|
||||
(let-values (((before after ref) (apply values (string-split line))))
|
||||
(when (equal? ref head-ref)
|
||||
(generate-html-files)))))))
|
||||
|
||||
(main (command-line-arguments))
|
||||
|
||||
|
|
Loading…
Reference in a new issue