[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [MirageOS-devel] Question: Diff between 2 commits in Irmin
Hi, > > I'm trying to generate a list of 10-20 most recent events in Canopy. These > events would be changes done to Articles (modifications, deletions, > additions). I'd like to get the changes introduced by each commit from latest > to the earliest. How do I do that in Irmin? > > Will `Irmin.View.diff` help me do the above? If so, how do I get a type `t` > that it expects as its first 2 arguments? What is `t` in that context? > https://github.com/mirage/irmin/blob/master/lib/ir_view.mli#L42 The online API doc is probably better to read that the (internal) mli file: http://mirage.github.io/irmin/Irmin.View.html Here a (simple?) example on how to use that API: ```diff.ml open Lwt.Infix open Irmin_unix module S = Irmin_git.FS(Irmin.Contents.String)(Irmin.Ref.String)(Irmin.Hash.SHA1) module V = Irmin.View(S) let view_of_commit repo c = S.of_commit_id task c repo >>= fun t -> V.of_path (t "view") [] let diff repo c1 c2 = view_of_commit repo c1 >>= fun v1 -> view_of_commit repo c2 >>= fun v2 -> V.diff v1 v2 >|= fun diff -> List.iter (function | k, `Added _ -> Printf.printf "+ %s\n%!" (S.Key.to_hum k) | k, `Updated _ -> Printf.printf "* %s\n%!" (S.Key.to_hum k) | k, `Removed _ -> Printf.printf "- %s\n%!" (S.Key.to_hum k) ) diff let () = let c1 = S.Hash.of_hum Sys.argv.(1) in let c2 = S.Hash.of_hum Sys.argv.(2) in Lwt_main.run begin S.Repo.create (Irmin_git.config ~root:"." ()) >>= fun repo -> diff repo c1 c2 end ``` compile it with: $ ocamlfind ocamlopt -package irmin.unix diff.ml -o diff -linkpkg And then, you can use it in a Git repo: $ git init $ touch a && git add a && git commit -a -m "add a" 167602309fffb440bd44e51cdba2e465df799f23 $ touch b && git add b && git commit -a -m "add b" be3c9d683d26e861e32c93b6fa7d17a70f61ee86 $ ./diff be3c9d683d26e861e32c93b6fa7d17a70f61ee86 167602309fffb440bd44e51cdba2e465df799f23 ./foo be3c9d683d26e861e32c93b6fa7d17a70f61ee86 167602309fffb440bd44e51cdba2e465df799f23 + /b > Btw, what are open-source projects that are great examples of how to use > Irmin? At Docker, we use Irmin in datakit at Docker: https://github.com/docker/datakit Datakit is an in-memory VFS which can be mounted as a normal filesystem (currently we only support 9p, but it should be doable to use fuse too) and which uses Irmin to persist data. We use it in Docker for Mac and Docker for Windows[1] to exposes configuration data stored in a Git repository on the host (Window or OSX) into a FS mount in a Linux VM (running the Docker daemon)[2]. We also use it for our internal CI to coordinate build pipelines[3] -- we plan to use it to test MirageOS too[4]. Best, Thomas [1]: https://www.docker.com/products/docker#/mac [2]: https://github.com/docker/hyperkit [3]: https://github.com/docker/datakit/tree/master/ci [4]: https://github.com/avsm/mirage-ci _______________________________________________ MirageOS-devel mailing list MirageOS-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |