<commit_before>(*
 * Copyright (c) 2013 <NAME> <<EMAIL>>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *)

open Lwt
open Test_common

let test_db = ".git"

let init_memory () =
  Git_memory.create ~root:"." () >>= fun t ->
  Git_memory.clear t

let init_disk () =
  if Filename.basename (Sys.getcwd ()) <> "lib_test" then
    failwith "The Git test should be run in the lib_test/ directory."
  else if Sys.file_exists test_db then
    Git_fs.create ~root:"." () >>= fun t ->
    Git_fs.clear t
  else
    return_unit

let init = function
  | `Disk   -> init_disk
  | `Memory -> init_memory

let string_of_g = function
  | `Disk   -> ""
  | `Memory -> ".MEM"

let suite k g =
  {
    name  = "GIT" ^ string_of_g g ^ string_of_kind k;
    kind  = k;
    init  = init g;
    clean = unit;
    store =
      let (module Config) = match g with
        | `Memory -> (module IrminGit.Memory: IrminGit.Config)
        | `Disk   -> (module struct
            let root = None
            module Store = Git_fs
            let bare = false
            let disk = true
          end) in
      let module M = IrminGit.Make(Config) in
      let (module K), (module C), (module T) = modules k in
      Irmin.cast (module M.Make(K)(C)(T))
  }<commit_msg>Fix the Git backend tests<commit_after>(*
 * Copyright (c) 2013 <NAME> <<EMAIL>>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *)

open Lwt
open Test_common

let test_db = "test_db_git"

let init_memory () =
  Git_memory.create ~root:test_db () >>= fun t ->
  Git_memory.clear t

let init_disk () =
  if Filename.basename (Sys.getcwd ()) <> "lib_test" then
    failwith "The Git test should be run in the lib_test/ directory."
  else if Sys.file_exists test_db then
    Git_fs.create ~root:test_db () >>= fun t ->
    Git_fs.clear t
  else
    return_unit

module Memory = struct
  include IrminGit.Memory
  let root = Some test_db
end

module Disk = struct

  let root = Some test_db

  module Store = Git_fs

  (* expanding the filesystem with random binary filenames is ususally
     not a good idea. *)
  let bare = true

  let disk = true

end

let init = function
  | `Disk   -> init_disk
  | `Memory -> init_memory

let string_of_g = function
  | `Disk   -> ""
  | `Memory -> ".MEM"

let suite k g =
  {
    name  = "GIT" ^ string_of_g g ^ string_of_kind k;
    kind  = k;
    init  = init g;
    clean = unit;
    store =
      let (module Config) = match g with
        | `Memory -> (module Memory: IrminGit.Config)
        | `Disk   -> (module Disk  : IrminGit.Config) in
      let module M = IrminGit.Make(Config) in
      let (module K), (module C), (module T) = modules k in
      Irmin.cast (module M.Make(K)(C)(T))
  }
{'fraction_non_alphanumeric': 0.09036890319385987, 'fraction_numerical': 0.0019806882891804903, 'mean_word_length': 2.918525703200776, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3352829', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1231, 'n_words': 510}