Retool :Git blame colored commits

Use 3 characters of the commit hash rather than 6, limiting the maximum
total declarations to 4,096 rather than 16 million. Avoid color
components lower than 0x20 and higher than 0xdf to help avoid colors
that blend into the background, light or dark.  And for the terminal,
replace the use of CSApprox with a simple usage of the 6x6x6 color cube
found on 256 color terminals.  CSApprox aims to provide accurate
replication of the input colors, whereas our goal is simply to use all
colors in roughly equal amounts.
This commit is contained in:
Tim Pope
2021-03-24 19:38:44 -04:00
parent b2195e7690
commit 7de9b5a04b
2 changed files with 22 additions and 11 deletions

View File

@@ -5725,7 +5725,6 @@ function! fugitive#BlameSyntax() abort
syn spell notoplevel syn spell notoplevel
syn match FugitiveblameBlank "^\s\+\s\@=" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalFile,FugitiveblameOriginalLineNumber skipwhite syn match FugitiveblameBlank "^\s\+\s\@=" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalFile,FugitiveblameOriginalLineNumber skipwhite
syn match FugitiveblameHash "\%(^\^\=[?*]*\)\@<=\<\x\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite syn match FugitiveblameHash "\%(^\^\=[?*]*\)\@<=\<\x\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite
syn match FugitiveblameUncommitted "\%(^\^\=\)\@<=\<0\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite
if s:HasOpt(flags, '-b') || FugitiveConfigGet('blame.blankBoundary') =~# '^1$\|^true$' if s:HasOpt(flags, '-b') || FugitiveConfigGet('blame.blankBoundary') =~# '^1$\|^true$'
syn match FugitiveblameBoundaryIgnore "^\^[*?]*\x\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite syn match FugitiveblameBoundaryIgnore "^\^[*?]*\x\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite
else else
@@ -5757,31 +5756,37 @@ function! fugitive#BlameSyntax() abort
endif endif
let seen = {} let seen = {}
for lnum in range(1, line('$')) for lnum in range(1, line('$'))
let hash = matchstr(getline(lnum), '^\^\=\zs\x\{6\}') let orig_hash = matchstr(getline(lnum), '^\^\=[*?]*\zs\x\{6\}')
if hash ==# '' || hash ==# '000000' || has_key(seen, hash) let hash = orig_hash
let hash = substitute(hash, '\(\x\)\x', '\=submatch(1).printf("%x", 15-str2nr(submatch(1),16))', 'g')
let hash = substitute(hash, '\(\x\x\)', '\=printf("%02x", str2nr(submatch(1),16)*3/4+32)', 'g')
if hash ==# '' || orig_hash ==# '000000' || has_key(seen, hash)
continue continue
endif endif
let seen[hash] = 1 let seen[hash] = 1
if &t_Co > 16 && get(g:, 'CSApprox_loaded') && !empty(findfile('autoload/csapprox/per_component.vim', escape(&rtp, ' '))) if &t_Co == 256
\ && empty(get(s:hash_colors, hash)) let [s, r, g, b; __] = map(matchlist(orig_hash, '\(\x\)\x\(\x\)\x\(\x\)\x'), 'str2nr(v:val,16)')
let [s, r, g, b; __] = map(matchlist(hash, '\(\x\x\)\(\x\x\)\(\x\x\)'), 'str2nr(v:val,16)') let color = 16 + (r + 1) / 3 * 36 + (g + 1) / 3 * 6 + (b + 1) / 3
let color = csapprox#per_component#Approximate(r, g, b) if color == 16
if color == 16 && &background ==# 'dark' let color = 235
let color = 8 elseif color == 231
let color = 255
endif endif
let s:hash_colors[hash] = ' ctermfg='.color let s:hash_colors[hash] = ' ctermfg='.color
else else
let s:hash_colors[hash] = '' let s:hash_colors[hash] = ''
endif endif
exe 'syn match FugitiveblameHash'.hash.' "\%(^\^\=\)\@<='.hash.'\x\{1,34\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite' let pattern = substitute(orig_hash, '^\(\x\)\x\(\x\)\x\(\x\)\x$', '\1\\x\2\\x\3\\x', '') . '*\>'
exe 'syn match FugitiveblameHash'.hash.' "\%(^\^\=[*?]*\)\@<='.pattern.'" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite'
endfor endfor
syn match FugitiveblameUncommitted "\%(^\^\=[?*]*\)\@<=\<0\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameScoreDebug,FugitiveblameOriginalLineNumber,FugitiveblameOriginalFile skipwhite
call s:BlameRehighlight() call s:BlameRehighlight()
endfunction endfunction
function! s:BlameRehighlight() abort function! s:BlameRehighlight() abort
for [hash, cterm] in items(s:hash_colors) for [hash, cterm] in items(s:hash_colors)
if !empty(cterm) || has('gui_running') || has('termguicolors') && &termguicolors if !empty(cterm) || has('gui_running') || has('termguicolors') && &termguicolors
exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.get(s:hash_colors, hash, '') exe 'hi FugitiveblameHash'.hash.' guifg=#' . hash . cterm
else else
exe 'hi link FugitiveblameHash'.hash.' Identifier' exe 'hi link FugitiveblameHash'.hash.' Identifier'
endif endif

View File

@@ -59,6 +59,12 @@ that are part of Git repositories).
~ reblame at [count]th first grandparent ~ reblame at [count]th first grandparent
P reblame at [count]th parent (like HEAD^[count]) P reblame at [count]th parent (like HEAD^[count])
*g:fugitive_dynamic_colors*
In the GUI or a 256 color terminal, commit hashes will
highlighted in different colors. To disable this:
>
let g:fugitive_dynamic_colors = 0
<
:[range]Git blame [...] If a range is given, just that part of the file will :[range]Git blame [...] If a range is given, just that part of the file will
:Git blame [...] {file} be blamed, and a horizontal split without :Git blame [...] {file} be blamed, and a horizontal split without
scrollbinding is used. You can also give an arbitrary scrollbinding is used. You can also give an arbitrary