@@ -2,13 +2,15 @@ open Lwt.Infix
22open Canopy_config
33open Canopy_utils
44
5+
56module Store (CTX : Irmin_mirage.CONTEXT ) (INFL : Git.Inflate.S ) = struct
67
78 module Hash = Irmin.Hash. SHA1
89 module Mirage_git_memory = Irmin_mirage.Irmin_git. Memory (CTX )(INFL )
910 module Store = Mirage_git_memory (Irmin.Contents. String )(Irmin.Ref. String )(Hash )
1011 module Sync = Irmin. Sync (Store )
1112 module Topological = Graph.Topological. Make (Store. History )
13+ module View = Irmin. View (Store )
1214
1315 let src = Logs.Src. create " canopy-store" ~doc: " Canopy store logger"
1416 module Log = (val Logs. src_log src : Logs.LOG )
@@ -77,33 +79,35 @@ module Store (CTX: Irmin_mirage.CONTEXT) (INFL: Git.Inflate.S) = struct
7779 in
7880 Topological. fold aux history (Lwt. return (commit, commit, None ))
7981
82+ let set_diffs repo c1 c2 =
83+ let view_of_commit repo commit_id =
84+ Store. of_commit_id task commit_id repo >> = fun t ->
85+ View. of_path (t " view" ) []
86+ in
87+ view_of_commit repo c1 >> = fun v1 ->
88+ view_of_commit repo c2 >> = fun v2 ->
89+ View. diff v1 v2 > |= fun diffs ->
90+ diffs
91+
8092 let fill_history_cache () =
8193 new_task () >> = fun t ->
8294 repo () >> = fun repo ->
8395 Store. history (t " Reading history" ) >> = fun history ->
84- let fn key value cache =
85- value () >> = fun value ->
86- match key_type key with
87- | `Article -> (
88- let uri = String. concat " /" key in
89- match KeyMap. find_opt cache key with
90- | None ->
91- let create_event = Printf. sprintf " Article added: %s" uri in
92- KeyMap. add key create_event cache |> Lwt. return
93- | Some old_value ->
94- if old_value = value then Lwt. return cache
95- else
96- let update_event = Printf. sprintf " Article modified: %s" uri in
97- KeyMap. add key update_event cache |> Lwt. return
98- )
99- | `Static | `Config -> Lwt. return cache
100- in
10196 let aux commit_id acc =
102- Store. of_commit_id (Irmin.Task. none) commit_id repo >> = fun store ->
10397 acc >> = fun acc ->
104- fold (store () ) fn acc
98+ match acc with
99+ | None , acc_list ->
100+ (Some commit_id, acc_list) |> Lwt. return
101+ | Some prev_commit_id , acc_list ->
102+ Store.Repo. task_of_commit_id repo commit_id >> = fun task ->
103+ let timestamp = Irmin.Task. date task |> Int64. to_float |> Ptime. of_float_s in
104+ set_diffs repo prev_commit_id commit_id > |= fun diffs ->
105+ let c_history = Canopy_content. of_c_history timestamp diffs in
106+ let acc_list = List. append acc_list c_history in
107+ (Some commit_id, acc_list)
105108 in
106- Topological. fold aux history (Lwt. return KeyMap. empty)
109+ Topological. fold aux history (Lwt. return (None , [] )) > |= fun (_ , diffs ) ->
110+ diffs
107111
108112 let date_updated_created key =
109113 new_task () >> = fun t ->
0 commit comments