Created
June 24, 2012 08:01
-
-
Save anyakichi/2982373 to your computer and use it in GitHub Desktop.
Show differences to be committed for hg and svn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nnoremap <Space>D :<C-u>call <SID>commit_diff()<CR> | |
function! s:commit_diff(...) | |
let mod = a:0 > 0 ? a:1 : '' " 'vertical' or 'tab' | |
if bufname('%') =~ 'hg-editor-\w\+.txt' | |
call s:hg_commit_diff(mod) | |
elseif bufname('%') =~ 'svn-commit\%(\.\d\+\)\?\.tmp$' | |
call s:svn_commit_diff(mod) | |
else | |
echo 'unknown VCS' | |
endif | |
endfunction | |
function! s:vcs_commit_diff(mod, cmd, files) | |
if empty(a:files) | |
echo 'No changed files' | |
return | |
endif | |
silent execute a:mod 'new' | |
silent execute '0read' '!'.a:cmd join(a:files) | |
normal! gg | |
set buftype=nofile | |
setf diff | |
endfunction | |
function! s:hg_commit_diff(mod) | |
let lines = filter(getline(1, '$'), 'v:val =~ "^HG: changed"') | |
let files = map(lines, 'v:val[12:]') | |
call s:vcs_commit_diff(a:mod, 'hg diff --cwd $(hg root)', files) | |
endfunction | |
function! s:svn_commit_diff(mod) | |
let lines = getline(1, '$') | |
let last_empty_line = 1 | |
for lnum in range(len(lines)) | |
if empty(lines[lnum]) | |
let last_empty_line = lnum | |
endif | |
endfor | |
let lines = filter(lines[(last_empty_line):], 'v:val =~ "^M"') | |
let files = map(lines, 'split(v:val)[1]') | |
call s:vcs_commit_diff(a:mod, 'svn diff', files) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment