<commit_before>open! Stdune

module File = struct
  type t =
    { src : Path.t
    ; dst : Path.t
    }

  (* XXX these sexp converters will be useful for the dump command *)
  (* let _t =
   *   let open Dsexp.Of_sexp in
   *   peek_exn >>= function
   *   | List (_, [_; Atom (_, A "as"); _]) ->
   *     enter
   *       (let % map src = Path.t
   *        and () = junk
   *        and dst = Path.t
   *        in
   *        { src; dst })
   *   | sexp ->
   *     Dsexp.Of_sexp.of_sexp_errorf (Sexp.Ast.loc sexp)
   *       "(<file> as <file>) expected" *)

  (* let _sexp_of_t { src; dst } =
   *   Sexp.List [Path.sexp_of_t src; Sexp.unsafe_atom_of_string "as";
   *              Path.sexp_of_t dst] *)

  let db : t list ref = ref []

  let register t = db := t :: !db

  let promote { src; dst } =
    Format.eprintf "Promoting %s to %s.@."
      (Path.to_string_maybe_quoted src)
      (Path.to_string_maybe_quoted dst);
    Io.copy_file ~src ~dst ()
end

module P = Utils.Persistent(struct
    type t = File.t list
    let name = "TO-PROMOTE"
    let version = 1
  end)

let db_file = Path.relative Path.build_dir ".to-promote"

let dump_db db =<commit_msg>Uncomment promotion rules<commit_after>open! Stdune

module File = struct
  type t =
    { src : Path.t
    ; dst : Path.t
    }

  (* XXX these sexp converters will be useful for the dump command *)
  let _dparse =
    let open Dsexp.Of_sexp in
    peek_exn >>= function
    | List (_, [_; Atom (_, A "as"); _]) ->
      enter
        (let%map src = Path_dsexp.dparse
         and () = junk
         and dst = Path_dsexp.dparse
         in
         { src; dst })
    | sexp ->
      Dsexp.Of_sexp.of_sexp_errorf (Dsexp.Ast.loc sexp)
        "(<file> as <file>) expected"

  let _sexp_of_t { src; dst } =
    Sexp.List
      [ Path.sexp_of_t src
      ; Sexp.Atom "as"
      ; Path.sexp_of_t dst
      ]

  let db : t list ref = ref []

  let register t = db := t :: !db

  let promote { src; dst } =
    Format.eprintf "Promoting %s to %s.@."
      (Path.to_string_maybe_quoted src)
      (Path.to_string_maybe_quoted dst);
    Io.copy_file ~src ~dst ()
end

module P = Utils.Persistent(struct
    type t = File.t list
    let name = "TO-PROMOTE"
    let version = 1
  end)

let db_file = Path.relative Path.build_dir ".to-promote"

let dump_db db =
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0008620689655172414, 'mean_word_length': 2.0539473684210527, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '1152645', 'n_tokens_mistral': 903, 'n_tokens_neox': 881, 'n_words': 235}