From 1264fdad0af76f23eb1e31bae431a346f6d70010 Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Tue, 13 Jun 2023 14:48:31 +0200 Subject: [PATCH 1/2] Add the compression level argument into to_octets --- git-kv.opam | 6 ++++++ src/git_kv.ml | 8 ++++---- src/git_kv.mli | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/git-kv.opam b/git-kv.opam index 00f9963..1c241ac 100644 --- a/git-kv.opam +++ b/git-kv.opam @@ -13,6 +13,7 @@ depends: [ "git" {>= "3.10.0"} "mirage-kv" {>= "6.0.0"} "carton" {>= "0.6.0"} + "carton-lwt" {>= "0.6.0"} "fmt" {>= "0.8.7"} "mirage-clock" {>= "2.0.0"} "ptime" @@ -27,3 +28,8 @@ build: [ ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] + +pin-depends: [ + [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#98e15fda0b3f0d51fa215a56ffee808a83849765" ] + [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#98e15fda0b3f0d51fa215a56ffee808a83849765" ] +] diff --git a/src/git_kv.ml b/src/git_kv.ml index d46fec2..15b9802 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -183,7 +183,7 @@ let ( >>? ) x f = let open Lwt.Infix in match x with | None -> Lwt.return_none let ( >>! ) x f = Lwt.Infix.(x >>= f) -let pack t ~commit stream = +let pack t ?(level= 4) ~commit stream = let open Lwt.Infix in let load t hash = Store.read_inflated t hash >|= function @@ -227,7 +227,7 @@ let pack t ~commit stream = | Some None -> failwith "Try to encode an OBJ_REF object" (* XXX(dinosaure): should never occur! *) | Some (Some (_ (* offset *) : int)) | None -> Hashtbl.add offsets (Carton.Enc.target_uid targets.(idx)) !cursor ; - Carton_lwt.Enc.encode_target ~b ~find ~load:(load t) ~uid targets.(idx) ~cursor:(Int64.to_int !cursor) + Carton_lwt.Enc.encode_target ~level ~b ~find ~load:(load t) ~uid targets.(idx) ~cursor:(Int64.to_int !cursor) >>= fun (len, encoder) -> let payload = Bigstringaf.substring b.o ~off:0 ~len in stream (Some payload) ; @@ -254,7 +254,7 @@ let pack t ~commit stream = stream None ; Lwt.return_unit -let to_octets t = match t.head with +let to_octets ?level t = match t.head with | None -> Lwt.return "PACK\000\000\000\002\000\000\000\000\ \x02\x9d\x08\x82\x3b\xd8\xa8\xea\xb5\x10\xad\x6a\xc7\x5c\x82\x3c\xfd\x3e\xd3\x1e" @@ -262,7 +262,7 @@ let to_octets t = match t.head with let buf = Buffer.create 0x100 in let stream = Option.iter (Buffer.add_string buf) in let open Lwt.Infix in - pack t.store ~commit stream >|= fun () -> + pack ?level t.store ~commit stream >|= fun () -> Buffer.contents buf (* XXX(dinosaure): we have the full-control between [to_octets]/[of_octets] diff --git a/src/git_kv.mli b/src/git_kv.mli index bfc0020..b58d9d9 100644 --- a/src/git_kv.mli +++ b/src/git_kv.mli @@ -43,8 +43,10 @@ val connect : Mimic.ctx -> string -> t Lwt.t val branch : t -> Git.Reference.t (** [branch t] returns the branch used by the given [t]. *) -val to_octets : t -> string Lwt.t -(** [to_octets store] returns a serialized version of the given [store]. *) +val to_octets : ?level:int -> t -> string Lwt.t +(** [to_octets ?level store] returns a serialized version of the given [store]. + [level] is the {i zlib} level compression used for Git object (between [0] + and [9] including). *) val of_octets : Mimic.ctx -> remote:string -> string -> (t, [> `Msg of string]) result Lwt.t From cbfba38063fa626b5ad9cd1db3190f01527d29b7 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Sun, 11 Feb 2024 22:44:55 +0100 Subject: [PATCH 2/2] minor tweaks --- git-kv.opam | 9 ++------- src/git_kv.mli | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/git-kv.opam b/git-kv.opam index 1c241ac..eba381c 100644 --- a/git-kv.opam +++ b/git-kv.opam @@ -12,8 +12,8 @@ depends: [ "dune" {>= "2.9.0"} "git" {>= "3.10.0"} "mirage-kv" {>= "6.0.0"} - "carton" {>= "0.6.0"} - "carton-lwt" {>= "0.6.0"} + "carton" {>= "0.7.0"} + "carton-lwt" {>= "0.7.0"} "fmt" {>= "0.8.7"} "mirage-clock" {>= "2.0.0"} "ptime" @@ -28,8 +28,3 @@ build: [ ["dune" "build" "-p" name "-j" jobs] ["dune" "runtest" "-p" name "-j" jobs] {with-test} ] - -pin-depends: [ - [ "carton.dev" "git+https://github.com/mirage/ocaml-git.git#98e15fda0b3f0d51fa215a56ffee808a83849765" ] - [ "carton-lwt.dev" "git+https://github.com/mirage/ocaml-git.git#98e15fda0b3f0d51fa215a56ffee808a83849765" ] -] diff --git a/src/git_kv.mli b/src/git_kv.mli index b58d9d9..2a72f53 100644 --- a/src/git_kv.mli +++ b/src/git_kv.mli @@ -46,7 +46,7 @@ val branch : t -> Git.Reference.t val to_octets : ?level:int -> t -> string Lwt.t (** [to_octets ?level store] returns a serialized version of the given [store]. [level] is the {i zlib} level compression used for Git object (between [0] - and [9] including). *) + and [9] including), defaults to [4]. *) val of_octets : Mimic.ctx -> remote:string -> string -> (t, [> `Msg of string]) result Lwt.t