fix: git diff doesn't work because we don't store the raw file content

pull/1764/head
Tienson Qin 2021-05-09 11:25:41 +08:00
parent a1fd8425c5
commit 7349910e6f
3 changed files with 74 additions and 73 deletions

View File

@ -6,6 +6,7 @@
[frontend.handler.file :as file]
[frontend.handler.notification :as notification]
[frontend.handler.common :as common-handler]
[frontend.handler.file :as file-handler]
[frontend.state :as state]
[clojure.string :as string]
[frontend.db :as db]
@ -49,9 +50,16 @@
:style {:background-color bg-color}}
value]))])
(rum/defc file < rum/reactive
[repo type path contents remote-oid]
(let [{:keys [collapse? resolved?]} (util/react (rum/cursor diff-state path))
(rum/defcs file < rum/reactive
{:will-mount (fn [state]
(let [*local-content (atom "")
[repo _ path & _others] (:rum/args state)]
(p/let [content (file-handler/load-file repo path )]
(reset! *local-content content))
(assoc state ::local-content *local-content)))}
[state repo type path contents remote-oid]
(let [local-content (rum/react (get state ::local-content))
{:keys [collapse? resolved?]} (util/react (rum/cursor diff-state path))
edit? (util/react *edit?)
delete? (= type "remove")]
[:div.cp__diff-file
@ -70,7 +78,6 @@
(let [content (get contents path)]
(if (or (and delete? (nil? content))
content)
(let [local-content (db/get-file path)]
(if (not= content local-content)
(let [local-content (or local-content "")
content (or content "")
@ -137,7 +144,7 @@
(reset! *edit? true)))]
:else
nil)])))
nil)]))
[:div "loading..."]))]))
;; TODO: `n` shortcut for next diff, `p` for previous diff

View File

@ -88,13 +88,8 @@
;; raw-page-blocks (get grouped-blocks-by-file file-path raw-page-blocks)
page-blocks (block-handler/with-dummy-block raw-page-blocks format
(if (empty? raw-page-blocks)
(let [content (db/get-file repo file-path)]
{:block/page {:db/id (:db/id page)}
:block/file {:db/id (:db/id (:block/file page))}
:block/meta
(let [file-id (:db/id (:block/file page))]
{:start-pos (utf8/length (utf8/encode content))
:end-pos nil})}))
:block/file {:db/id (:db/id (:block/file page))}})
{:journal? journal?
:page-name page-name})
hiccup-config {:id (if block? (str block-id) page-name)

View File

@ -33,7 +33,6 @@
(not= content (db/get-file path))
(when-let [last-modified-at (db/get-file-last-modified-at repo path)]
(> mtime last-modified-at)))
(let [_ (file-handler/alter-file repo path content {:re-render-root? true
:from-disk? true})]
(db/set-file-last-modified-at! repo path mtime))