Skip to content

Commit

Permalink
Support line anchors for commit URLs
Browse files Browse the repository at this point in the history
Anchor format is:

   #diff-<MD5 of path>[[L|R]<start line number>[-[L|R]<end line number>]]

With L line number is relative to the '---' side, and R to the '+++'
side of the diff.  Path of the '+++' side used when it exists, otherwise
path of the '---' side (for removals).

Closes tpope#36
  • Loading branch information
odnoletkov committed Aug 21, 2019
1 parent 9edacf9 commit df6d79f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion autoload/rhubarb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,27 @@ function! rhubarb#FugitiveUrl(opts, ...) abort
else
let commit = a:opts.commit
endif
if get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$'
if get(a:opts, 'type', '') ==# 'commit'
let url = root . '/commit/' . commit
let diff = get(a:opts, 'diff', {})
if len(diff) > 0 && executable('md5')
let url .= '#diff-' . system('md5 -qs ' . s:shellesc(len(diff.newpath) > 0 ? diff.newpath : diff.oldpath))[0:-2]
if len(get(diff, 'start', '')) > 0
if diff.start == '+'
let url .= 'R' . diff.newstart
else
let url .= 'L' . diff.oldstart
endif
if diff.oldend - diff.oldstart + diff.newend - diff.newstart > 0
if diff.end == '+'
let url .= '-R' . diff.newend
else
let url .= '-L' . diff.oldend
endif
endif
endif
endif
elseif get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$'
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$'
let escaped_commit = substitute(commit, '#', '%23', 'g')
Expand Down

0 comments on commit df6d79f

Please sign in to comment.