From 7d9615bd0ea68118fdcff0765100cf5d73e81e58 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 29 Jan 2023 21:54:16 +0000 Subject: git: Deprecate call-with-file-in-git. Functions called by call-with-file-in-git may expect to read files directly off the filesystem. These functions are not all within the user's control and cannot be rewritten to do otherwise. It is more robust to provide a filesystem checkout of the git repository like these functions expect. In this commit, we deprecate call-with-file-in-git and replace calls to it with call-with-input-file. These invocations have been arranged such that they all happen at the top level of a repository checkout. * tissue/git.scm (call-with-file-in-git): Delete function. * .dir-locals.el (scheme-mode): Unregister it. * bin/tissue (tissue-show, load-config), tissue/file-document.scm (file-text, read-gemtext-document), tissue/issue.scm (read-gemtext-issue): Replace call-with-file-in-git with call-with-input-file. (pull, tissue-web): Call load-config from the top level of a repository checkout. --- bin/tissue | 86 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 41 deletions(-) (limited to 'bin') diff --git a/bin/tissue b/bin/tissue index 7d1c4e9..57ddaee 100755 --- a/bin/tissue +++ b/bin/tissue @@ -108,7 +108,7 @@ Show the text of FILE. " (command-line-program))) ((file) - (call-with-file-in-git (current-git-repository) file + (call-with-input-file file (lambda (port) (port-transduce (compose @@ -152,7 +152,7 @@ Show the text of FILE. (define (load-config) "Load configuration and return object." - (call-with-file-in-git (current-git-repository) "tissue.scm" + (call-with-input-file "tissue.scm" (compose eval-string get-string-all))) (define tissue-repl @@ -278,7 +278,10 @@ Serve repositories specified in CONFIG-FILE over HTTP. (parameterize ((%current-git-repository (repository-open repository-directory))) (cons name - `((project . ,(load-config)) + `((project . ,(call-with-temporary-checkout repository-directory + (lambda (temporary-checkout) + (call-with-current-directory temporary-checkout + load-config)))) (repository-directory . ,repository-directory) (website-directory . ,(string-append state-directory "/" name "/website")) (xapian-directory . ,(string-append state-directory "/" name "/xapian")) @@ -401,44 +404,45 @@ HOSTNAME." (format (current-error-port) "Cloned upstream repository.~%") repository))))) - (let ((config (load-config))) - (parameterize ((%aliases (tissue-configuration-aliases config))) - (call-with-temporary-checkout (git-top-level) - (lambda (temporary-repository-clone) - ;; Add the top level of the git repository to the - ;; load path since there may be user-written - ;; modules in the repository. - ;; TODO: Though not strictly required, it would - ;; be better to remove the added load path once - ;; done. - (add-to-load-path temporary-repository-clone) - ;; Index. - (unless (file-exists? "xapian") - (mkdir "xapian")) - (let ((xapian-directory (canonicalize-path "xapian"))) - (call-with-current-directory temporary-repository-clone - (cut index - xapian-directory - (tissue-configuration-indexed-documents config))) - (format (current-error-port) - "Indexed latest changes.~%")) - ;; Build website. - (let ((website-directory "website")) - (guard (c (else (format (current-error-port) - "Building website failed.~%") - (raise c))) - (call-with-temporary-directory - (lambda (temporary-output-directory) - (call-with-current-directory temporary-repository-clone - (cut build-website - temporary-output-directory - (tissue-configuration-web-files config))) - (delete-file-recursively website-directory) - (rename-file temporary-output-directory - website-directory))) - (chmod website-directory #o755) - (format (current-error-port) - "Built website.~%")))))))))))))) + (call-with-temporary-checkout (git-top-level) + (lambda (temporary-repository-clone) + (let ((config (call-with-current-directory temporary-repository-clone + load-config))) + (parameterize ((%aliases (tissue-configuration-aliases config))) + ;; Add the top level of the git repository to the + ;; load path since there may be user-written + ;; modules in the repository. + ;; TODO: Though not strictly required, it would + ;; be better to remove the added load path once + ;; done. + (add-to-load-path temporary-repository-clone) + ;; Index. + (unless (file-exists? "xapian") + (mkdir "xapian")) + (let ((xapian-directory (canonicalize-path "xapian"))) + (call-with-current-directory temporary-repository-clone + (cut index + xapian-directory + (tissue-configuration-indexed-documents config))) + (format (current-error-port) + "Indexed latest changes.~%")) + ;; Build website. + (let ((website-directory "website")) + (guard (c (else (format (current-error-port) + "Building website failed.~%") + (raise c))) + (call-with-temporary-directory + (lambda (temporary-output-directory) + (call-with-current-directory temporary-repository-clone + (cut build-website + temporary-output-directory + (tissue-configuration-web-files config))) + (delete-file-recursively website-directory) + (rename-file temporary-output-directory + website-directory))) + (chmod website-directory #o755) + (format (current-error-port) + "Built website.~%")))))))))))))) (define tissue-pull (match-lambda* -- cgit v1.2.3