niklaas / lightline-gitdiff

Show added, deleted and modified lines (`git diff`) in your statusline or lightline
Other
27 stars 4 forks source link

lightline-gitdiff breaks when calculating diff #14

Closed scattenlaeufer closed 5 years ago

scattenlaeufer commented 5 years ago

I encountered an issue with this plugin getting stuck when trying to calculate the additions and deletions of a file that differs from the last commit of it. If the file is the same as in the last commit or isn't part of a git repo, there are no visible problems I've encountered. When vim gets stuck, I can terminate the currently executed command with <C-c> and edit the file, but lightline-gitdiff doesn't work any more.

In the log I found the following:

Executing BufRead Autocommands for "*"
autocommand :call lightline#gitdiff#update(v:false)

Calling shell to execute: "(cd '/home/bjoern/git/pybaccm' && git rev-parse --is-inside-work-tree --prefix '.') >/tmp/vujHtbr/0 2>&1"
Calling shell to execute: "(cd '/home/bjoern/git/pybaccm' && git diff --word-diff=porcelain --unified=0 -- 'main.py') >/tmp/vujHtbr/1 2>&1"
Command terminated

I was also able to pinpoint the first occurrence of this issue to commit 8dff97506f032a1457f71b5b249a46e733b25352. In the log produced with the plugin on this commit, I found the following:

Executing BufRead Autocommands for "*"
autocommand :call lightline#gitdiff#write_to_cache(v:false) | :call lightline#update()

Calling shell to execute: "(cd '/home/bjoern/git/pybaccm' && git diff --word-diff=porcelain --unified=0 -- 'main.py') >/tmp/vudtl1o/0 2>&1"
Command terminated
niklaas commented 5 years ago

Thanks for reporting an issue. 8dff975 introduced a new algorithm for calculating the changes that, next to added and deleted lines, also calculates modified lines. (I have not documented that properly yet, but it's on my list, see #4.) In the master branch, the corresponding function still has some flaws, but I'm working on that in #8, #10 and #12.

I suspect that the new algorithm causes the issue but let's be sure about that. When encountering the issue with file main.py can you post the output of the following command?

cd /home/bjoern/git/pybaccm && git diff --word-diff=porcelain --unified=0 -- main.py | tail +5 | cut -c 1

This return the indicators of the porcelain diff of the file that seems to cause issues. So I can check whether I missed some combination.

Further, in #13 I refactored the new algorithm, which solves some of its flaws. Can you check out the pull request's branch and see whether the new implementation still causes the issue? (Make sure to restart vim after you checked out that branch for the plugin to be reloaded too.)

It's always a headache when plugins disturb your daily workflow. So, if you want to use the plugin in the meantime, you can (although it's not public API yet) force to use the old algorithm. Most probably, you won't encounter the issue then. Make sure that you're using the version of the plugin of the master branch and set the following in your .vimrc:

let g:lightline#gitdiff#algorithm = { -> s:calculate_numstat() }

Because of https://github.com/niklaas/lightline-gitdiff/blob/b843ef65369a4218d5f07f326edd4ebb2a5764fc/autoload/lightline/gitdiff.vim#L31 this should use the old algorithm. It's not as complicated as the new one and cannot calculate modified lines. However, it should be more robust at this stage.

scattenlaeufer commented 5 years ago

Found the problem and fixed it.

Thanks for the help!

niklaas commented 5 years ago

Thanks a lot for your contribution! Hadn't thought about external differs. :+1: