Compute old lines for changed file
Opened this issue · 3 comments
After #24, it's now possible to generate URLs for changed files.
Unfortunately that is done at the expense of the line numbers which are discarded since on a changed file they no longer make sense. See #21 for further discussion.
It should be possible to parse git diff
and compute what the old line numbers were, and use those ones instead of nothing.
I'll try to research how https://github.com/gitkraken/vscode-gitlens does this (if they do it). This doesn't feel like a novel problem, surely someone must've done something similar
Fugitive's :GBrowse
command + vim-rhubarb does this for github. I think vim-rhubarb has nothing really to do with the actual logic of computing the old line numbers, but am not 100% sure since reading complex vimscript gives me a headache.
I think the code to do the old line number computation lives in this ~230 line behemoth of a function: https://github.com/tpope/vim-fugitive/blob/5b62c75238bf04b3156ffe62f821930827de8578/autoload/fugitive.vim#L7251=
Specifically here perhaps?: https://github.com/tpope/vim-fugitive/blob/5b62c75238bf04b3156ffe62f821930827de8578/autoload/fugitive.vim#L7404-L7431=
Looks like it's using git blame
somehow to assist with the logic.
@ruifm git link does not make sense to use unless it's a commit pushed to remote. My suggestion is to use a config param to allow the git diff line remap to be applied until the latest commit pushed remotely. Depending on whether config specifies to use latest commit or latest remote commit do the diff line remap accordingly.