<commit_before>let s:grep_available = executable('grep')
let s:grep_command = ' | ' . (g:gitgutter_escape_grep ? '\grep' : 'grep') . ' -e "^@@ "'
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'


function! diff#run_diff(realtime, use_external_grep)
  let cmd = 'git ls-files --error-unmatch ' . utility#shellescape(utility#file()) . ' && ('

  if a:realtime
    let blob_name = ':' . utility#shellescape(utility#file_relative_to_repo_root())
    let blob_file = tempname()
    let cmd .= 'git show ' . blob_name . ' > ' . blob_file .
          \ ' && diff -U0 ' . g:gitgutter_diff_args . ' ' . blob_file . ' - '
  else
    let cmd .= 'git diff --no-ext-diff --no-color -U0 ' . g:gitgutter_diff_args . ' ' . utility#shellescape(utility#file())
  endif

  if a:use_external_grep && s:grep_available
    " grep exits with 1 when no matches are found.  However we want to treat
    " non-matches as non-erroneous behaviour; so we OR the command with one
    " which always returns true.
    let cmd .= s:grep_command . ' || true'
  endif

  let cmd .= ')'

  if a:realtime
    let diff = system(utility#command_in_directory_of_file(cmd), utility#buffer_contents())
  else
    let diff = system(utility#command_in_directory_of_file(cmd))
  endif

  if v:shell_error
    " A shell error indicates the file is not tracked by git (unless something
    " bizarre is going on).
    throw 'diff failed'
  endif

  return diff
endfunction

function! diff#parse_diff(diff)
  let hunks = []
  for line in split(a:diff, '\n')
    let hunk_info = diff#parse_hunk(line)
    if len(hunk_info) == 4
      call add(hunks, hunk_info)
    endif
  endfor
  return hunks
endfunction

function! diff#parse_hunk(line)<commit_msg>Wrap compound commands in parentheses.<commit_after>let s:grep_available = executable('grep')
let s:grep_command = ' | ' . (g:gitgutter_escape_grep ? '\grep' : 'grep') . ' -e "^@@ "'
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'


function! diff#run_diff(realtime, use_external_grep)
  " Wrap compound command in parentheses to make Windows happy.
  let cmd = '(git ls-files --error-unmatch ' . utility#shellescape(utility#file()) . ' && ('

  if a:realtime
    let blob_name = ':' . utility#shellescape(utility#file_relative_to_repo_root())
    let blob_file = tempname()
    let cmd .= 'git show ' . blob_name . ' > ' . blob_file .
          \ ' && diff -U0 ' . g:gitgutter_diff_args . ' ' . blob_file . ' - '
  else
    let cmd .= 'git diff --no-ext-diff --no-color -U0 ' . g:gitgutter_diff_args . ' ' . utility#shellescape(utility#file())
  endif

  if a:use_external_grep && s:grep_available
    " grep exits with 1 when no matches are found.  However we want to treat
    " non-matches as non-erroneous behaviour; so we OR the command with one
    " which always returns true.
    let cmd .= s:grep_command . ' || true'
  endif

  let cmd .= '))'

  if a:realtime
    let diff = system(utility#command_in_directory_of_file(cmd), utility#buffer_contents())
  else
    let diff = system(utility#command_in_directory_of_file(cmd))
  endif

  if v:shell_error
    " A shell error indicates the file is not tracked by git (unless something
    " bizarre is going on).
    throw 'diff failed'
  endif

  return diff
endfunction

function! diff#parse_diff(diff)
  let hunks = []
  for line in split(a:diff, '\n')
    let hunk_info = diff#parse_hunk(line)
    if len(hunk_info) == 4
      call add(hunks, hunk_info)
    endif
  endfor
  return hunks
endfunction

function! diff#parse_hunk(line)
{'fraction_non_alphanumeric': 0.14131973945058057, 'fraction_numerical': 0.0022656471254602095, 'mean_word_length': 3.209773539928486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1600647', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1237, 'n_words': 316}