diff options
-rwxr-xr-x | config-cache-hook.tl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/config-cache-hook.tl b/config-cache-hook.tl new file mode 100755 index 00000000..73b7e30b --- /dev/null +++ b/config-cache-hook.tl @@ -0,0 +1,34 @@ +#!txr --lisp + +;; +;; This program is intended to be installed as .git/hooks/post-checkout. +;; It caches the build configuration for the current commit, and restores +;; it for the new commit, if possible. +;; + +;; People have git hook directories which are shared among different +;; repos; we only want to fire for txr. +(unless (ends-with "txr" (pwd)) + (exit)) + +(defvarl %files% '#"reconfigure config.h config.make") +(defvarl %cachedir% ".config-cache") + +(defun try-save-current-config (sha) + (when [all %files% path-exists-p] + (let ((dir (path-cat %cachedir% sha))) + (ensure-dir dir) + (copy-files %files% dir)))) + +(defun try-restore-new-config (sha) + (let* ((dir (path-cat %cachedir% sha)) + (files [map (op path-cat dir) %files%])) + (when [all files path-exists-p] + (copy-files files ".") + (put-line `restored cached configuration for @sha`)))) + +(match-case *args* + (@(require (@prevsha @newsha @nil) + (nequal prevsha newsha)) + (try-save-current-config prevsha) + (try-restore-new-config newsha))) |