Skip to content

Commit 7225f76

Browse files
committed
simplify zen configs, delta upd inp, add events
1 parent 21a6ae9 commit 7225f76

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

src/zd/core.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[ring.util.codec]
1111
[zd.view.core :as view])
1212
(:import [org.httpkit BytesInputStream]
13+
[org.eclipse.jgit.revwalk RevWalk]
14+
[org.eclipse.jgit.diff DiffFormatter]
1315
[java.io ByteArrayOutputStream]))
1416

1517

@@ -207,17 +209,14 @@
207209

208210
(def ztx (start))
209211

210-
211212
(stop ztx)
212213

213214
(:zd/backlinks @ztx)
214215

215-
(def out (ByteArrayOutputStream.))
216+
(git/exec {:dir (:zd/dir @ztx) :exec ["git" "log" "-1"]})
216217

217-
(-> (.diff (:zd/repo @ztx))
218-
(.setShowNameAndStatusOnly true)
219-
(.setOutputStream out)
220-
(.call))
218+
(git/exec {:dir (:zd/dir @ztx) :exec ["git" "diff" "--name-only" "4a569701e759120e8638eb46f8bedd4964b3250a"
219+
"7b7fa19bd92422ab9a2544599a1deb1360a19a25"]})
221220

222221
(config ztx)
223222
(store/re-validate ztx)

src/zd/store.clj

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns zd.store
22
(:require [zen.core :as zen]
3+
[zd.git :as zgit]
34
[clj-jgit.porcelain :as git]
45
[zd.parser]
56
[xtdb.api :as xt]
@@ -105,7 +106,10 @@
105106
(defn put-doc
106107
[ztx {docname :zd/docname :as doc}]
107108
(if (and doc docname)
108-
(swap! ztx assoc-in [:zdb docname] (assoc doc :zd/parent (parent-name docname)))
109+
(let [doc* (assoc doc :zd/parent (parent-name docname))]
110+
(swap! ztx assoc-in [:zdb docname] doc*)
111+
(zen/pub ztx 'zd.events/on-doc-load doc*))
112+
;; TODO emit zen event
109113
(println :put/error doc))
110114
doc)
111115

@@ -390,15 +394,31 @@
390394

391395
(extract-docname ":a 1\n:zd/docname docname\n:b 1")
392396

397+
(defn last-commit-hash [ztx]
398+
(->> {:dir (:zd/dir @ztx) :exec ["git" "log" "-1"]}
399+
(zgit/exec)
400+
(:stdout)
401+
(first)
402+
(drop-while #(not= % \space))
403+
(rest)
404+
(apply str)))
405+
393406
(defn commit-changes
394407
"commit added, changed files and push"
395408
[ztx docpath docname]
396409
(when-let [repo (:zd/repo @ztx)]
397410
(git/with-identity ident
398411
(let [;; TODO sync all untracked docs at gitsync start?
399412
{:keys [untracked modified] :as status} (git/git-status repo)
400-
git-config (git/git-config-load repo)]
413+
git-config (git/git-config-load repo)
414+
;; TODO use jgit instead of execs, understand interop
415+
ours-last (last-commit-hash ztx)]
401416
(git/git-pull repo {:ff-mode :ff :rebase-mode :none :strategy :ours})
417+
(let [their-last (last-commit-hash ztx)]
418+
(when (not= ours-last their-last)
419+
(zgit/exec {:dir (:zd/dir @ztx)
420+
:exec ["git" "diff" "--name-only" their-last ours-last]})))
421+
402422
(doseq [m (into untracked modified)]
403423
(when (str/includes? docpath m)
404424
(let [uname (or (.getString git-config "user" nil "name") "unknown editor")
@@ -486,6 +506,7 @@
486506
"read docs from filesystem and load into memory"
487507
[ztx & [dir]]
488508
(let [dir (or dir (:zd/dir @ztx))]
509+
(zen/pub ztx 'zd.events/on-load-start {})
489510
(load-meta ztx)
490511
(load-repo ztx)
491512
(->> (dir-read ztx dir)
@@ -497,7 +518,8 @@
497518
(fn [_docname doc]
498519
(let [idoc (doc-inference ztx doc)]
499520
(re-index-doc ztx idoc)
500-
idoc)))))
521+
idoc)))
522+
(zen/pub ztx 'zd.events/on-load-complete {})))
501523

502524
(defn menu
503525
"return navigation"

zrc/zd.edn

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
{:ns zd
22
:import #{zen-web zd.engines zd.events}
33

4-
remote
5-
{:zen/tags #{zen/schema}
6-
:type zen/map
7-
;; TODO use zen-web/url
8-
:require #{:from}
9-
:keys {:from {:type zen/string}
10-
:key {:type zen/string
11-
:zen/desc "private ssh key to use"}
12-
:keystore {:type zen/string
13-
:zen/desc "ssh keys directory"}
14-
:to {:type zen/string}
15-
:branch {:type zen/string}}}
16-
174
zendoc-config
185
{:zen/tags #{zen/tag zen/schema}
196
:type zen/map
20-
:keys {:root {:type zen/string}
21-
:paths {:type zen/vector
22-
:every {:type zen/string}}
23-
:pull-rate {:type zen/integer}
24-
:remote {:confirms #{remote}}
25-
:remotes {:type zen/vector
26-
:every {:confirms #{remote}}}}}
7+
:keys {:dir {:type zen/string}}}
278

289
query
2910
{:zen/tags #{zen/op}
@@ -136,7 +117,7 @@
136117
:api api}
137118

138119
zendoc
139-
{:zen/tags #{zen/start}
120+
{:zen/tags #{zen/start zendoc-config}
140121
:zen/state-key :zd/config
141122
:dir "docs"}
142123

zrc/zd/events.edn

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
:zen/desc "event when key rendering throws exception"
66
:type zen/map}
77

8-
sub
9-
{:zen/tags #{zen/tag zen/schema}
10-
:type zen/map
11-
:keys {:config {:type zen/symbol :tags #{zd/zendoc}}}}
12-
138
on-doc-save
149
{:zen/tags #{zen/event zen/schema}
1510
:zen/desc "save document in an api"

0 commit comments

Comments
 (0)