Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading commits with very long subjects #3533

Merged
merged 4 commits into from May 15, 2024

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

This PR fixes a problem with lazygit locking up completely when there's a commit whose subject line is longer than approximately 65500 characters.

Fixes #3529.

@stefanhaller stefanhaller added the bug Something isn't working label Apr 27, 2024
Copy link

codacy-production bot commented Apr 27, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -2.00%) 92.50%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (5558d87) 50798 42820 84.29%
Head commit (f69eb6d) 50834 (+36) 42849 (+29) 84.29% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3533) 40 37 92.50%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

@Ziwi01
Copy link

Ziwi01 commented May 9, 2024

Any chance to get this merged into master?

@stefanhaller
Copy link
Collaborator Author

I'd love to; it's waiting for a review by @jesseduffield.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Scanners can return errors (e.g. ErrTooLong), and if we don't handle it, the
cmd.Wait() call below will block forever because nobody drains the command's
output.

This happens for CommitLoader.GetCommits when there's a commit whose subject
line is longer than approx. 65500 characters; in that case, lazygit would lock
up completely. With this fix it remains usable, but the commit list is truncated
before the bad commit, which is not good enough. We'll improve that in the
remaining commits of this branch.
We are going to truncate overly long lines returned from git log, and the most
likely field that is going to make the line too long is the subject; so we must
put it last, otherwise we'd end up with not enough fields to split when it's too
long.

It might not be obvious from the diff what's happening to the mock command
output in the test: it didn't have the divergence field (">") at all, which was
kind of a bug. It didn't matter for these tests though, because we are not
testing the divergence here, and our production code happens to be resilient
against it missing. But now we must add the ">" field before the subject.
@stefanhaller stefanhaller force-pushed the fix-loading-commits-with-very-long-subjects branch from 52e8efc to f69eb6d Compare May 15, 2024 11:27
@stefanhaller stefanhaller merged commit d8b3c0e into master May 15, 2024
13 of 14 checks passed
@stefanhaller stefanhaller deleted the fix-loading-commits-with-very-long-subjects branch May 15, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazygit hangs terminal on listing commits
3 participants