Get all keys using Irmin_git


I’m implementing a “database” using the irmin_git’s package and irmin_unix’s package, but I can’t figure out how to get all the branch’s keys.

I found the find_all function but as I see it’s like a find without metadata.

I have searched in the documentation but it’s pretty dense and I can’t find out which function can do the job for me.

Can you give me any clue to get what I want ?

I’m using Irmin 1.4.0 and Irmin_unix 1.3.3.

Here is my code :

module Git_store = Irmin_unix.Git.FS.KV(Irmin.Contents.String)
let git_config = Irmin_git.config ~bare:true "./irmin/"

let master config = Git_store.Repo.v config >>= Git_store.master
let branch config name = Git_store.Repo.v config >>= fun repo -> Git_store.of_branch repo name

(* de a vers b *)
let irmin = Git_store.Repo.v git_config >>= Git_store.master >>= fun t ->
           Git_store.find_all t [] >>= fun c ->
           (match c with
           | Some (b,_) -> Printf.printf "Read: %s \n%!" b ; Lwt.return_unit
           | None -> Printf.printf "Nop"; Lwt.return_unit)
           >>= fun () ->
           Server.respond_string ~status:`OK ~body:"OK" ()

Thanks in advance for your responses,

1 Like

First, it seems that you look into the documentation of irmin.2.0.0 where it seems that you use irmin.1.4.0.

Then, I’m not sure to understand what you want but from what I know, your type t represents a graph or more specially a tree with nodes and leafs. To be able to get all keys of your type t, you must walk inside the tree.

Such function exists with fold which will walk recursively into your tree. The given tree should be the root tree of your branch which can be get with tree.

More concretely with Git, a tree is a directory which can have some blobs (leafs) and the type t can be considered as a commit.


Thank you for your help !

I know but these functions doesn’t change between the 1.4.0 and the 2.0.0 version. I’m using the offline documentation with odig.

I’m a beginner with Irmin so I am sorry if my demand wasn’t clear.
That I want is to get all the keys of the current branch.
For example, when I add data with this :
Git_store.Tree.add tree ["test1"] user_1
Git_store.Tree.add tree ["test2"] user_2
I am searching a way to get a String list like this ["test1";"test2";...]

As I understand, the fold function will execute my function f if it got a leaf, and if not (So it’s a node) it will recursively call itself by passing the node.
And the function f take key, contents and 'a in parameters which will be given by fold. For example, can the key and the content be the ["test1"] and user_1 I added before ?

Thanks for your reply