summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorArun Isaac2022-07-03 01:44:50 +0530
committerArun Isaac2022-07-03 23:21:41 +0530
commit2562403d13daaabb1c6eb324b2c34b0c17e1656b (patch)
treec22f4ee45909f416f90d62ee3b3ab7501bb19d00 /bin
parent7db5c16efe41ed0e57be24125f21edf94e78429e (diff)
downloadtissue-2562403d13daaabb1c6eb324b2c34b0c17e1656b.tar.gz
tissue-2562403d13daaabb1c6eb324b2c34b0c17e1656b.tar.lz
tissue-2562403d13daaabb1c6eb324b2c34b0c17e1656b.zip
tissue: Read files from git repository, not from the working tree.
This also frees us from checking if the file actually exists in the
working tree.

* bin/tissue (tissue-show): Use call-with-file-in-git instead of
call-with-input-file.
(load-config): Use call-with-file-in-git and eval-string instead of
load.
* tissue/document.scm: Import (tissue git).
(document-text, read-gemtext-document): Use call-with-file-in-git
instead of call-with-input-file.
* tissue/issue.scm (file-details): Read from a port instead of from a
file.
(read-gemtext-issue): Call file-details with a port reading the file
committed into the git repository.
* tissue/web/server.scm: Import (tissue git).
* tissue/web/static.scm (exporter): Use call-with-file-in-git instead
of call-with-input-file.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue89
1 files changed, 43 insertions, 46 deletions
diff --git a/bin/tissue b/bin/tissue
index 2c739b3..3ee0565 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -99,57 +99,54 @@ Show the text of FILE.
 "
              (command-line-program)))
     ((file)
-     ;; Files may be renamed or deleted, but not committed. Therefore,
-     ;; only read the file if it exists.
-     (if (file-exists? file)
-         (call-with-input-file file
-           (lambda (port)
-             (port-transduce
-              (compose
-               ;; Detect preformatted text blocks.
-               (tfold (match-lambda*
-                        (((pre? . _) line)
-                         (cons (if (string-prefix? "```" line)
-                                   (not pre?)
-                                   pre?)
-                               line)))
-                      (cons #f #f))
-               (tmap (lambda (pre?+line)
-                       (match pre?+line
-                         ((pre? . line)
-                          (cond
-                           ;; Print headlines in bold.
-                           ((string-prefix? "#" line)
-                            (display (colorize-string line 'BOLD)))
-                           ;; Print lists in cyan.
-                           ((string-prefix? "*" line)
-                            (display (colorize-string line 'CYAN)))
-                           ;; Print links in cyan, but only the actual
-                           ;; link, and not the => prefix or the label.
-                           ((string-match "^(=>[ \t]*)([^ ]*)([^\n]*)" line)
-                            => (lambda (m)
-                                 (display (match:substring m 1))
-                                 (display (colorize-string (match:substring m 2) 'CYAN))
-                                 (display (match:substring m 3))))
-                           ;; Print preformatted text backticks in
-                           ;; magenta.
-                           ((string-prefix? "```" line)
-                            (display (colorize-string line 'MAGENTA)))
-                           (else
-                            ;; If part of preformatted block, print in
-                            ;; magenta. Else, print in default color.
-                            (display (if pre? (colorize-string line 'MAGENTA) line))))))
-                       (newline))))
-              (const #t)
-              get-line-dos-or-unix
-              port)))
-         (raise (issue-file-not-found-error file))))))
+     (call-with-file-in-git (current-git-repository) file
+       (lambda (port)
+         (port-transduce
+          (compose
+           ;; Detect preformatted text blocks.
+           (tfold (match-lambda*
+                    (((pre? . _) line)
+                     (cons (if (string-prefix? "```" line)
+                               (not pre?)
+                               pre?)
+                           line)))
+                  (cons #f #f))
+           (tmap (lambda (pre?+line)
+                   (match pre?+line
+                     ((pre? . line)
+                      (cond
+                       ;; Print headlines in bold.
+                       ((string-prefix? "#" line)
+                        (display (colorize-string line 'BOLD)))
+                       ;; Print lists in cyan.
+                       ((string-prefix? "*" line)
+                        (display (colorize-string line 'CYAN)))
+                       ;; Print links in cyan, but only the actual
+                       ;; link, and not the => prefix or the label.
+                       ((string-match "^(=>[ \t]*)([^ ]*)([^\n]*)" line)
+                        => (lambda (m)
+                             (display (match:substring m 1))
+                             (display (colorize-string (match:substring m 2) 'CYAN))
+                             (display (match:substring m 3))))
+                       ;; Print preformatted text backticks in
+                       ;; magenta.
+                       ((string-prefix? "```" line)
+                        (display (colorize-string line 'MAGENTA)))
+                       (else
+                        ;; If part of preformatted block, print in
+                        ;; magenta. Else, print in default color.
+                        (display (if pre? (colorize-string line 'MAGENTA) line))))))
+                   (newline))))
+          (const #t)
+          get-line-dos-or-unix
+          port))))))
 
 (define load-config
   (memoize-thunk
    (lambda ()
      "Load configuration and return <tissue-configuration> object."
-     (load (canonicalize-path "tissue.scm")))))
+     (call-with-file-in-git (current-git-repository) "tissue.scm"
+       (compose eval-string get-string-all)))))
 
 (define tissue-repl
   (match-lambda*