mhinz/vim-toplevel — pull request #2 by Raugturi (2013-10-03 19:52:22+00:00)
Title: Use findfile() if finddir() fails

Fossil uses a file as the root marker, rather than a directory. Added findfile as a fallback. Also, if you prefer this would also work as the find_root_by_find function:

" #find_root_by_find {{{1
function! toplevel#find_root_by_find(bang) abort
if exists('b:root_by_find')
return s:cd_to_vcs_root(a:bang, b:root_by_find)
endif

let curdir = resolve(expand(':p:h'))

for vcs in s:vcs_list
let root = finddir(vcs[1], curdir . ';')
if !empty(root)
let b:root_by_find = fnamemodify(root, ':p:h:h')
return s:cd_to_vcs_root(a:bang, b:root_by_find)
endif

let root = findfile(vcs[1], curdir . ';')
if !empty(root)
let b:root_by_find = fnamemodify(root, ':p:h')
return s:cd_to_vcs_root(a:bang, b:root_by_find)
endif
endfor

echohl ErrorMsg
echo 'No VCS found.'
echohl NONE
endfunction

It might be easier to read than the one in the commit, also it depends on one less function call (doesn't need getftype()). However, I didn't like that it added an extra return which makes the flow a bit harder to understand.

Or if both options suck, I'm open to suggestions. I don't really know vimscript all that well and I couldn't find a built-in function that finds a file *or* a dir. If I overlooked it that would be the obvious solution.