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-<SHA256 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 #36
  • Loading branch information
odnoletkov committed Apr 7, 2021
1 parent 71d5c35 commit 4769400
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion autoload/rhubarb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,24 @@ function! rhubarb#FugitiveUrl(...) abort
else
let commit = opts.commit
endif
if get(opts, 'type', '') ==# 'tree' || opts.path =~# '/$'
if get(opts, 'type', '') ==# 'commit'
let url = root . '/commit/' . commit
if has_key(opts, 'ancestor')
let url .= '#diff-' . sha256(len(opts.path) > 0 ? opts.path : opts.ancestor.path)
let lines = []
if get(opts, 'line1') > 0
let lines += ['R' . opts.line1]
elseif get(opts.ancestor, 'line1') > 0
let lines += ['L' . opts.ancestor.line1]
endif
if get(opts, 'line2') > 0
let lines += ['R' . opts.line2]
elseif get(opts.ancestor, 'line2') > 0
let lines += ['L' . opts.ancestor.line2]
endif
let url .= join(uniq(lines), '-')
endif
elseif get(opts, 'type', '') ==# 'tree' || opts.path =~# '/$'
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
elseif get(opts, 'type', '') ==# 'blob' || opts.path =~# '[^/]$'
let escaped_commit = substitute(commit, '#', '%23', 'g')
Expand Down

0 comments on commit 4769400

Please sign in to comment.