chore(deps): bump diff-merge to 0.1.0

pull/9739/head
Andelf 2023-06-17 00:23:58 +08:00
parent 2c41d4a20d
commit a59ecb370d
6 changed files with 57 additions and 40 deletions

View File

@ -47,7 +47,7 @@
(fs/mkdirSync (path/join dir "journals")) (fs/mkdirSync (path/join dir "journals"))
(fs/mkdirSync (path/join dir "pages"))) (fs/mkdirSync (path/join dir "pages")))
(deftest ^:focus build-graph-files (deftest build-graph-files
(create-logseq-graph "tmp/test-graph") (create-logseq-graph "tmp/test-graph")
;; Create files that are recognized ;; Create files that are recognized
(fs/writeFileSync "tmp/test-graph/pages/foo.md" "") (fs/writeFileSync "tmp/test-graph/pages/foo.md" "")

View File

@ -91,7 +91,7 @@
"@excalidraw/excalidraw": "0.12.0", "@excalidraw/excalidraw": "0.12.0",
"@hugotomazi/capacitor-navigation-bar": "^2.0.0", "@hugotomazi/capacitor-navigation-bar": "^2.0.0",
"@logseq/capacitor-file-sync": "0.0.30", "@logseq/capacitor-file-sync": "0.0.30",
"@logseq/diff-merge": "^0.0.3", "@logseq/diff-merge": "0.1.0",
"@logseq/react-tweet-embed": "1.3.1-1", "@logseq/react-tweet-embed": "1.3.1-1",
"@radix-ui/colors": "^0.1.8", "@radix-ui/colors": "^0.1.8",
"@sentry/react": "^6.18.2", "@sentry/react": "^6.18.2",

View File

@ -118,7 +118,7 @@
(let [content (gp-block/get-block-content utf8-encoded-content (second block) format fixed-pos-meta block-pattern) (let [content (gp-block/get-block-content utf8-encoded-content (second block) format fixed-pos-meta block-pattern)
content-raw (get-sub-content-from-pos-meta utf8-encoded-content fixed-pos-meta)] content-raw (get-sub-content-from-pos-meta utf8-encoded-content fixed-pos-meta)]
(recur (conj headings {:body content (recur (conj headings {:body content
:raw-body (string/trimr content-raw) :meta {:raw-body (string/trimr content-raw)}
:level (:level (second block)) :level (:level (second block))
:uuid (:id properties)}) :uuid (:id properties)})
(rest blocks) (rest blocks)
@ -155,9 +155,9 @@
[_base-diffblocks diffs _format] [_base-diffblocks diffs _format]
;; [[[0 {:body "attrib:: xxx", :level 1, :uuid nil}] ...] ...] ;; [[[0 {:body "attrib:: xxx", :level 1, :uuid nil}] ...] ...]
(let [ops-fn (fn [ops] (let [ops-fn (fn [ops]
(map (fn [[op {:keys [raw-body]}]] (map (fn [[op {:keys [meta]}]]
(when (or (= op 0) (= op 1)) ;; equal or insert (when (or (= op 0) (= op 1)) ;; equal or insert
raw-body)) (:raw-body meta)))
ops))] ops))]
(->> diffs (->> diffs
(mapcat ops-fn) (mapcat ops-fn)
@ -181,6 +181,13 @@
current-diffblocks (ast->diff-blocks-alt current-ast current format options) current-diffblocks (ast->diff-blocks-alt current-ast current format options)
branch-diffblocks [income-diffblocks current-diffblocks] branch-diffblocks [income-diffblocks current-diffblocks]
merged (.mergeBlocks merger (bean/->js base-diffblocks) (bean/->js branch-diffblocks)) merged (.mergeBlocks merger (bean/->js base-diffblocks) (bean/->js branch-diffblocks))
;; For extracting diff-merge test cases
;; _ (prn "input:")
;; _ (prn (js/JSON.stringify (bean/->js base-diffblocks)))
;; _ (prn (js/JSON.stringify (bean/->js branch-diffblocks)))
;; _ (prn "logseq diff merge version: " version)
;; _ (prn "output:")
;; _ (prn (js/JSON.stringify merged))
merged-diff (bean/->clj merged) merged-diff (bean/->clj merged)
merged-content (rebuild-content base-diffblocks merged-diff format)] merged-content (rebuild-content base-diffblocks merged-diff format)]
merged-content)) merged-content))

View File

@ -1,13 +1,13 @@
(ns frontend.fs.diff-merge-test (ns frontend.fs.diff-merge-test
(:require [cljs.test :refer [deftest are is]] (:require [cljs-bean.core :as bean]
[logseq.db :as ldb] [cljs.test :refer [are deftest is]]
[logseq.graph-parser :as graph-parser] [frontend.db.conn :as conn]
[logseq.graph-parser.text :as text]
[frontend.fs.diff-merge :as fs-diff] [frontend.fs.diff-merge :as fs-diff]
[frontend.handler.common.file :as file-common-handler] [frontend.handler.common.file :as file-common-handler]
[frontend.db.conn :as conn] [logseq.db :as ldb]
[logseq.graph-parser :as graph-parser]
[logseq.graph-parser.mldoc :as gp-mldoc] [logseq.graph-parser.mldoc :as gp-mldoc]
[cljs-bean.core :as bean])) [logseq.graph-parser.text :as text]))
(defn test-db->diff-blocks (defn test-db->diff-blocks
"A hijacked version of db->diff-blocks for testing. "A hijacked version of db->diff-blocks for testing.
@ -29,18 +29,18 @@
:ID: 72289d9a-eb2f-427b-ad97-b605a4b8c59b :ID: 72289d9a-eb2f-427b-ad97-b605a4b8c59b
:END: :END:
#+tItLe: Well parsed!" #+tItLe: Well parsed!"
[{:body ":PROPERTIES:\n:ID: 72289d9a-eb2f-427b-ad97-b605a4b8c59b\n:END:\n#+tItLe: Well parsed!" [{:body ":PROPERTIES:\n:ID: 72289d9a-eb2f-427b-ad97-b605a4b8c59b\n:END:\n#+tItLe: Well parsed!"
:uuid "72289d9a-eb2f-427b-ad97-b605a4b8c59b" :uuid "72289d9a-eb2f-427b-ad97-b605a4b8c59b"
:level 1}] :level 1}]
"#+title: Howdy" "#+title: Howdy"
[{:body "#+title: Howdy" :uuid nil :level 1}] [{:body "#+title: Howdy" :uuid nil :level 1}]
":PROPERTIES: ":PROPERTIES:
:fiction: [[aldsjfklsda]] :fiction: [[aldsjfklsda]]
:END:\n#+title: Howdy" :END:\n#+title: Howdy"
[{:body ":PROPERTIES:\n:fiction: [[aldsjfklsda]]\n:END:\n#+title: Howdy" [{:body ":PROPERTIES:\n:fiction: [[aldsjfklsda]]\n:END:\n#+title: Howdy"
:uuid nil :uuid nil
:level 1}])) :level 1}]))
(deftest db<->ast-diff-blocks-test (deftest db<->ast-diff-blocks-test
@ -85,7 +85,7 @@
\t\t\t- nice \t\t\t- nice
\t\t\t- bingo \t\t\t- bingo
\t\t\t- world" \t\t\t- world"
[{:body "## hello" :uuid nil :level 2} [{:body "## hello" :uuid nil :level 1}
{:body "world" :uuid nil :level 2} {:body "world" :uuid nil :level 2}
{:body "nice" :uuid nil :level 3} {:body "nice" :uuid nil :level 3}
{:body "nice" :uuid nil :level 4} {:body "nice" :uuid nil :level 4}
@ -103,20 +103,20 @@
\t- i \t- i
- j" - j"
[{:body "# a" :uuid nil :level 1} [{:body "# a" :uuid nil :level 1}
{:body "## b" :uuid nil :level 2} {:body "## b" :uuid nil :level 1}
{:body "### c" :uuid nil :level 3} {:body "### c" :uuid nil :level 1}
{:body "#### d" :uuid nil :level 4} {:body "#### d" :uuid nil :level 1}
{:body "### e" :uuid nil :level 3} {:body "### e" :uuid nil :level 1}
{:body "f" :uuid nil :level 1} {:body "f" :uuid nil :level 1}
{:body "g" :uuid nil :level 2} {:body "g" :uuid nil :level 2}
{:body "h" :uuid nil :level 3} {:body "h" :uuid nil :level 3}
{:body "i" :uuid nil :level 2} {:body "i" :uuid nil :level 2}
{:body "j" :uuid nil :level 1}] {:body "j" :uuid nil :level 1}]
"- a\n id:: 63e25526-3612-4fb1-8cf9-f66db1254a58 "- a\n id:: 63e25526-3612-4fb1-8cf9-f66db1254a58
\t- b \t- b
\t\t- c" \t\t- c"
[{:body "a\nid:: 63e25526-3612-4fb1-8cf9-f66db1254a58" [{:body "a\nid:: 63e25526-3612-4fb1-8cf9-f66db1254a58"
:uuid "63e25526-3612-4fb1-8cf9-f66db1254a58" :level 1} :uuid "63e25526-3612-4fb1-8cf9-f66db1254a58" :level 1}
{:body "b" :uuid nil :level 2} {:body "b" :uuid nil :level 2}
{:body "c" :uuid nil :level 3}])) {:body "c" :uuid nil :level 3}]))
@ -142,10 +142,10 @@
;; See https://github.com/logseq/diff-merge#usage ;; See https://github.com/logseq/diff-merge#usage
[[] [[]
[[-1 {:body "## hello" [[-1 {:body "## hello"
:level 2 :level 1
:uuid nil}] :uuid nil}]
[1 {:body "## Halooooo" [1 {:body "## Halooooo"
:level 2 :level 1
:uuid nil}]] :uuid nil}]]
[[0 {:body "world" [[0 {:body "world"
:level 2 :level 2
@ -162,7 +162,7 @@
[[0 {:body "world" [[0 {:body "world"
:level 4 :level 4
:uuid nil}]]] :uuid nil}]]]
"## hello "## hello
\t- world \t- world
\t id:: 63e25526-3612-4fb1-8cf9-abcd12354abc \t id:: 63e25526-3612-4fb1-8cf9-abcd12354abc
@ -180,10 +180,10 @@
;; See https://github.com/logseq/diff-merge#usage ;; See https://github.com/logseq/diff-merge#usage
[[] [[]
[[-1 {:body "## hello" [[-1 {:body "## hello"
:level 2 :level 1
:uuid nil}] :uuid nil}]
[1 {:body "## Halooooo" [1 {:body "## Halooooo"
:level 2 :level 1
:uuid nil}] :uuid nil}]
[1 {:body "world" [1 {:body "world"
:level 2 :level 2
@ -234,7 +234,7 @@
"bar" "bar"
[{:body "ghi\nid:: 11451411-1111-1111-1111-111111111111" :uuid "11451411-1111-1111-1111-111111111111" :level 1} [{:body "ghi\nid:: 11451411-1111-1111-1111-111111111111" :uuid "11451411-1111-1111-1111-111111111111" :level 1}
{:body "jkl\nid:: 63241234-1234-1234-1234-123412341234" :uuid "63241234-1234-1234-1234-123412341234" :level 2}]) {:body "jkl\nid:: 63241234-1234-1234-1234-123412341234" :uuid "63241234-1234-1234-1234-123412341234" :level 2}])
(are [page-name text new-uuids] (= (let [old-blks (test-db->diff-blocks conn page-name) (are [page-name text new-uuids] (= (let [old-blks (test-db->diff-blocks conn page-name)
new-blks (text->diffblocks text) new-blks (text->diffblocks text)
@ -271,7 +271,7 @@
[[["Properties" [["TiTlE" "Howdy" []]]] nil]] [[["Properties" [["TiTlE" "Howdy" []]]] nil]]
"#+title: Howdy" "#+title: Howdy"
[{:body "#+title: Howdy", :level 1, :uuid nil}]) [{:body "#+title: Howdy", :level 1, :uuid nil}])
(are [ast text diff-blocks] (are [ast text diff-blocks]
(= (fs-diff/ast->diff-blocks ast text :org {:block-pattern "-" :user-config {:property-pages/enabled? true}}) (= (fs-diff/ast->diff-blocks ast text :org {:block-pattern "-" :user-config {:property-pages/enabled? true}})
diff-blocks) diff-blocks)
@ -349,7 +349,7 @@
foo-new-content foo-new-content
"foo-persist" "foo-persist"
(fn [db-uuids] (conj db-uuids nil)) (fn [db-uuids] (conj db-uuids nil))
;; Prepend a new line to bar ;; Prepend a new line to bar
(gp-mldoc/->edn new-bar-content (gp-mldoc/default-config :markdown)) (gp-mldoc/->edn new-bar-content (gp-mldoc/default-config :markdown))
new-bar-content new-bar-content
@ -379,7 +379,7 @@
(deftest test-remove-indentation-spaces (deftest test-remove-indentation-spaces
(is (= "" (gp-mldoc/remove-indentation-spaces "" 0 false))) (is (= "" (gp-mldoc/remove-indentation-spaces "" 0 false)))
(is (= "" (gp-mldoc/remove-indentation-spaces "" 3 true))) (is (= "" (gp-mldoc/remove-indentation-spaces "" 3 true)))
(is (= "- nice\n happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 3 true))) (is (= "- nice\n happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 3 true)))
(is (= "\t\t\t- nice\n happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 3 false))) (is (= "\t\t\t- nice\n happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 3 false)))
(is (= "\t\t\t- nice\n\t\t\t happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 0 true)))) (is (= "\t\t\t- nice\n\t\t\t happy" (gp-mldoc/remove-indentation-spaces "\t\t\t- nice\n\t\t\t happy" 0 true))))
@ -389,3 +389,11 @@
(is (= "nice\n\t\t\t good" (text/remove-level-spaces "\t\t\t- nice\n\t\t\t good" :markdown "-"))) (is (= "nice\n\t\t\t good" (text/remove-level-spaces "\t\t\t- nice\n\t\t\t good" :markdown "-")))
(is (= "- nice" (text/remove-level-spaces "\t\t\t- nice" :markdown ""))) (is (= "- nice" (text/remove-level-spaces "\t\t\t- nice" :markdown "")))
(is (= "nice" (text/remove-level-spaces "\t\t\t- nice" :markdown "-")))) (is (= "nice" (text/remove-level-spaces "\t\t\t- nice" :markdown "-"))))
(deftest test-three-way-merge
(is (= (fs-diff/three-way-merge
"- a\n id:: 648ab5e6-5e03-4c61-95d4-dd904a0a007f\n- b"
"- a\n id:: 648ab5e6-5e03-4c61-95d4-dd904a0a007f\n aaa:: 111\n- b"
"- c"
:markdown)
"- a\n id:: 648ab5e6-5e03-4c61-95d4-dd904a0a007f\n aaa:: 111\n- c")))

View File

@ -27,17 +27,19 @@
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 22 "3" 4 6 nil nil nil)} #{(sync/->FileMetadata 1 22 "3" 4 6 nil nil nil)}
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 22 "3" 4 4 nil nil nil) (sync/->FileMetadata 1 22 "3" 44 5 nil nil nil)} #{(sync/->FileMetadata 1 22 "3" 4 4 nil nil nil)
(sync/->FileMetadata 1 22 "3" 44 5 nil nil nil)}
#{} #{}
#{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 5 nil nil nil)}
#{(sync/->FileMetadata 1 2 "3" 4 4 nil nil nil) (sync/->FileMetadata 1 2 "3" 4 6 nil nil nil)} #{(sync/->FileMetadata 1 2 "3" 4 4 nil nil nil)
(sync/->FileMetadata 1 2 "3" 4 6 nil nil nil)}
) )
) )

View File

@ -492,10 +492,10 @@
resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.30.tgz#9441ad5689f6139acbc7444530b11e0648a586b3" resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.30.tgz#9441ad5689f6139acbc7444530b11e0648a586b3"
integrity sha512-rrk4CdSyS8y1M3WgqkFtdtoP3YWRhuaaQOPtO18roOTztbwdu/w7/+uEt7RDVcV92rwCjhCeg4yaTxbmgWwFYw== integrity sha512-rrk4CdSyS8y1M3WgqkFtdtoP3YWRhuaaQOPtO18roOTztbwdu/w7/+uEt7RDVcV92rwCjhCeg4yaTxbmgWwFYw==
"@logseq/diff-merge@^0.0.3": "@logseq/diff-merge@0.1.0":
version "0.0.3" version "0.1.0"
resolved "https://registry.yarnpkg.com/@logseq/diff-merge/-/diff-merge-0.0.3.tgz#bf60de2142d95b8343d7420914f9558b003a09e6" resolved "https://registry.yarnpkg.com/@logseq/diff-merge/-/diff-merge-0.1.0.tgz#fca282e3ff7c256a1f447d0463d78fb23ebee1d9"
integrity sha512-/2fwGWK9GXM1zHq4+GUToTT5eyYWo+A4IzRDIU+Rsp9mlEfeWcUBFkGR0YHRgxAL16X1F1pp+B2OKQ0CXuGYqQ== integrity sha512-VNAJI7Mo/xHEw2LN6rpoWf/BbVfsC1wRpyyLbvm1jQbRxcwRgqYwWkSIVS0t1wswquDS64ZolJkCIFXeNXQbTA==
"@logseq/react-tweet-embed@1.3.1-1": "@logseq/react-tweet-embed@1.3.1-1":
version "1.3.1-1" version "1.3.1-1"