Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decompress in ocaml-git #145

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .merlin
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG cstruct logs ocamlgraph re zip uri lwt mstruct cmdliner mirage-types
PKG nocrypto hex cohttp.lwt mirage-flow tcpip mirage-http alcotest fmt
PKG crc mirage-fs-unix astring mtime.os
PKG crc mirage-fs-unix astring mtime.os decompress
B _build/**
S lib/
S lib/
2 changes: 1 addition & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Library git
Sync, Gri, Search, Global_graph, User, Store,
Memory, FS, Version
BuildDepends: mstruct, logs, ocamlgraph, uri, lwt, hex, astring,
crc, fmt
crc, fmt, decompress

Library git_top
Path: lib/top
Expand Down
10 changes: 9 additions & 1 deletion _tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: 1f887a5c66fe18fa975c85eb35845de1)
# DO NOT EDIT (digest: 90381a679a56d9478299f2b1bc256f13)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
Expand Down Expand Up @@ -44,6 +44,7 @@ true: annot, bin_annot
"lib/LRU.cmx": for-pack(Git)
<lib/*.ml{,i,y}>: pkg_astring
<lib/*.ml{,i,y}>: pkg_crc
<lib/*.ml{,i,y}>: pkg_decompress
<lib/*.ml{,i,y}>: pkg_fmt
<lib/*.ml{,i,y}>: pkg_hex
<lib/*.ml{,i,y}>: pkg_logs
Expand All @@ -59,6 +60,7 @@ true: annot, bin_annot
<lib/http/*.ml{,i,y}>: pkg_astring
<lib/http/*.ml{,i,y}>: pkg_cohttp.lwt
<lib/http/*.ml{,i,y}>: pkg_crc
<lib/http/*.ml{,i,y}>: pkg_decompress
<lib/http/*.ml{,i,y}>: pkg_fmt
<lib/http/*.ml{,i,y}>: pkg_hex
<lib/http/*.ml{,i,y}>: pkg_logs
Expand All @@ -74,6 +76,7 @@ true: annot, bin_annot
<lib/unix/*.ml{,i,y}>: pkg_cohttp.lwt
<lib/unix/*.ml{,i,y}>: pkg_conduit.lwt-unix
<lib/unix/*.ml{,i,y}>: pkg_crc
<lib/unix/*.ml{,i,y}>: pkg_decompress
<lib/unix/*.ml{,i,y}>: pkg_fmt
<lib/unix/*.ml{,i,y}>: pkg_hex
<lib/unix/*.ml{,i,y}>: pkg_logs
Expand All @@ -94,6 +97,7 @@ true: annot, bin_annot
<lib/mirage/*.ml{,i,y}>: pkg_cohttp.lwt
<lib/mirage/*.ml{,i,y}>: pkg_conduit.mirage
<lib/mirage/*.ml{,i,y}>: pkg_crc
<lib/mirage/*.ml{,i,y}>: pkg_decompress
<lib/mirage/*.ml{,i,y}>: pkg_dns.mirage
<lib/mirage/*.ml{,i,y}>: pkg_fmt
<lib/mirage/*.ml{,i,y}>: pkg_hex
Expand All @@ -115,6 +119,7 @@ true: annot, bin_annot
<bin/ogit.{native,byte}>: pkg_cohttp.lwt
<bin/ogit.{native,byte}>: pkg_conduit.lwt-unix
<bin/ogit.{native,byte}>: pkg_crc
<bin/ogit.{native,byte}>: pkg_decompress
<bin/ogit.{native,byte}>: pkg_fmt
<bin/ogit.{native,byte}>: pkg_fmt.cli
<bin/ogit.{native,byte}>: pkg_fmt.tty
Expand All @@ -139,6 +144,7 @@ true: annot, bin_annot
<bin/*.ml{,i,y}>: pkg_cohttp.lwt
<bin/*.ml{,i,y}>: pkg_conduit.lwt-unix
<bin/*.ml{,i,y}>: pkg_crc
<bin/*.ml{,i,y}>: pkg_decompress
<bin/*.ml{,i,y}>: pkg_fmt
<bin/*.ml{,i,y}>: pkg_fmt.cli
<bin/*.ml{,i,y}>: pkg_fmt.tty
Expand Down Expand Up @@ -166,6 +172,7 @@ true: annot, bin_annot
<lib_test/test.{native,byte}>: pkg_conduit.lwt-unix
<lib_test/test.{native,byte}>: pkg_conduit.mirage
<lib_test/test.{native,byte}>: pkg_crc
<lib_test/test.{native,byte}>: pkg_decompress
<lib_test/test.{native,byte}>: pkg_dns.mirage
<lib_test/test.{native,byte}>: pkg_fmt
<lib_test/test.{native,byte}>: pkg_fmt.tty
Expand Down Expand Up @@ -198,6 +205,7 @@ true: annot, bin_annot
<lib_test/*.ml{,i,y}>: pkg_conduit.lwt-unix
<lib_test/*.ml{,i,y}>: pkg_conduit.mirage
<lib_test/*.ml{,i,y}>: pkg_crc
<lib_test/*.ml{,i,y}>: pkg_decompress
<lib_test/*.ml{,i,y}>: pkg_dns.mirage
<lib_test/*.ml{,i,y}>: pkg_fmt
<lib_test/*.ml{,i,y}>: pkg_fmt.tty
Expand Down
4 changes: 2 additions & 2 deletions lib/META
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OASIS_START
# DO NOT EDIT (digest: a01af07d306c69a55a64dfda6f7e4240)
# DO NOT EDIT (digest: 5b0fd45ae655f8f13a94f5d02d4681e8)
version = "1.8.0"
description = "A low-level interface to Git in pure OCaml"
requires = "mstruct logs ocamlgraph uri lwt hex astring crc fmt"
requires = "mstruct logs ocamlgraph uri lwt hex astring crc fmt decompress"
archive(byte) = "git.cma"
archive(byte, plugin) = "git.cma"
archive(native) = "git.cmxa"
Expand Down
81 changes: 81 additions & 0 deletions lib/inflate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,84 @@ module Make (Zlib: ZLIB) = struct
None

end

module Decompress : S =
struct
module Inflate = Decompress.Inflate.Make(Decompress.ExtString)(Decompress.ExtBytes)
module Deflate = Decompress.Deflate.Make(Decompress.ExtString)(Decompress.ExtBytes)

let deflate ?level buff =
let len = Cstruct.len buff in
let position = ref 0 in

let input = Bytes.create 1024 in
let output = Bytes.create 1024 in
let buffer = Buffer.create (Cstruct.len buff) in

let refill' _ =
let n = min (len - !position) 1024 in
Cstruct.blit_to_bytes buff !position input 0 n;
position := !position + n;
if !position >= len then true, n else false, n
in

let flush' _ len =
Buffer.add_subbytes buffer output 0 len;
len
in

Deflate.compress ?level (Bytes.unsafe_to_string input) output refill' flush';
Cstruct.of_string (Buffer.contents buffer)

let inflate ?output_size orig =
let buff = Mstruct.clone orig in
let output_size =
match output_size with
| None -> Mstruct.length orig
| Some s -> s
in
let input = Bytes.create 1024 in
let output = Bytes.create 1024 in
let buffer = Buffer.create output_size in
let s = ref 0 in

let inflater = Inflate.make input output in

let refill' () =
let n = min (Mstruct.length buff) 1024 in
let i = Mstruct.get_string buff n in
Bytes.blit i 0 input 0 n;
n
in

let flush' len =
Buffer.add_subbytes buffer output 0 len;
len
in

let len = refill' () in
Inflate.refill inflater len;
Inflate.flush inflater 1024;

let rec aux () = match Inflate.eval inflater with
| `Ok ->
let drop = flush' (Inflate.contents inflater) in
s := !s + Inflate.used_in inflater;
Inflate.flush inflater drop
| `Flush ->
let drop = flush' (Inflate.contents inflater) in
Inflate.flush inflater drop;
aux ()
| `Wait ->
let len = refill' () in
s := !s + Inflate.used_in inflater;
Inflate.refill inflater len;
aux ()
| `Error -> failwith "Inflate.inflate"
in

try aux ();
Mstruct.shift orig !s;
Some (Mstruct.of_string (Buffer.contents buffer))
with _ -> None
end
1 change: 1 addition & 0 deletions lib/inflate.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ module type ZLIB = sig
end

module Make (Z: ZLIB): S
module Decompress : S
4 changes: 2 additions & 2 deletions lib/unix/git_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ module IO_FS = struct

end

module Zlib = Git.Inflate.Make(Zlib)
module Zlib = Git.Inflate.Decompress

module SHA1 = struct

Expand Down Expand Up @@ -440,7 +440,7 @@ module Make (D: Git.Hash.DIGEST) (I: Git.Inflate.S) = struct

end

module M = Make(SHA1)(Zlib)
module M = Make(SHA1)(Git.Inflate.Decompress)
include M

module type S = sig
Expand Down
1 change: 1 addition & 0 deletions opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ depends: [
"hex"
"astring"
"crc"
"decompress" {>= "0.4"}
"alcotest" {test}
"mirage-types-lwt" {test}
"mirage-http" {test}
Expand Down
9 changes: 5 additions & 4 deletions setup.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.4.1 *)

(* OASIS_START *)
(* DO NOT EDIT (digest: 72320e11d60d8e8c46b5b7f061dd57d1) *)
(* DO NOT EDIT (digest: 78a50bff56837dc12f31fd1a4a0bd3d1) *)
(*
Regenerated by OASIS v0.4.5
Visit http://oasis.forge.ocamlcore.org for more information and
Expand Down Expand Up @@ -6955,7 +6955,8 @@ let setup_t =
FindlibPackage ("hex", None);
FindlibPackage ("astring", None);
FindlibPackage ("crc", None);
FindlibPackage ("fmt", None)
FindlibPackage ("fmt", None);
FindlibPackage ("decompress", None)
];
bs_build_tools = [ExternalTool "ocamlbuild"];
bs_c_sources = [];
Expand Down Expand Up @@ -7313,14 +7314,14 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.4.5";
oasis_digest = Some ")�q�T%2~��\005\018)��";
oasis_digest = Some "\146\255\227\198=\005aB\025VD\017\241o;I";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false
};;

let setup () = BaseSetup.setup setup_t;;

# 7325 "setup.ml"
# 7326 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;