Remove hard coded length limit of 40 on hashes

SHA-256 is coming eventually, may as well rip these out now.
This commit is contained in:
Tim Pope 2019-07-01 21:19:47 -04:00
parent 302ee3b41c
commit fc6643c318

View File

@ -363,7 +363,7 @@ function! fugitive#Head(...) abort
let head = readfile(fugitive#Find('.git/HEAD', dir))[0]
if head =~# '^ref: '
return substitute(head, '\C^ref: \%(refs/\%(heads/\|remotes/\|tags/\)\=\)\=', '', '')
elseif head =~# '^\x\{40\}$'
elseif head =~# '^\x\{40,\}$'
let len = a:0 ? a:1 : 0
return len < 0 ? head : len ? head[0:len-1] : ''
else
@ -373,7 +373,7 @@ endfunction
function! fugitive#RevParse(rev, ...) abort
let [hash, exec_error] = s:ChompError([a:0 ? a:1 : s:Dir(), 'rev-parse', '--verify', a:rev, '--'])
if !exec_error && hash =~# '^\x\{40\}$'
if !exec_error && hash =~# '^\x\{40,\}$'
return hash
endif
call s:throw('rev-parse '.a:rev.': '.hash)
@ -576,7 +576,7 @@ call s:add_methods('repo',['config', 'user'])
" Section: File API
function! s:DirCommitFile(path) abort
let vals = matchlist(s:Slash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\x\{40\}\|[0-3]\)\(/.*\)\=$')
let vals = matchlist(s:Slash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\x\{40,\}\|[0-3]\)\(/.*\)\=$')
if empty(vals)
return ['', '', '']
endif
@ -596,7 +596,7 @@ function! s:Owner(path, ...) abort
let actualdir = fugitive#Find('.git/', dir)
let [pdir, commit, file] = s:DirCommitFile(a:path)
if s:cpath(dir, pdir)
if commit =~# '^\x\{40\}$'
if commit =~# '^\x\{40,\}$'
return commit
elseif commit ==# '2'
return 'HEAD^{}'
@ -789,7 +789,7 @@ function! fugitive#Find(object, ...) abort
return file
endif
endif
if commit !~# '^[0-9a-f]\{40\}$'
if commit !~# '^[0-9a-f]\{40,\}$'
let commit = s:ChompDefault('', [dir, 'rev-parse', '--verify', commit, '--'])
endif
if len(commit)
@ -942,7 +942,7 @@ function! s:TreeInfo(dir, commit) abort
endfor
endif
return [get(s:indexes[a:dir][1], a:commit[-1:-1], {}), newftime]
elseif a:commit =~# '^\x\{40\}$'
elseif a:commit =~# '^\x\{40,\}$'
if !has_key(s:trees, a:dir)
let s:trees[a:dir] = {}
endif
@ -1141,7 +1141,7 @@ function! fugitive#writefile(lines, url, ...) abort
call call('writefile', [a:lines, temp] + a:000)
let [hash, exec_error] = s:ChompError([dir, 'hash-object', '-w', temp])
let mode = len(entry[1]) ? entry[1] : '100644'
if !exec_error && hash =~# '^\x\{40\}$'
if !exec_error && hash =~# '^\x\{40,\}$'
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
\ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1])[1]
if !exec_error
@ -2869,8 +2869,8 @@ function! s:RebaseEdit(cmd, dir) abort
let shas = {}
for i in range(len(new))
if new[i] =~# '^\l\+\s\+[0-9a-f]\{3,\}\>'
let sha = matchstr(new[i], '\C\v[a-f0-9]{5,40}')
if new[i] =~# '^\l\+\s\+[0-9a-f]\{5,\}\>'
let sha = matchstr(new[i], '\C\<[a-f0-9]\{5,\}\>')
if !sha_length
let sha_length = len(s:TreeChomp(a:dir, 'rev-parse', '--short', sha))
endif
@ -3027,10 +3027,10 @@ function! s:RebaseClean(file) abort
for i in range(len(new))
let new[i] = substitute(new[i], '^\l\>', '\=get(s:rebase_abbrevs,submatch(0),submatch(0))', '')
let sha = matchstr(new[i], '\C\v[a-f0-9]{5,40}')
let sha = matchstr(new[i], '\C\<[a-f0-9]\{5,\}\>')
let rebase_shas = getbufvar(a:file, 'fugitive_rebase_shas')
if len(sha) && type(rebase_shas) == type({}) && has_key(rebase_shas, sha)
let new[i] = substitute(new[i], sha, rebase_shas[sha], '')
let new[i] = substitute(new[i], '\C\<' . sha . '\>', rebase_shas[sha], '')
endif
endfor
if new !=# old
@ -3927,7 +3927,7 @@ endfunction
function! s:BlameCommit(cmd, ...) abort
let line = a:0 ? a:1 : getline('.')
if line =~# '^0\{4,40\} '
if line =~# '^0\{4,\} '
return 'echoerr ' . string('Not Committed Yet')
endif
let cmd = s:Open(a:cmd, 0, '', matchstr(line, '\x\+'), [matchstr(line, '\x\+')])
@ -4019,8 +4019,8 @@ function! s:BlameSyntax() abort
let arg = exists('b:fugitive_blame_arguments') ? b:fugitive_blame_arguments : ''
syn match FugitiveblameBoundary "^\^"
syn match FugitiveblameBlank "^\s\+\s\@=" nextgroup=FugitiveblameAnnotation,fugitiveblameOriginalFile,FugitiveblameOriginalLineNumber skipwhite
syn match FugitiveblameHash "\%(^\^\=\)\@<=\<\x\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
syn match FugitiveblameUncommitted "\%(^\^\=\)\@<=\<0\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
syn match FugitiveblameHash "\%(^\^\=\)\@<=\<\x\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
syn match FugitiveblameUncommitted "\%(^\^\=\)\@<=\<0\{7,\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
syn region FugitiveblameAnnotation matchgroup=FugitiveblameDelimiter start="(" end="\%( \d\+\)\@<=)" contained keepend oneline
syn match FugitiveblameTime "[0-9:/+-][0-9:/+ -]*[0-9:/+-]\%( \+\d\+)\)\@=" contained containedin=FugitiveblameAnnotation
exec 'syn match FugitiveblameLineNumber " *\d\+)\@=" contained containedin=FugitiveblameAnnotation'.conceal
@ -4135,7 +4135,7 @@ function! s:BrowseCommand(line1, line2, range, count, bang, mods, reg, arg, args
endif
if path =~# '^\.git/.*HEAD$' && filereadable(dir . '/' . path[5:-1])
let body = readfile(dir . '/' . path[5:-1])[0]
if body =~# '^\x\{40\}$'
if body =~# '^\x\{40,\}$'
let commit = body
let type = 'commit'
let path = ''
@ -4192,7 +4192,7 @@ function! s:BrowseCommand(line1, line2, range, count, bang, mods, reg, arg, args
if exec_error
let commit = ''
endif
if a:count && empty(a:args) && commit =~# '^\x\{40\}$'
if a:count && empty(a:args) && commit =~# '^\x\{40,\}$'
let blame_list = tempname()
call writefile([commit, ''], blame_list, 'b')
let blame_in = tempname()
@ -4354,7 +4354,7 @@ function! fugitive#MapJumps(...) abort
nnoremap <buffer> <silent> O :<C-U>exe <SID>GF("tabedit")<CR>
nnoremap <buffer> <silent> p :<C-U>exe <SID>GF("pedit")<CR>
endif
exe "nnoremap <buffer> <silent>" nowait "- :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>NavigateUp(v:count1))<Bar> if getline(1) =~# '^tree \x\{40\}$' && empty(getline(2))<Bar>call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')<Bar>endif<CR>"
exe "nnoremap <buffer> <silent>" nowait "- :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>NavigateUp(v:count1))<Bar> if getline(1) =~# '^tree \x\{40,\}$' && empty(getline(2))<Bar>call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')<Bar>endif<CR>"
nnoremap <buffer> <silent> P :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'^'.v:count1.<SID>Relative(':'))<CR>
nnoremap <buffer> <silent> ~ :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'~'.v:count1.<SID>Relative(':'))<CR>
nnoremap <buffer> <silent> C :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>
@ -4466,7 +4466,7 @@ function! s:cfile() abort
let treebase = substitute(s:DirCommitFile(@%)[1], '^\d$', ':&', '') . ':' .
\ s:Relative('') . (s:Relative('') =~# '^$\|/$' ? '' : '/')
if getline('.') =~# '^\d\{6\} \l\{3,8\} \x\{40\}\t'
if getline('.') =~# '^\d\{6\} \l\{3,8\} \x\{40,\}\t'
return [treebase . s:sub(matchstr(getline('.'),'\t\zs.*'),'/$','')]
elseif showtree
return [treebase . s:sub(getline('.'),'/$','')]
@ -4476,8 +4476,8 @@ function! s:cfile() abort
let dcmds = []
" Index
if getline('.') =~# '^\d\{6\} \x\{40\} \d\t'
let ref = matchstr(getline('.'),'\x\{40\}')
if getline('.') =~# '^\d\{6\} \x\{40,\} \d\t'
let ref = matchstr(getline('.'),'\x\{40,\}')
let file = ':'.s:sub(matchstr(getline('.'),'\d\t.*'),'\t',':')
return [file]
endif
@ -4485,12 +4485,12 @@ function! s:cfile() abort
if getline('.') =~# '^ref: '
let ref = strpart(getline('.'),5)
elseif getline('.') =~# '^commit \x\{40\}\>'
let ref = matchstr(getline('.'),'\x\{40\}')
elseif getline('.') =~# '^commit \x\{40,\}\>'
let ref = matchstr(getline('.'),'\x\{40,\}')
return [ref]
elseif getline('.') =~# '^parent \x\{40\}\>'
let ref = matchstr(getline('.'),'\x\{40\}')
elseif getline('.') =~# '^parent \x\{40,\}\>'
let ref = matchstr(getline('.'),'\x\{40,\}')
let line = line('.')
let parent = 0
while getline(line) =~# '^parent '
@ -4499,22 +4499,22 @@ function! s:cfile() abort
endwhile
return [ref]
elseif getline('.') =~# '^tree \x\{40\}$'
let ref = matchstr(getline('.'),'\x\{40\}')
elseif getline('.') =~# '^tree \x\{40,\}$'
let ref = matchstr(getline('.'),'\x\{40,\}')
if len(myhash) && fugitive#RevParse(myhash.':') ==# ref
let ref = myhash.':'
endif
return [ref]
elseif getline('.') =~# '^object \x\{40\}$' && getline(line('.')+1) =~ '^type \%(commit\|tree\|blob\)$'
let ref = matchstr(getline('.'),'\x\{40\}')
elseif getline('.') =~# '^object \x\{40,\}$' && getline(line('.')+1) =~ '^type \%(commit\|tree\|blob\)$'
let ref = matchstr(getline('.'),'\x\{40,\}')
let type = matchstr(getline(line('.')+1),'type \zs.*')
elseif getline('.') =~# '^\l\{3,8\} '.myhash.'$'
let ref = s:DirRev(@%)[1]
elseif getline('.') =~# '^\l\{3,8\} \x\{40\}\>'
let ref = matchstr(getline('.'),'\x\{40\}')
elseif getline('.') =~# '^\l\{3,8\} \x\{40,\}\>'
let ref = matchstr(getline('.'),'\x\{40,\}')
echoerr "warning: unknown context ".matchstr(getline('.'),'^\l*')
elseif getline('.') =~# '^[+-]\{3\} [abciow12]\=/'
@ -4558,10 +4558,10 @@ function! s:cfile() abort
let ref = matchstr(line,'\Cdiff --git \%([abciow12]/.*\|/dev/null\) \zs\%([abciow12]/.*\|/dev/null\)')
let dcmd = 'Gdiff!'
elseif line('$') == 1 && getline('.') =~ '^\x\{40\}$'
elseif line('$') == 1 && getline('.') =~ '^\x\{40,\}$'
let ref = getline('.')
elseif expand('<cword>') =~# '^\x\{7,40\}\>'
elseif expand('<cword>') =~# '^\x\{7,\}\>'
return [expand('<cword>')]
else