Skip to content

Commit

Permalink
simplify zen configs, delta upd inp, add events
Browse files Browse the repository at this point in the history
  • Loading branch information
carbon-hvze committed Sep 5, 2023
1 parent 21a6ae9 commit 7225f76
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
11 changes: 5 additions & 6 deletions src/zd/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[ring.util.codec]
[zd.view.core :as view])
(:import [org.httpkit BytesInputStream]
[org.eclipse.jgit.revwalk RevWalk]
[org.eclipse.jgit.diff DiffFormatter]
[java.io ByteArrayOutputStream]))


Expand Down Expand Up @@ -207,17 +209,14 @@

(def ztx (start))


(stop ztx)

(:zd/backlinks @ztx)

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

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

(config ztx)
(store/re-validate ztx)
Expand Down
28 changes: 25 additions & 3 deletions src/zd/store.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns zd.store
(:require [zen.core :as zen]
[zd.git :as zgit]
[clj-jgit.porcelain :as git]
[zd.parser]
[xtdb.api :as xt]
Expand Down Expand Up @@ -105,7 +106,10 @@
(defn put-doc
[ztx {docname :zd/docname :as doc}]
(if (and doc docname)
(swap! ztx assoc-in [:zdb docname] (assoc doc :zd/parent (parent-name docname)))
(let [doc* (assoc doc :zd/parent (parent-name docname))]
(swap! ztx assoc-in [:zdb docname] doc*)
(zen/pub ztx 'zd.events/on-doc-load doc*))
;; TODO emit zen event
(println :put/error doc))
doc)

Expand Down Expand Up @@ -390,15 +394,31 @@

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

(defn last-commit-hash [ztx]
(->> {:dir (:zd/dir @ztx) :exec ["git" "log" "-1"]}
(zgit/exec)
(:stdout)
(first)
(drop-while #(not= % \space))
(rest)
(apply str)))

(defn commit-changes
"commit added, changed files and push"
[ztx docpath docname]
(when-let [repo (:zd/repo @ztx)]
(git/with-identity ident
(let [;; TODO sync all untracked docs at gitsync start?
{:keys [untracked modified] :as status} (git/git-status repo)
git-config (git/git-config-load repo)]
git-config (git/git-config-load repo)
;; TODO use jgit instead of execs, understand interop
ours-last (last-commit-hash ztx)]
(git/git-pull repo {:ff-mode :ff :rebase-mode :none :strategy :ours})
(let [their-last (last-commit-hash ztx)]
(when (not= ours-last their-last)
(zgit/exec {:dir (:zd/dir @ztx)
:exec ["git" "diff" "--name-only" their-last ours-last]})))

(doseq [m (into untracked modified)]
(when (str/includes? docpath m)
(let [uname (or (.getString git-config "user" nil "name") "unknown editor")
Expand Down Expand Up @@ -486,6 +506,7 @@
"read docs from filesystem and load into memory"
[ztx & [dir]]
(let [dir (or dir (:zd/dir @ztx))]
(zen/pub ztx 'zd.events/on-load-start {})
(load-meta ztx)
(load-repo ztx)
(->> (dir-read ztx dir)
Expand All @@ -497,7 +518,8 @@
(fn [_docname doc]
(let [idoc (doc-inference ztx doc)]
(re-index-doc ztx idoc)
idoc)))))
idoc)))
(zen/pub ztx 'zd.events/on-load-complete {})))

(defn menu
"return navigation"
Expand Down
23 changes: 2 additions & 21 deletions zrc/zd.edn
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
{:ns zd
:import #{zen-web zd.engines zd.events}

remote
{:zen/tags #{zen/schema}
:type zen/map
;; TODO use zen-web/url
:require #{:from}
:keys {:from {:type zen/string}
:key {:type zen/string
:zen/desc "private ssh key to use"}
:keystore {:type zen/string
:zen/desc "ssh keys directory"}
:to {:type zen/string}
:branch {:type zen/string}}}

zendoc-config
{:zen/tags #{zen/tag zen/schema}
:type zen/map
:keys {:root {:type zen/string}
:paths {:type zen/vector
:every {:type zen/string}}
:pull-rate {:type zen/integer}
:remote {:confirms #{remote}}
:remotes {:type zen/vector
:every {:confirms #{remote}}}}}
:keys {:dir {:type zen/string}}}

query
{:zen/tags #{zen/op}
Expand Down Expand Up @@ -136,7 +117,7 @@
:api api}

zendoc
{:zen/tags #{zen/start}
{:zen/tags #{zen/start zendoc-config}
:zen/state-key :zd/config
:dir "docs"}

Expand Down
5 changes: 0 additions & 5 deletions zrc/zd/events.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
:zen/desc "event when key rendering throws exception"
:type zen/map}

sub
{:zen/tags #{zen/tag zen/schema}
:type zen/map
:keys {:config {:type zen/symbol :tags #{zd/zendoc}}}}

on-doc-save
{:zen/tags #{zen/event zen/schema}
:zen/desc "save document in an api"
Expand Down

0 comments on commit 7225f76

Please sign in to comment.