Skip to content

Commit 1d862fc

Browse files
committed
paths
1 parent 6cf1230 commit 1d862fc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/datomic/codeq/core.clj

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@
129129
:db/doc "filename of a tree node"
130130
:db.install/_attribute :db.part/db}
131131

132+
{:db/id #db/id[:db.part/db]
133+
:db/ident :git/paths
134+
:db/valueType :db.type/ref
135+
:db/cardinality :db.cardinality/many
136+
:db/doc "paths of a tree node"
137+
:db.install/_attribute :db.part/db}
138+
132139
{:db/id #db/id[:db.part/db]
133140
:db/ident :git/object
134141
:db/valueType :db.type/ref
@@ -280,29 +287,38 @@
280287
authorid (email->id author)
281288
committerid (email->id committer)
282289
cid (d/tempid :db.part/user)
283-
tx-data (fn f [[sha type filename]]
284-
(let [id (sha->id sha)
290+
tx-data (fn f [inpath [sha type filename]]
291+
(let [path (str inpath filename)
292+
id (sha->id sha)
285293
filenameid (filename->id filename)
294+
pathid (filename->id path)
286295
nodeid (or (and (not (tempid? id))
287296
(not (tempid? filenameid))
288297
(ffirst (d/q '[:find ?e :in $ ?filename ?id
289298
:where [?e :git/filename ?filename] [?e :git/object ?id]]
290299
db filenameid id)))
291300
(d/tempid :db.part/user))
301+
newpath (or (tempid? pathid) (tempid? nodeid)
302+
(not (ffirst (d/q '[:find ?node :in $ ?path
303+
:where [?node :git/paths ?path]]
304+
db pathid))))
292305
data (cond-> []
293306
(tempid? filenameid) (conj [:db/add filenameid :file/name filename])
307+
(tempid? pathid) (conj [:db/add pathid :file/name path])
294308
(tempid? nodeid) (conj {:db/id nodeid :git/filename filenameid :git/object id})
309+
newpath (conj [:db/add nodeid :git/paths pathid])
295310
(tempid? id) (conj {:db/id id :git/sha sha :git/type type}))
296-
data (if (and (tempid? id) (= type :tree))
311+
data (if (and newpath (= type :tree))
297312
(let [es (dir sha)]
298313
(reduce (fn [data child]
299-
(let [[cid cdata] (f child)
314+
(let [[cid cdata] (f (str path "/") child)
300315
data (into data cdata)]
301-
(conj data [:db/add id :git/nodes cid])))
316+
(cond-> data
317+
(tempid? id) (conj [:db/add id :git/nodes cid]))))
302318
data es))
303319
data)]
304320
[nodeid data]))
305-
[treeid treedata] (tx-data [tree :tree repo-name])
321+
[treeid treedata] (tx-data nil [tree :tree repo-name])
306322
tx (into treedata
307323
[[:db/add repo :git/commits cid]
308324
{:db/id (d/tempid :db.part/tx)
@@ -404,6 +420,6 @@
404420
(def conn (d/connect uri))
405421
(def db (d/db conn))
406422
(seq (d/datoms db :aevt :file/name))
407-
(seq (d/datoms db :aevt :git/tree))
423+
(seq (d/datoms db :aevt :git/object))
408424
(d/q '[:find ?e :where [?f :file/name "core.clj"] [?n :git/filename ?f] [?n :git/object ?e]] db)
409425
)

0 commit comments

Comments
 (0)