From 3f23cf320239cab558594b98ce75177e6fe3dac0 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Fri, 2 Aug 2024 18:51:37 +0300 Subject: refactoring: code cleanup --- web/view/markdown.scm | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'web/view') diff --git a/web/view/markdown.scm b/web/view/markdown.scm index 30c9f33..900378e 100644 --- a/web/view/markdown.scm +++ b/web/view/markdown.scm @@ -67,13 +67,12 @@ (let* ( (abs_path (string-append repo "/" query_path))) (if (file-exists? abs_path) (let* ((full_path (canonicalize-path abs_path)) (content (call-with-input-file full_path get-string-all)) + (commit-sha (get-latest-commit-sha1 repo)) ) `(("path" . ,query_path) ("content" . ,content) - ("hash" . "commit hash here")) - ) (throw 'file-error (string-append "the file path " abs_path " does not exists"))) - )) - + ("hash" . ,commit-sha)) + ) (throw 'file-error (string-append "the file path " abs_path " does not exists"))))) (define (git-invoke repo-path . args) @@ -81,9 +80,8 @@ (define (is-repo? repo-path) (let ((data (git-invoke repo-path "rev-parse")) ) - (zero? data) - ) - ) + (zero? data)) +) (define (get-latest-commit-sha1 repo-path) @@ -93,18 +91,13 @@ commit-sha)) - - (define (commit-file repo file-path content commit-message username email) (if (is-repo? repo) (match (file-exists? (string-append repo "/" file-path)) (#t (with-output-to-file (string-append repo "/" file-path) (lambda () - (display content) - ) - ) - ;;prevent users from commit other people changes check for git add status + (display content))) (let* ((git-add-file (git-invoke repo "add" file-path)) (git-commit-file (git-invoke repo "commit" @@ -114,18 +107,10 @@ ) (git-commit-sha (get-latest-commit-sha1 repo)) ) - ;; check if git add had an error ;; check git commit if had an error - ;;runs the risk of commit a different user changes check this ;; potential for collisions (if (zero? git-commit-file) `(("status" . "201") ("message" . "committed file successfully") ("content" . ,content) ("commit-sha" . ,git-commit-sha) ("commit-message" . ,commit-message) ) `(("status" . "200") ("message" . "Nothing to commit, working tree clean") ("commit-sha" . ,git-commit-sha)) - ) - ) - ) + ))) (#f - (throw 'system-error (string-append file-path " File does not exist Error")) - ) - ) - (throw 'system-error (string-append repo " Is not a git repo.")) - ) - ) + (throw 'system-error (string-append file-path " File does not exist Error")))) + (throw 'system-error (string-append repo " Is not a git repo.")))) -- cgit v1.2.3