<commit_before>let s:V = gita#vital()
let s:Prelude = s:V.import('Prelude')
let s:Path = s:V.import('System.Filepath')
let s:Git = s:V.import('Git')
let s:GitTerm = s:V.import('Git.Term')

function! s:parse_cmdarg(cmdarg) abort
  let options = {}
  if a:cmdarg =~# '++enc='
    let options.encoding = matchstr(a:cmdarg, '++enc=\zs[^ ]\+\ze')
  endif
  if a:cmdarg =~# '++ff='
    let options.fileformat = matchstr(a:cmdarg, '++ff=\zs[^ ]\+\ze')
  endif
  if a:cmdarg =~# '++bad='
    let options.bad = matchstr(a:cmdarg, '++bad=\zs[^ ]\+\ze')
  endif
  let options.binary = a:cmdarg =~# '++bin'
  let options.nobinary = a:cmdarg =~# '++nobin'
  let options.edit = a:cmdarg =~# '++edit'
  return options
endfunction

function! s:on_SourceCmd() abort
  let content = getbufline(expand('<afile>'), 1, '$')
  try
    let tempfile = tempname()
    call writefile(content, tempfile)
    execute printf('source %s', fnameescape(tempfile))
  finally
    if filereadable(tempfile)
      call delete(tempfile)
    endif
  endtry
endfunction
function! s:on_BufReadCmd() abort
  let options = extend({
        \ 'encoding': '',
        \ 'fileformat': '',
        \}, s:parse_cmdarg(v:cmdarg))
  let info = gita#autocmd#parse(expand('<afile>'))
  call gita#util#doautocmd('BufReadPre')
  let content_type = get(info, 'content_type')
  if content_type ==# 'show'
    call gita#command#show#edit({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  elseif content_type ==# 'diff'
    call gita#command#diff#edit({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'cached': index(info.extra_options, 'cached') >= 0,
          \ 'reverse': index(info.extra_options, 'reverse') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  else
    call gita#throw(printf(
          \ 'Unknown content-type "%s" is specified', content_type,
          \))
  endif
  call gita#util#doautocmd('BufReadPost')
endfunction
function! s:on_FileReadCmd() abort
  let info = gita#autocmd#parse(expand('<afile>'))
  call gita#util#doautocmd('FileReadPre')
  let content_type = get(info, 'content_type')
  if content_type ==# 'show'
    call gita#command#show#read({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  elseif content_type ==# 'diff'
    call gita#command#diff#read({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'cached': index(info.extra_options, 'cached') >= 0,
          \ 'reverse': index(info.extra_options, 'reverse') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  else<commit_msg>Fix autocmd issue on FileReadCmd<commit_after>let s:V = gita#vital()
let s:Prelude = s:V.import('Prelude')
let s:Path = s:V.import('System.Filepath')
let s:Git = s:V.import('Git')
let s:GitTerm = s:V.import('Git.Term')

function! s:parse_cmdarg(cmdarg) abort
  let options = {}
  if a:cmdarg =~# '++enc='
    let options.encoding = matchstr(a:cmdarg, '++enc=\zs[^ ]\+\ze')
  endif
  if a:cmdarg =~# '++ff='
    let options.fileformat = matchstr(a:cmdarg, '++ff=\zs[^ ]\+\ze')
  endif
  if a:cmdarg =~# '++bad='
    let options.bad = matchstr(a:cmdarg, '++bad=\zs[^ ]\+\ze')
  endif
  let options.binary = a:cmdarg =~# '++bin'
  let options.nobinary = a:cmdarg =~# '++nobin'
  let options.edit = a:cmdarg =~# '++edit'
  return options
endfunction

function! s:on_SourceCmd() abort
  let content = getbufline(expand('<afile>'), 1, '$')
  try
    let tempfile = tempname()
    call writefile(content, tempfile)
    execute printf('source %s', fnameescape(tempfile))
  finally
    if filereadable(tempfile)
      call delete(tempfile)
    endif
  endtry
endfunction
function! s:on_BufReadCmd() abort
  let options = extend({
        \ 'encoding': '',
        \ 'fileformat': '',
        \}, s:parse_cmdarg(v:cmdarg))
  let info = gita#autocmd#parse(expand('<afile>'))
  call gita#util#doautocmd('BufReadPre')
  let content_type = get(info, 'content_type')
  if content_type ==# 'show'
    call gita#command#show#edit({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  elseif content_type ==# 'diff'
    call gita#command#diff#edit({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'cached': index(info.extra_options, 'cached') >= 0,
          \ 'reverse': index(info.extra_options, 'reverse') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  else
    call gita#throw(printf(
          \ 'Unknown content-type "%s" is specified', content_type,
          \))
  endif
  call gita#util#doautocmd('BufReadPost')
endfunction
function! s:on_FileReadCmd() abort
  let options = extend({
        \ 'encoding': '',
        \ 'fileformat': '',
        \}, s:parse_cmdarg(v:cmdarg))
  let info = gita#autocmd#parse(expand('<afile>'))
  call gita#util#doautocmd('FileReadPre')
  let content_type = get(info, 'content_type')
  if content_type ==# 'show'
    call gita#command#show#read({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  elseif content_type ==# 'diff'
    call gita#command#diff#read({
          \ 'encoding': options.encoding,
          \ 'fileformat': options.fileformat,
          \ 'commit': info.commit,
          \ 'filename': info.filename,
          \ 'patch': index(info.extra_options, 'patch') >= 0,
          \ 'cached': index(info.extra_options, 'cached') >= 0,
          \ 'reverse': index(info.extra_options, 'reverse') >= 0,
          \ 'force': v:cmdbang && !&modified,
          \})
  else
{'fraction_non_alphanumeric': 0.17573895229733685, 'fraction_numerical': 0.0026338893766461808, 'mean_word_length': 2.8014460511679644, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '4593164', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2312, 'n_words': 465}