aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-04-29 05:45:43 +0200
committerTeddy Wing2017-04-29 05:45:43 +0200
commit0773fdd7bde5e7ce462c15bd1c71db3a3e46862a (patch)
tree89ad2cce29ab9544f2f71325f5be296e91c77218
parent8175afae4fa1f1ed9b945c9cb29f9dc574884fef (diff)
downloadvim-gitcha-0773fdd7bde5e7ce462c15bd1c71db3a3e46862a.tar.bz2
autoload/gitcha.vim: Add commit subject to completion popup (WIP)
Initial try at adding the commit subject to the popup menu to provide context for the commit. Currently only shows the first word of the subject because I'm using `split()`.
-rw-r--r--autoload/gitcha.vim30
1 files changed, 27 insertions, 3 deletions
diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim
index bde75a2..d84cf15 100644
--- a/autoload/gitcha.vim
+++ b/autoload/gitcha.vim
@@ -19,9 +19,10 @@ function! gitcha#GitSHAComplete(findstart, base)
" Match Git SHAs in the current repository
let matches = []
- let revs = system('git rev-list --all')
- for m in split(revs)
- if m =~ '^' . a:base
+ let revs = system('git rev-list --all --pretty=oneline --no-abbrev-commit')
+
+ for m in s:BuildMatchDictionary(revs)
+ if m['word'] =~ '^' . a:base
call add(matches, m)
endif
endfor
@@ -29,6 +30,29 @@ function! gitcha#GitSHAComplete(findstart, base)
return matches
endfunction
+" Takes rev-list output from:
+" $ git rev-list --all --pretty=oneline --no-abbrev-commit
+"
+" Creates a dictionary to be used for matching that uses commit SHAs for the
+" completion word and the commit subject as extra text.
+function! s:BuildMatchDictionary(rev_list)
+ let matches = []
+ let commits = split(a:rev_list, '\n')
+
+ for commit in commits
+ let commit_parts = split(commit)
+ let sha = commit_parts[0]
+ let subject = commit_parts[1]
+
+ call add(matches, {
+ \ 'word': sha,
+ \ 'menu': subject
+ \ })
+ endfor
+
+ return matches
+endfunction
+
" Allow mappings to initiate completion
function! gitcha#StartGitSHACompletion()
set completefunc=gitcha#GitSHAComplete