From 5ec0793b8808f5d01b8935a1bcb60bf4fddb6807 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 27 May 2022 19:56:43 -0400 Subject: [PATCH] Accept both fugitive://C:/ and fugitive:///C:/ on win32 The 2 slash version slots the drive letter into the host field, which I'm worried will cause problems when the URLs are used non-opaquely, for example, with an LSP. Let's start transitioning to the convention used by file:// URLs. --- autoload/fugitive.vim | 4 +++- plugin/fugitive.vim | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index d37b9c9..2b59973 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -139,10 +139,12 @@ function! s:Mods(mods, ...) abort endfunction if exists('+shellslash') + let s:dir_commit_file = '\c^fugitive://\%(/\a\@=\)\=\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$' function! s:Slash(path) abort return tr(a:path, '\', '/') endfunction else + let s:dir_commit_file = '\c^fugitive://\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$' function! s:Slash(path) abort return a:path endfunction @@ -1606,7 +1608,7 @@ call s:add_methods('repo',['config', 'user']) " Section: File API function! s:DirCommitFile(path) abort - let vals = matchlist(s:Slash(a:path), '\c^fugitive://\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$') + let vals = matchlist(s:Slash(a:path), s:dir_commit_file) if empty(vals) return ['', '', ''] endif diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 513f0fd..d661d08 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -88,10 +88,10 @@ endfunction " the inverse of FugitiveFind(). function! FugitiveParse(...) abort let path = s:Slash(a:0 ? a:1 : @%) - if path !~# '^fugitive:' + if path !~# '^fugitive://' return ['', ''] endif - let vals = matchlist(path, '\c^fugitive://\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$') + let vals = matchlist(path, s:dir_commit_file) if len(vals) return [(vals[2] =~# '^.\=$' ? ':' : '') . vals[2] . substitute(vals[3], '^/', ':', ''), vals[1]] endif @@ -412,8 +412,8 @@ function! FugitiveExtractGitDir(path) abort else let path = s:Slash(a:path) endif - if path =~# '^fugitive:' - return matchstr(path, '\C^fugitive:\%(//\)\=\zs.\{-\}\ze\%(//\|::\|$\)') + if path =~# '^fugitive://' + return get(matchlist(path, s:dir_commit_file), 1, '') elseif empty(path) return '' else @@ -509,10 +509,12 @@ function! FugitiveGitPath(path) abort endfunction if exists('+shellslash') + let s:dir_commit_file = '\c^fugitive://\%(/\a\@=\)\=\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$' function! s:Slash(path) abort return tr(a:path, '\', '/') endfunction else + let s:dir_commit_file = '\c^fugitive://\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$' function! s:Slash(path) abort return a:path endfunction @@ -521,7 +523,7 @@ endif function! s:ProjectionistDetect() abort let file = s:Slash(get(g:, 'projectionist_file', '')) let dir = FugitiveExtractGitDir(file) - let base = matchstr(file, '^fugitive://.\{-\}//\x\+') + let base = get(matchlist(file, s:dir_commit_file), 1, '') if empty(base) let base = s:Tree(dir) endif