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:
pho4cexa 2022-12-04 12:17:31 -08:00 committed by m455
parent aac42ed7b2
commit b3719a005d

View file

@ -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))