Preserve remaining lines when splitting large diff chunks#530
Merged
Conversation
Contributor
|
I had to really read and process the line in the PR. It's not clear from the code what this does. I would consider this if you re-work it, add a comment about what it's doing, and make the code more obvious. Something like this: # Leave the last chunk in @lines so we do not miss any lines on a split
my $last = pop(@chunks) // [];
@lines = @$last; |
Contributor
Author
|
Hi @scottchiefbaker, Thank you for the thoughtful feedback. I have reworked this part to make the intent explicit in the code:
This keeps the split-boundary behavior self-documenting at the call site, reduces the chance of future misuse/regressions, and avoids extra history tracing for context. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This commit fixes a chunk-splitting bug in
diff-so-fancywhen processing large rename-only diffs (more than 100 lines).Previously, when input exceeded 100 lines, the code cleared
@linesentirely after chunking, which dropped the trailing partial chunk.Now it preserves the last incomplete chunk with:
so remaining lines continue to be processed correctly.
Root Cause
In the large-input path:
get_diff_chunks(\@lines)returns complete chunks plus a trailing incomplete chunk.@lines = ();, discarding that trailing data.Observed Failure
Before this commit, the reproduction can trigger:
This warning is consistent with missing trailing lines after chunk splitting.
Debug Evidence
Using
--debug, the output clearly stops right after the second line of block51, showing the processing boundary ends too early.Sample around block
51:If the warning location is temporarily forced to use an empty string so execution continues, another breakpoint appears around
76, which confirms there is additional data that should have remained connected but was cut by chunk handling.Sample around block
76:This is the key evidence that the issue is a chunk-truncation problem, not an upstream input issue.
Fix
Keep the trailing chunk in
@linesand only process the completed chunks immediately.Reproduction
Run:
Behavior Comparison
Before this commit
$nextmay appear atdiff-so-fancy line 409.--debugoutput ends early around block51(second line), indicating a broken chunk boundary.After this commit
76was previously observed after forcing continuation).Verification