Skip to content

Instantly share code, notes, and snippets.

@tyru
Forked from mattn/Changes
Created June 7, 2012 16:23
Show Gist options
  • Save tyru/2889852 to your computer and use it in GitHub Desktop.
Save tyru/2889852 to your computer and use it in GitHub Desktop.
修正予定な箇所
9ee1a32
Data.String: diffidx does not handle multi-byte string.
b2bbfdd
add modeline (see #21 for the discussion)
3bb4cee
Fixed detecting case-insensitive system.
" これだと1行だけしか変更点を書けないので
" 以下のような行で、SHA1の次の行頭にインデントが続く行を返した方がいい
" ------------
" deadbea
" hoge
" fuga
" coffeee
" bar
"
" baaaaaa
" baz
" ------------
"
" s:getChanges() = {
" 'deadbea': ['hoge', 'fuga'],
" 'coffeee': ['bar'],
" 'baaaaaa': ['baz'],
" }
function! s:getChanges()
" 7桁とは限らない気がするので、s:showChanges()のcurrentもこの正規表現もどちらも正規化する
let sections = split(join(readfile("Changes"), "\n"), '\n\ze[a-z0-9]\{7}\n')
let changes = {}
for section in sections
let lines = split(section, "\n")
let changes[lines[0]] = join(
\ map(lines[1:], 'matchstr(v:val, "^\\s*\\zs.*")'), "\n")
endfor
return changes
endfunction
" こういうディレクトリ下で呼ばれる想定
" ./Changes
" ./autoload/vital/_*
" ./.git (vital repo)
function! s:showChanges()
" autoload/vital/_xxxxxxx.vimが来るのを想定していない
" 確かに今の順番的に1番目にautoload/vital/_xxxxxxxのディレクトリが来るが、
" 1. vitalの仕様変更
" 2. glob()の仕様変更
" で変わる必要があり、isdirectoryでチェックした方がいい
let current = fnamemodify(split(glob('autoload/vital/_*'), "\n")[0], ':t')
if current != '__latest__'
" currentをgit logに指定すれば履歴が大量にあるリポジトリでも速くなる
let keys = split(system("git log --format=format:%h"), "\n")
let pos = index(keys, current[1:])
if pos != -1
" s:getChanges()にcurrentを渡すと速い
let changes = s:getChanges()
for n in range(pos)
if has_key(changes, keys[n])
echo keys[n]
echo " " changes[keys[n]]
endif
endfor
endif
endif
endfunction
call s:showChanges()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment