Explorar o código

enhance: no need to git add when file changed because push will check

Tienson Qin %!s(int64=4) %!d(string=hai) anos
pai
achega
6f689631f8

+ 0 - 2
src/main/frontend/handler/draw.cljs

@@ -6,7 +6,6 @@
             [frontend.state :as state]
             [frontend.db :as db]
             [frontend.handler.file :as file-handler]
-            [frontend.handler.git :as git-handler]
             [frontend.date :as date]
             [frontend.config :as config]
             [frontend.storage :as storage]
@@ -33,7 +32,6 @@
          (p/do!
           (create-draws-directory! repo)
           (fs/write-file! repo repo-dir path data nil)
-          (git-handler/git-add repo path)
           (db/transact! repo
                         [{:file/path path
                           :page/name file

+ 1 - 3
src/main/frontend/handler/editor.cljs

@@ -5,7 +5,6 @@
             [frontend.db.utils :as db-utils]
             [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
-            [frontend.handler.git :as git-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.file :as file-handler]
@@ -463,8 +462,7 @@
                              (or (:page/original-name page)
                                  (:page/name page)))
                            value)]
-          (p/let [_ (fs/create-if-not-exists repo dir file-path content)
-                  _ (git-handler/git-add repo path)]
+          (p/let [_ (fs/create-if-not-exists repo dir file-path content)]
             (file-handler/reset-file! repo path content)
             (ui-handler/re-render-root!)
 

+ 2 - 2
src/main/frontend/handler/external.cljs

@@ -12,7 +12,7 @@
 
 (defonce debug-files (atom nil))
 (defn index-files!
-  [repo files git-add-cb]
+  [repo files finish-handler]
   (let [titles (->> files
                     (map :title)
                     (map :text)
@@ -39,7 +39,7 @@
       (file-handler/alter-files repo files {:add-history? false
                                             :update-db? false
                                             :update-status? false
-                                            :git-add-cb git-add-cb}))
+                                            :finish-handler finish-handler}))
     (let [journal-pages-tx (let [titles (filter date/valid-journal-title? titles)]
                              (map
                               (fn [title]

+ 13 - 28
src/main/frontend/handler/file.cljs

@@ -8,7 +8,6 @@
             [frontend.db :as db]
             [frontend.git :as git]
             [frontend.handler.common :as common-handler]
-            [frontend.handler.git :as git-handler]
             [frontend.handler.extract :as extract-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.route :as route-handler]
@@ -185,8 +184,6 @@
       (db/set-file-content! repo path content))
     (util/p-handle (write-file!)
                    (fn [_]
-                     (when-not from-disk?
-                       (git-handler/git-add repo path update-status?))
                      (when (= path (config/get-config-path repo))
                        (restore-config! repo true))
                      (when (= path (config/get-custom-css-path repo))
@@ -216,7 +213,7 @@
                                    :path-params {:path path}}))))))
 
 (defn alter-files
-  [repo files {:keys [add-history? update-status? git-add-cb reset? update-db? chan chan-callback resolved-handler]
+  [repo files {:keys [add-history? update-status? finish-handler reset? update-db? chan chan-callback resolved-handler]
                :or {add-history? true
                     update-status? true
                     reset? false
@@ -240,7 +237,7 @@
           (chan-callback))))))
 
 (defn alter-files-handler!
-  [repo files {:keys [add-history? update-status? git-add-cb reset? chan]
+  [repo files {:keys [add-history? update-status? finish-handler reset? chan]
                :or {add-history? true
                     update-status? true
                     reset? false}} file->content]
@@ -253,29 +250,18 @@
                                         (log/error :write-file/failed {:path path
                                                                        :content content
                                                                        :error error}))))))
-        git-add-f (fn []
-                    (let [add-helper
-                          (fn []
-                            (map
-                              (fn [[path content]]
-                                (git-handler/git-add repo path update-status?))
-                              files))]
-                      (-> (p/all (add-helper))
-                          (p/then (fn [_]
-                                    (when git-add-cb
-                                      (git-add-cb))))
-                          (p/catch (fn [error]
-                                     (println "Git add failed:")
-                                     (js/console.error error)))))
-                    (ui-handler/re-render-file!)
-                    (when add-history?
-                      (let [files-tx (mapv (fn [[path content]]
-                                             (let [original-content (get file->content path)]
-                                               [path original-content content])) files)]
-                        (history/add-history! repo files-tx))))]
+        finish-handler (fn []
+                         (when finish-handler
+                           (finish-handler))
+                         (ui-handler/re-render-file!)
+                         (when add-history?
+                           (let [files-tx (mapv (fn [[path content]]
+                                                  (let [original-content (get file->content path)]
+                                                    [path original-content content])) files)]
+                             (history/add-history! repo files-tx))))]
     (-> (p/all (map write-file-f files))
         (p/then (fn []
-                  (git-add-f)
+                  (finish-handler)
                   (when chan
                     (async/put! chan true))))
         (p/catch (fn [error]
@@ -339,5 +325,4 @@
     (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" config/app-name))
             file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]
       (when-not file-exists?
-        (reset-file! repo-url path default-content)
-        (git-handler/git-add repo-url path)))))
+        (reset-file! repo-url path default-content)))))

