aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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