about summary refs log tree commit diff
path: root/web/view
diff options
context:
space:
mode:
authorAlexander_Kabui2024-08-02 18:51:37 +0300
committerAlexander_Kabui2024-08-02 19:50:41 +0300
commit3f23cf320239cab558594b98ce75177e6fe3dac0 (patch)
treeec040bccce8e650096fb7d0c2210ce4073870efa /web/view
parent0baf76460ce9e15dceecafa5c82bad7e14314b20 (diff)
downloadgn-guile-3f23cf320239cab558594b98ce75177e6fe3dac0.tar.gz
refactoring: code cleanup
Diffstat (limited to 'web/view')
-rw-r--r--web/view/markdown.scm33
1 files changed, 9 insertions, 24 deletions
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."))))