Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
at benchs 54 lines 1.9 kB view raw
1(** Export command - export store to external formats. *) 2 3let run ~repo ~branch ~output () = 4 let config = Config.load ~repo () in 5 Eio_main.run @@ fun env -> 6 let fs = Eio.Stdenv.cwd env in 7 Eio.Switch.run @@ fun sw -> 8 let is_car = 9 String.length output > 4 10 && String.sub output (String.length output - 4) 4 = ".car" 11 in 12 match config.Config.backend with 13 | Config.Git when is_car -> 14 Common.error "CAR export not yet supported for Git backend"; 15 1 16 | Config.Git -> ( 17 (* Export as bundle or tar - for now just list what would be exported *) 18 let git_dir = Fpath.(v config.store_path / ".git") in 19 let store = Irmin.Git_interop.import_git ~sw ~fs ~git_dir in 20 match Irmin.Store.Git.checkout store ~branch with 21 | None -> 22 Common.error "Branch %a not found" Common.styled_cyan branch; 23 1 24 | Some tree -> 25 let rec count_entries path = 26 let entries = Irmin.Tree.Git.list tree path in 27 List.fold_left 28 (fun acc (name, kind) -> 29 match kind with 30 | `Contents -> acc + 1 31 | `Node -> count_entries (path @ [ name ]) + acc) 32 0 entries 33 in 34 let n = count_entries [] in 35 Common.error "Export to %s not yet implemented (%d entries)" output n; 36 1) 37 | Config.Mst | Config.Memory -> 38 if is_car then begin 39 let irmin_dir = Filename.concat config.store_path ".irmin" in 40 let blocks_path = Filename.concat irmin_dir "blocks" in 41 if not (Sys.file_exists blocks_path) then begin 42 Common.error "No MST store found"; 43 1 44 end 45 else begin 46 (* TODO: Export CAR from blockstore *) 47 Common.error "CAR export not yet implemented"; 48 1 49 end 50 end 51 else begin 52 Common.error "Only .car export supported for MST backend"; 53 1 54 end