+ 1 - 3
src/main/frontend/handler/page.cljs

@@ -9,7 +9,6 @@
             [frontend.handler.route :as route-handler]
             [frontend.handler.file :as file-handler]
             [frontend.handler.repo :as repo-handler]
-            [frontend.handler.git :as git-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.project :as project-handler]
             [frontend.handler.web.nfs :as web-nfs]
@@ -74,8 +73,7 @@
                  ;; a new file created.
                  ;; Question: what if the fs write failed?
                  (p/let [_ (file-handler/reset-file! repo path content)
-                         _ (fs/create-if-not-exists repo dir file-path content)
-                         _ (git-handler/git-add repo path)]
+                         _ (fs/create-if-not-exists repo dir file-path content)]
                    (when redirect?
                      (route-handler/redirect! {:to :page
                                                :path-params {:name page}})

+ 4 - 8
src/main/frontend/handler/repo.cljs

@@ -64,8 +64,7 @@
         (p/let [file-exists? (fs/create-if-not-exists repo-url repo-dir (str app-dir "/" config/config-file) default-content)]
           (when-not file-exists?
             (file-handler/reset-file! repo-url path default-content)
-            (common-handler/reset-config! repo-url default-content)
-            (git-handler/git-add repo-url path)))))))
+            (common-handler/reset-config! repo-url default-content)))))))
 
 (defn create-contents-file
   [repo-url]
@@ -85,8 +84,7 @@
     (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" (state/get-pages-directory)))
             file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]
       (when-not file-exists?
-        (file-handler/reset-file! repo-url path default-content)
-        (git-handler/git-add repo-url path)))))
+        (file-handler/reset-file! repo-url path default-content)))))
 
 (defn create-custom-theme
   [repo-url]
@@ -98,8 +96,7 @@
     (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" config/app-name))
             file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]
       (when-not file-exists?
-        (file-handler/reset-file! repo-url path default-content)
-        (git-handler/git-add repo-url path)))))
+        (file-handler/reset-file! repo-url path default-content)))))
 
 (defn create-dummy-notes-page
   [repo-url content]
@@ -149,8 +146,7 @@
              (file-handler/reset-file! repo-url path content)
              (p/let [_ (fs/create-if-not-exists repo-url repo-dir file-path content)]
                (when-not (state/editing?)
-                 (ui-handler/re-render-root!))
-               (git-handler/git-add repo-url path)))))))))
+                 (ui-handler/re-render-root!))))))))))
 
 (defn create-today-journal!
   []