Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vim-gitgutter
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
airblade
vim-gitgutter
Commits
952dbc34
Commit
952dbc34
authored
Nov 10, 2023
by
Andy Stewart
Browse files
Options
Downloads
Patches
Plain Diff
Move base_path() to gitgutter#utility
parent
4e262693
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
autoload/gitgutter/diff.vim
+1
-68
1 addition, 68 deletions
autoload/gitgutter/diff.vim
autoload/gitgutter/utility.vim
+65
-0
65 additions, 0 deletions
autoload/gitgutter/utility.vim
with
66 additions
and
68 deletions
autoload/gitgutter/diff.vim
+
1
−
68
View file @
952dbc34
...
...
@@ -123,7 +123,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
endif
" Write file from index to temporary file.
let
index_name
=
gitgutter#utility#get_diff_base
(
a:bufnr
).
':'
.
s:
base_path
(
a:bufnr
)
let
index_name
=
gitgutter#utility#get_diff_base
(
a:bufnr
).
':'
.
gitgutter#utility#
base_path
(
a:bufnr
)
let
cmd
.=
gitgutter#git
().
' --no-pager show --textconv '
.
index_name
.
' > '
.
from_file
.
' || exit 0) && ('
elseif
a:from
==
#
'working_tree'
...
...
@@ -425,70 +425,3 @@ endfunction
function
!
s:save_last_seen_change
(
bufnr
)
abort
call
gitgutter#utility#
setbufvar
(
a:bufnr
,
'tick'
,
getbufvar
(
a:bufnr
,
'changedtick'
))
endfunction
" Returns the original path (shellescaped) at the buffer's diff base.
function
!
s:base_path
(
bufnr
)
let
diffbase
=
gitgutter#utility#get_diff_base
(
a:bufnr
)
" If we already know the original path at this diff base, return it.
let
basepath
=
gitgutter#utility#
getbufvar
(
a:bufnr
,
'basepath'
,
''
)
if
!
empty
(
basepath
)
let
[
base
,
bpath
]
=
split
(
basepath
,
':'
,
1
)
if
base
==
diffbase
return
gitgutter#utility#
shellescape
(
bpath
)
endif
endif
" Obtain buffers' paths.
let
current_paths
=
{}
for
bufnr
in
range
(
1
,
bufnr
(
'$'
)
+
1
)
if
gitgutter#utility#has_repo_path
(
bufnr
)
let
current_paths
[
gitgutter#utility#repo_path
(
bufnr
,
0
)]
=
bufnr
endif
endfor
" Get a list of file renames at the buffer's diff base.
" Store the original paths on any corresponding buffers.
" If the buffer's file was one of them, return its original path.
let
op
=
''
let
renames
=
s:obtain_file_renames
(
a:bufnr
,
diffbase
)
for
[
current
,
original
]
in
items
(
renames
)
if
has_key
(
current_paths
,
current
)
let
bufnr
=
current_paths
[
current
]
let
basepath
=
diffbase
.
':'
.
original
call
gitgutter#utility#
setbufvar
(
bufnr
,
'basepath'
,
basepath
)
if
bufnr
==
a:bufnr
let
op
=
original
endif
endif
endfor
if
!
empty
(
op
)
return
gitgutter#utility#
shellescape
(
op
)
endif
" Buffer's file was not renamed, so store current path and return it.
let
current_path
=
gitgutter#utility#repo_path
(
a:bufnr
,
0
)
let
basepath
=
diffbase
.
':'
.
current_path
call
gitgutter#utility#
setbufvar
(
a:bufnr
,
'basepath'
,
basepath
)
return
gitgutter#utility#
shellescape
(
current_path
)
endfunction
" Returns a dict of current path to original path at the given base.
function
!
s:obtain_file_renames
(
bufnr
,
base
)
let
renames
=
{}
let
cmd
=
gitgutter#git
().
' diff --diff-filter=R --name-status '
.
a:base
let
[
out
,
error_code
]
=
gitgutter#utility#
system
(
gitgutter#utility#cd_cmd
(
a:bufnr
,
cmd
))
if
error_code
" Assume the problem is the diff base.
call
gitgutter#utility#
warn
(
'g:gitgutter_diff_base ('
.
a:base
.
') is invalid'
)
return
{}
endif
for
line
in
split
(
out
,
'\n'
)
let
[
original
,
current
]
=
split
(
line
)[
1
:]
let
renames
[
current
]
=
original
endfor
return
renames
endfunction
This diff is collapsed.
Click to expand it.
autoload/gitgutter/utility.vim
+
65
−
0
View file @
952dbc34
...
...
@@ -236,6 +236,71 @@ function! gitgutter#utility#get_diff_base(bufnr)
return
g:gitgutter_diff_base
endfunction
" Returns the original path (shellescaped) at the buffer's diff base.
function
!
gitgutter#utility#base_path
(
bufnr
)
let
diffbase
=
gitgutter#utility#get_diff_base
(
a:bufnr
)
" If we already know the original path at this diff base, return it.
let
basepath
=
gitgutter#utility#
getbufvar
(
a:bufnr
,
'basepath'
,
''
)
if
!
empty
(
basepath
)
let
[
base
,
bpath
]
=
split
(
basepath
,
':'
,
1
)
if
base
==
diffbase
return
gitgutter#utility#
shellescape
(
bpath
)
endif
endif
" Obtain buffers' paths.
let
current_paths
=
{}
for
bufnr
in
range
(
1
,
bufnr
(
'$'
)
+
1
)
if
gitgutter#utility#has_repo_path
(
bufnr
)
let
current_paths
[
gitgutter#utility#repo_path
(
bufnr
,
0
)]
=
bufnr
endif
endfor
" Get a list of file renames at the buffer's diff base.
" Store the original paths on any corresponding buffers.
" If the buffer's file was one of them, return its original path.
let
op
=
''
let
renames
=
s:obtain_file_renames
(
a:bufnr
,
diffbase
)
for
[
current
,
original
]
in
items
(
renames
)
if
has_key
(
current_paths
,
current
)
let
bufnr
=
current_paths
[
current
]
let
basepath
=
diffbase
.
':'
.
original
call
gitgutter#utility#
setbufvar
(
bufnr
,
'basepath'
,
basepath
)
if
bufnr
==
a:bufnr
let
op
=
original
endif
endif
endfor
if
!
empty
(
op
)
return
gitgutter#utility#
shellescape
(
op
)
endif
" Buffer's file was not renamed, so store current path and return it.
let
current_path
=
gitgutter#utility#repo_path
(
a:bufnr
,
0
)
let
basepath
=
diffbase
.
':'
.
current_path
call
gitgutter#utility#
setbufvar
(
a:bufnr
,
'basepath'
,
basepath
)
return
gitgutter#utility#
shellescape
(
current_path
)
endfunction
" Returns a dict of current path to original path at the given base.
function
!
s:obtain_file_renames
(
bufnr
,
base
)
let
renames
=
{}
let
cmd
=
gitgutter#git
().
' diff --diff-filter=R --name-status '
.
a:base
let
[
out
,
error_code
]
=
gitgutter#utility#
system
(
gitgutter#utility#cd_cmd
(
a:bufnr
,
cmd
))
if
error_code
" Assume the problem is the diff base.
call
gitgutter#utility#
warn
(
'g:gitgutter_diff_base ('
.
a:base
.
') is invalid'
)
return
{}
endif
for
line
in
split
(
out
,
'\n'
)
let
[
original
,
current
]
=
split
(
line
)[
1
:]
let
renames
[
current
]
=
original
endfor
return
renames
endfunction
function
!
s:abs_path
(
bufnr
,
shellesc
)
let
p
=
resolve
(
expand
(
'#'
.
a:bufnr
.
':p'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment