<commit_before>:- ['src/dcg.pl'].

git_grep -->
    { inside_git_repository },
    { pattern(Pattern) },
    "git grep",
    " --untracked",
    " -I", % don't match pattern in binary files
    " -H", % include filename for each match
    " -n", % include line number for each match
    " --no-color",
    " -e '", atom(Pattern), "'".


inside_git_repository :-
    exists_directory('.git').<commit_msg>Teach git-grep about language specific searches<commit_after>:- use_module(library(dcg_util),[list//3]).
:- ['src/dcg.pl'].

git_grep -->
    { inside_git_repository },
    { pattern(Pattern) },
    "git grep",
    " --untracked",
    " -I", % don't match pattern in binary files
    " -H", % include filename for each match
    " -n", % include line number for each match
    " --no-color",
    " -e '", atom(Pattern), "'",
    pathspec.


inside_git_repository :-
    exists_directory('.git').


pathspec -->
    { include_lang(Lang) },
    !,
    " -- ",
    { findall(E,lang_extension(Lang,E),Exts) },
    list_(pathspec_extension,space,Exts),
    " ",
    { findall(F,lang_filename(Lang,F),Files) },
    list_(atom,space,Files).
pathspec -->
    "".

space --> " ".

pathspec_extension(Ext) -->
    "'*.", atom(Ext), "'".

% work around the way that list//3 handles empty lists
list_(Elem,Sep,Elems) -->
    ( { Elems=[] } -> []; list(Elem,Sep,Elems) ).
{'fraction_non_alphanumeric': 0.1947097722263042, 'fraction_numerical': 0.0014695077149155032, 'mean_word_length': 2.772853185595568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5955384', 'n_tokens_mistral': 481, 'n_tokens_neox': 465, 'n_words': 94}