Permalink
Browse files

refactor log parse.

  • Loading branch information...
hrsh7th committed Oct 1, 2012
1 parent 78e21b7 commit c95f749a172097d531f17650f0c617f93987dc19
Showing with 11 additions and 17 deletions.
  1. +11 −17 autoload/vcs/git/log.vim
View
@@ -1,11 +1,13 @@
let s:save_cpo = &cpo
set cpo&vim
+" HASH, PREV_HASH, AUTHOR_NAME, AUTHOR_EMAIL, AUTHOR_DATE, SUBJECT
+let s:format = '%H%x09%P%x09%an%x09%ae%x09%ai%x09%s'
+
function! vcs#git#log#do(args)
let target = vcs#target(a:args)
let str = s:system(target)
let list = s:str2list(str)
- let list = s:extract(list)
let list = s:parse(target, list)
return list
endfunction
@@ -16,35 +18,27 @@ function! s:system(target)
let result = vcs#system(join([
\ 'git',
\ 'log',
+ \ '--pretty=format:"' . s:format . '"',
\ vcs#escape(a:target)
\ ], ' '))
exec 'lcd ' . cwd
return result
endfunction
function! s:str2list(str)
- return split(a:str, 'commit ')
-endfunction
-
-function! s:extract(list)
- return filter(map(a:list, 'split(v:val, "\n")'), 'len(v:val) > 2')
+ return map(split(a:str, "\n"), "split(v:val, '\\t')")
endfunction
function! s:parse(target, list)
- let logs = map(a:list, '{
+ return map(a:list, '{
\ "revision": v:val[0],
- \ "author": split(v:val[1], "Author: ")[0],
- \ "message": v:val[4][4:-1],
+ \ "prev_revision": v:val[1],
+ \ "author": v:val[2],
+ \ "email": v:val[3],
+ \ "date": v:val[4],
+ \ "message": v:val[5],
\ "path": a:target
\ }')
-
- let i = 0
- while i < len(logs)
- let logs[i].prev_revision = exists('logs[i + 1].revision') ? logs[i + 1].revision : ''
- let i = i + 1
- endwhile
-
- return logs
endfunction
let &cpo = s:save_cpo

0 comments on commit c95f749

Please sign in to comment.