From b3719a005dccc8a3b10d8ef03d42a85fdbd808e9 Mon Sep 17 00:00:00 2001 From: pho4cexa Date: Sun, 4 Dec 2022 12:17:31 -0800 Subject: [PATCH] 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. --- main.scm | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/main.scm b/main.scm index ecd7184..11db882 100644 --- a/main.scm +++ b/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)) -