From 9a4f1e9df2bb5ee474483ca36a73d419abdbe7f8 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 22 May 2022 19:52:43 -0400 Subject: [PATCH] Extract helper for checking for same repository --- autoload/fugitive.vim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 314ff37..b450580 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -186,6 +186,11 @@ function! s:cpath(path, ...) abort return a:0 ? path ==# s:cpath(a:1) : path endfunction +function! s:SameRepo(one, two) abort + let one = s:GitDir(a:one) + return !empty(one) && one ==# s:GitDir(a:two) +endfunction + let s:executables = {} function! s:executable(binary) abort @@ -1631,7 +1636,7 @@ function! s:Owner(path, ...) abort endif let actualdir = fugitive#Find('.git/', dir) let [pdir, commit, file] = s:DirCommitFile(a:path) - if s:cpath(s:GitDir(dir), s:GitDir(pdir)) + if s:SameRepo(dir, pdir) if commit =~# '^\x\{40,\}$' return commit elseif commit ==# '2' @@ -1682,8 +1687,9 @@ function! fugitive#Path(url, ...) abort if empty(a:url) return '' endif - let dir = FugitiveVimPath(call('s:GitDir', a:000[1:-1])) - let tree = call('fugitive#Find', [':/'] + a:000[1:-1]) + let repo = call('s:Dir', a:000[1:-1]) + let dir_s = fugitive#Find('.git/', repo) + let tree = fugitive#Find(':/', repo) if !a:0 return fugitive#Real(a:url) elseif a:1 =~# '\.$' @@ -1712,10 +1718,10 @@ function! fugitive#Path(url, ...) abort let url = url[0:-2] endif let [argdir, commit, file] = s:DirCommitFile(url) - if !empty(argdir) && !s:cpath(s:GitDir(argdir), dir) + if !empty(argdir) && !s:SameRepo(argdir, repo) let file = '' - elseif len(dir) && s:cpath(url[0 : len(dir)]) ==# s:cpath(dir . '/') - let file = '/.git'.url[strlen(dir) : -1] + elseif len(dir_s) && s:cpath(strpart(url, 0, len(dir_s)), dir_s) + let file = '/.git' . strpart(url, len(dir_s)-1) elseif len(tree) && s:cpath(url[0 : len(tree)]) ==# s:cpath(tree . '/') let file = url[len(tree) : -1] elseif s:cpath(url) ==# s:cpath(tree) @@ -1878,7 +1884,7 @@ endfunction function! fugitive#Object(...) abort let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir() let [fdir, rev] = s:DirRev(a:0 ? a:1 : @%) - if s:cpath(dir) !=# s:cpath(fdir) + if !s:SameRepo(dir, fdir) let rev = '' endif let tree = s:Tree(dir)