From 37c66c28183e17d1cfec210d9125277e870afbcd Mon Sep 17 00:00:00 2001 From: David Date: Wed, 8 Nov 2017 22:24:19 +0200 Subject: [PATCH 1/6] added help file --- doc/gv-vim.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/gv-vim.txt diff --git a/doc/gv-vim.txt b/doc/gv-vim.txt new file mode 100644 index 0000000..54535fc --- /dev/null +++ b/doc/gv-vim.txt @@ -0,0 +1,30 @@ +gv-vim.txt gv-vim + +COMMANDS *gv-vim-commands* +============================================================================== + + -----------------+------------------------------------------------------------------- + Command | List ~ + -----------------+------------------------------------------------------------------- + `GV` | open commit browser -- You can pass git log options to the command, e.g. :GV -S foobar + `GV!` | will only list commits that affected the current file + `GV?` | fills the location list with the revisions of the current file + ---------------+------------------------------------------------------------------- + +MAPPINGS *gv-vim-mappings* +============================================================================== + +The following maps, work inside the "gv-buffer" + + ---------------------------------+------------------------------------------ + Mapping | Description ~ + ---------------------------------+------------------------------------------ + | Same as jo + | Same as ko + gb | open github on this commit + | display the diff in the range - display diff on commit if range omited + o | same as cr + O | similar to but opens a new tab instead + . | start command-line with :Git [CURSOR] SHA à la fugitive + q | close + ---------------------------------+------------------------------------------ From 223930d36078fd6614d869ee6815bc7037e5f1c4 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 8 Dec 2017 10:23:04 +0200 Subject: [PATCH 2/6] .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..926ccaa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +doc/tags From 82bdeda24b14dee170d173ef6b480015e0d63d7c Mon Sep 17 00:00:00 2001 From: David Date: Fri, 8 Dec 2017 10:25:30 +0200 Subject: [PATCH 3/6] disable DimInactive where appropriate --- plugin/gv.vim | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index fbb86e1..4027da9 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -106,6 +106,7 @@ function! s:open(visual, ...) call s:scratch() if type == 'commit' execute 'e' escape(target, ' ') + call s:disableDimInactive() nnoremap gb :Gbrowse elseif type == 'diff' call s:fill(target) @@ -164,11 +165,30 @@ function! s:syntax() hi def link diffLine Statement endfunction +function! s:gdiff() + let sha = gv#sha() + if len(sha) + tabnew + execute 'e '.g:currBufferForGv + execute 'Gedit '.sha + call search('^diff --git.*\sb/'.g:currBufferForGv.'\s*$') + normal o + " execute 'Gdiff '.sha + wincmd j + q + nmap q :wincmd o:qgt + wincmd l + nmap q :wincmd o:qgt + wincmd h + endif +endfunction function! s:maps() nnoremap q :$wincmd w close nnoremap gq :$wincmd w close nnoremap gb :call gbrowse() nnoremap :call open(0) + nnoremap gd :call gdiff() + nnoremap D :call gdiff() nnoremap o :call open(0) nnoremap O :call open(0, 1) xnoremap :call open(1) @@ -211,8 +231,21 @@ function! s:setup(git_dir, git_origin) let b:git_dir = a:git_dir endfunction +function! s:git_dir() + if empty(get(b:, 'git_dir', '')) + return fugitive#extract_git_dir(expand('%:p')) + endif + return b:git_dir +endfunction + +function! s:disableDimInactive() + if exists(':DimInactiveBufferOff') + DimInactiveBufferOff + endif +endfunction + function! s:scratch() - setlocal buftype=nofile bufhidden=wipe noswapfile nomodeline + setlocal buftype=nofile bufhidden=wipe noswapfile endfunction function! s:fill(cmd) @@ -239,7 +272,7 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2) if a:visual || a:bang let current = expand('%') call s:check_buffer(a:fugitive_repo, current) - return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', '--', current] + return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', current] endif return ['--graph'] endfunction @@ -253,7 +286,7 @@ function! s:list(fugitive_repo, log_opts) let bufname = repo_short_name.' '.join(a:log_opts) silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) - call s:fill(git_log_cmd) + call s:fill(git_log_cmd, a:root) setlocal nowrap tabstop=8 cursorline iskeyword+=# if !exists(':Gbrowse') @@ -317,6 +350,7 @@ function! s:gld() range endfunction function! s:gv(bang, visual, line1, line2, args) abort + let g:currBufferForGv = expand('%') if !exists('g:loaded_fugitive') return s:warn('fugitive not found') endif @@ -343,7 +377,7 @@ function! s:gv(bang, visual, line1, line2, args) abort else let log_opts = extend(gv#shellwords(a:args), s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2)) call s:setup(git_dir, fugitive_repo.config('remote.origin.url')) - call s:list(fugitive_repo, log_opts) + call s:list(fugitive_repo, log_opts, root) call FugitiveDetect(@#) endif catch From f05f6ea9b17e26af0f4d7a6c4d0045970f63dea7 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 4 Oct 2020 11:27:48 +0300 Subject: [PATCH 4/6] update from junegunn, enable side by side diffing --- plugin/gv.vim | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index 4027da9..d4c7f22 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -231,13 +231,6 @@ function! s:setup(git_dir, git_origin) let b:git_dir = a:git_dir endfunction -function! s:git_dir() - if empty(get(b:, 'git_dir', '')) - return fugitive#extract_git_dir(expand('%:p')) - endif - return b:git_dir -endfunction - function! s:disableDimInactive() if exists(':DimInactiveBufferOff') DimInactiveBufferOff @@ -245,7 +238,7 @@ function! s:disableDimInactive() endfunction function! s:scratch() - setlocal buftype=nofile bufhidden=wipe noswapfile + setlocal buftype=nofile bufhidden=wipe noswapfile nomodeline endfunction function! s:fill(cmd) @@ -272,7 +265,7 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2) if a:visual || a:bang let current = expand('%') call s:check_buffer(a:fugitive_repo, current) - return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', current] + return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', '--', current] endif return ['--graph'] endfunction @@ -286,7 +279,7 @@ function! s:list(fugitive_repo, log_opts) let bufname = repo_short_name.' '.join(a:log_opts) silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) - call s:fill(git_log_cmd, a:root) + call s:fill(git_log_cmd) setlocal nowrap tabstop=8 cursorline iskeyword+=# if !exists(':Gbrowse') @@ -377,7 +370,7 @@ function! s:gv(bang, visual, line1, line2, args) abort else let log_opts = extend(gv#shellwords(a:args), s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2)) call s:setup(git_dir, fugitive_repo.config('remote.origin.url')) - call s:list(fugitive_repo, log_opts, root) + call s:list(fugitive_repo, log_opts) call FugitiveDetect(@#) endif catch From a64ba5ed7a56840de15fd3212b580bf5b3578302 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 11 Jan 2021 09:20:22 +0200 Subject: [PATCH 5/6] improved regex --- plugin/gv.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index d4c7f22..b8e203d 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -171,7 +171,7 @@ function! s:gdiff() tabnew execute 'e '.g:currBufferForGv execute 'Gedit '.sha - call search('^diff --git.*\sb/'.g:currBufferForGv.'\s*$') + call search('^diff --git.*\sb/\S*'.g:currBufferForGv.'\s*$') normal o " execute 'Gdiff '.sha wincmd j From 79e8b5c653d0d26d209af0f353c480a8c1c26d67 Mon Sep 17 00:00:00 2001 From: David Susskind Date: Wed, 3 Nov 2021 10:36:57 +0200 Subject: [PATCH 6/6] merge latest junegun changes --- README.md | 4 +-- plugin/gv.vim | 74 +++++++++++++++++---------------------------------- syntax/GV.vim | 39 +++++++++++++++++++++++++++ test/gv.vader | 2 ++ 4 files changed, 67 insertions(+), 52 deletions(-) create mode 100644 syntax/GV.vim diff --git a/README.md b/README.md index 2aa3cf1..10e97a4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Usage ### Commands - `:GV` to open commit browser - - You can pass `git log` options to the command, e.g. `:GV -S foobar`. + - You can pass `git log` options to the command, e.g. `:GV -S foobar -- plugins`. - `:GV!` will only list commits that affected the current file - `:GV?` fills the location list with the revisions of the current file @@ -39,7 +39,7 @@ selected lines. - `o` or `` on a commit to display the content of it - `o` or `` on commits to display the diff in the range - `O` opens a new tab instead -- `gb` for `:Gbrowse` +- `gb` for `:GBrowse` - `]]` and `[[` to move between commits - `.` to start command-line with `:Git [CURSOR] SHA` à la fugitive - `q` or `gq` to close diff --git a/plugin/gv.vim b/plugin/gv.vim index b8e203d..1af4e76 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -52,7 +52,7 @@ function! s:gbrowse() if empty(sha) return s:shrug() endif - execute 'Gbrowse' sha + execute 'GBrowse' sha endfunction function! s:type(visual) @@ -61,7 +61,7 @@ function! s:type(visual) if len(shas) < 2 return [0, 0] endif - return ['diff', fugitive#repo().git_command('diff', shas[-1], shas[0])] + return ['diff', FugitiveShellCommand(['diff', shas[-1], shas[0]])] endif if exists('b:git_origin') @@ -126,45 +126,6 @@ function! s:dot() return empty(sha) ? '' : ':Git '.sha."\\" endfunction -function! s:syntax() - setf GV - syn clear - syn match gvInfo /^[^0-9]*\zs[0-9-]\+\s\+[a-f0-9]\+ / contains=gvDate,gvSha nextgroup=gvMessage,gvMeta - syn match gvDate /\S\+ / contained - syn match gvSha /[a-f0-9]\{6,}/ contained - syn match gvMessage /.* \ze(.\{-})$/ contained contains=gvTag,gvGitHub,gvJira nextgroup=gvAuthor - syn match gvAuthor /.*$/ contained - syn match gvMeta /([^)]\+) / contained contains=gvTag nextgroup=gvMessage - syn match gvTag /(tag:[^)]\+)/ contained - syn match gvGitHub /\<#[0-9]\+\>/ contained - syn match gvJira /\<[A-Z]\+-[0-9]\+\>/ contained - hi def link gvDate Number - hi def link gvSha Identifier - hi def link gvTag Constant - hi def link gvGitHub Label - hi def link gvJira Label - hi def link gvMeta Conditional - hi def link gvAuthor String - - syn match gvAdded "^\W*\zsA\t.*" - syn match gvDeleted "^\W*\zsD\t.*" - hi def link gvAdded diffAdded - hi def link gvDeleted diffRemoved - - syn match diffAdded "^+.*" - syn match diffRemoved "^-.*" - syn match diffLine "^@.*" - syn match diffFile "^diff\>.*" - syn match diffFile "^+++ .*" - syn match diffNewFile "^--- .*" - hi def link diffFile Type - hi def link diffNewFile diffFile - hi def link diffAdded Identifier - hi def link diffRemoved Special - hi def link diffFile Type - hi def link diffLine Statement -endfunction - function! s:gdiff() let sha = gv#sha() if len(sha) @@ -243,13 +204,14 @@ endfunction function! s:fill(cmd) setlocal modifiable + %delete _ silent execute 'read' escape('!'.a:cmd, '%') normal! gg"_dd setlocal nomodifiable endfunction function! s:tracked(fugitive_repo, file) - call system(a:fugitive_repo.git_command('ls-files', '--error-unmatch', a:file)) + call system(FugitiveShellCommand(['ls-files', '--error-unmatch', a:file])) return !v:shell_error endfunction @@ -265,15 +227,15 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2) if a:visual || a:bang let current = expand('%') call s:check_buffer(a:fugitive_repo, current) - return a:visual ? [printf('-L%d,%d:%s', a:line1, a:line2, current)] : ['--follow', '--', current] + return a:visual ? [[printf('-L%d,%d:%s', a:line1, a:line2, current)], []] : [['--follow'], ['--', current]] endif - return ['--graph'] + return [['--graph'], []] endfunction function! s:list(fugitive_repo, log_opts) let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)'] let git_args = ['log'] + default_opts + a:log_opts - let git_log_cmd = call(a:fugitive_repo.git_command, git_args, a:fugitive_repo) + let git_log_cmd = FugitiveShellCommand(git_args, a:fugitive_repo) let repo_short_name = fnamemodify(substitute(a:fugitive_repo.dir(), '[\\/]\.git[\\/]\?$', '', ''), ':t') let bufname = repo_short_name.' '.join(a:log_opts) @@ -282,13 +244,13 @@ function! s:list(fugitive_repo, log_opts) call s:fill(git_log_cmd) setlocal nowrap tabstop=8 cursorline iskeyword+=# - if !exists(':Gbrowse') + if !exists(':GBrowse') doautocmd User Fugitive endif call s:maps() - call s:syntax() + setf GV redraw - echo 'o: open split / O: open tab / gb: Gbrowse / q: quit' + echo 'o: open split / O: open tab / gb: GBrowse / q: quit' endfunction function! s:trim(arg) @@ -313,6 +275,16 @@ function! gv#shellwords(arg) return words endfunction +function! s:split_pathspec(args) + let split = index(a:args, '--') + if split < 0 + return [a:args, []] + elseif split == 0 + return [[], a:args] + endif + return [a:args[0:split-1], a:args[split:]] +endfunction + function! s:gl(buf, visual) if !exists(':Gllog') return @@ -320,7 +292,7 @@ function! s:gl(buf, visual) tab split silent execute a:visual ? "'<,'>" : "" 'Gllog' call setloclist(0, insert(getloclist(0), {'bufnr': a:buf}, 0)) - b # + noautocmd b # lopen xnoremap o :call gld() nnoremap o @@ -368,7 +340,9 @@ function! s:gv(bang, visual, line1, line2, args) abort call s:check_buffer(fugitive_repo, expand('%')) call s:gl(bufnr(''), a:visual) else - let log_opts = extend(gv#shellwords(a:args), s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2)) + let [opts1, paths1] = s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2) + let [opts2, paths2] = s:split_pathspec(gv#shellwords(a:args)) + let log_opts = opts1 + opts2 + paths1 + paths2 call s:setup(git_dir, fugitive_repo.config('remote.origin.url')) call s:list(fugitive_repo, log_opts) call FugitiveDetect(@#) diff --git a/syntax/GV.vim b/syntax/GV.vim new file mode 100644 index 0000000..e88872c --- /dev/null +++ b/syntax/GV.vim @@ -0,0 +1,39 @@ +if exists("b:current_syntax") + finish +endif + +syn clear +syn match gvInfo /^[^0-9]*\zs[0-9-]\+\s\+[a-f0-9]\+ / contains=gvDate,gvSha nextgroup=gvMessage,gvMeta +syn match gvDate /\S\+ / contained +syn match gvSha /[a-f0-9]\{6,}/ contained +syn match gvMessage /.* \ze(.\{-})$/ contained contains=gvTag,gvGitHub,gvJira nextgroup=gvAuthor +syn match gvAuthor /.*$/ contained +syn match gvMeta /([^)]\+) / contained contains=gvTag nextgroup=gvMessage +syn match gvTag /(tag:[^)]\+)/ contained +syn match gvGitHub /\<#[0-9]\+\>/ contained +syn match gvJira /\<[A-Z]\+-[0-9]\+\>/ contained +hi def link gvDate Number +hi def link gvSha Identifier +hi def link gvTag Constant +hi def link gvGitHub Label +hi def link gvJira Label +hi def link gvMeta Conditional +hi def link gvAuthor String + +syn match gvAdded "^\W*\zsA\t.*" +syn match gvDeleted "^\W*\zsD\t.*" +hi def link gvAdded diffAdded +hi def link gvDeleted diffRemoved + +syn match diffAdded "^+.*" +syn match diffRemoved "^-.*" +syn match diffLine "^@.*" +syn match diffFile "^diff\>.*" +syn match diffFile "^+++ .*" +syn match diffNewFile "^--- .*" +hi def link diffFile Type +hi def link diffNewFile diffFile +hi def link diffAdded Identifier +hi def link diffRemoved Special +hi def link diffFile Type +hi def link diffLine Statement diff --git a/test/gv.vader b/test/gv.vader index bcb9a56..10d5ccd 100644 --- a/test/gv.vader +++ b/test/gv.vader @@ -11,6 +11,8 @@ Execute (Test gv#shellwords): AssertEqual ['foo " bar'], gv#shellwords('"foo \" bar"') AssertEqual ['foo " bar', 'baz'], gv#shellwords("'foo \" bar' baz") AssertEqual ['foo', 'bar baz'], gv#shellwords("'foo' 'bar baz'") + AssertEqual ['--'], gv#shellwords('--') + AssertEqual ['--'], gv#shellwords('"--"') Execute (Test gv#sha): AssertEqual '33d2a88', gv#sha('* 2016-06-18 33d2a88 Let fugitive add buffer-local Git command to GV buffer (Junegunn Choi)')