Skip to content

git: Fix panic when unstaged diff is recalculated before its primary diff (#49753) (cherry-pick to stable)#49768

Merged
cole-miller merged 3 commits intov0.224.xfrom
cherry-pick-v0.224.x-930d9321
Feb 21, 2026
Merged

git: Fix panic when unstaged diff is recalculated before its primary diff (#49753) (cherry-pick to stable)#49768
cole-miller merged 3 commits intov0.224.xfrom
cherry-pick-v0.224.x-930d9321

Conversation

@zed-zippy
Copy link
Contributor

@zed-zippy zed-zippy bot commented Feb 21, 2026

Cherry-pick of #49753 to stable


For inverted diff APIs like hunks_intersecting_base_text_range, we
need a snapshot of the main buffer to use as context to compare hunk
anchors, convert anchors to points, etc. Previously, we were always
using a snapshot of the main buffer at the time when the diff was
calculated. This worked well for the hunks of the primary BufferDiff,
but it's not valid when the diff also has a secondary set of hunks,
because those hunks are recalculated on their own schedule--so it's
possible for the hunks of the secondary diff to contain anchors that are
newer than the original buffer snapshot that was taken at the time the
primary diff hunks were last calculated. This caused a panic when using
these anchors with the original buffer snapshot.

This PR fixes the issue by using the same approach for inverted diffs as
for non-inverted diffs at the multibuffer level: we take a snapshot of
the main buffer at the time when we snapshot the diff state (including
the diff itself), guaranteeing that that snapshot will be new enough to
resolve all the anchors included in both the primary diff and the
secondary diff.

Closes ZED-54J

Release Notes:

  • Fixed a panic that could occur when using the branch diff in split
    view mode.

Co-authored-by: Antonio Scandurra me@as-cii.com

…diff (#49753)

For inverted diff APIs like `hunks_intersecting_base_text_range`, we
need a snapshot of the main buffer to use as context to compare hunk
anchors, convert anchors to points, etc. Previously, we were always
using a snapshot of the main buffer at the time when the diff was
calculated. This worked well for the hunks of the primary `BufferDiff`,
but it's not valid when the diff also has a secondary set of hunks,
because those hunks are recalculated on their own schedule--so it's
possible for the hunks of the secondary diff to contain anchors that are
newer than the original buffer snapshot that was taken at the time the
primary diff hunks were last calculated. This caused a panic when using
these anchors with the original buffer snapshot.

This PR fixes the issue by using the same approach for inverted diffs as
for non-inverted diffs at the multibuffer level: we take a snapshot of
the main buffer at the time when we snapshot the diff state (including
the diff itself), guaranteeing that that snapshot will be new enough to
resolve all the anchors included in both the primary diff and the
secondary diff.

Closes ZED-54J

Release Notes:

- Fixed a panic that could occur when using the branch diff in split
view mode.

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 21, 2026
@zed-community-bot zed-community-bot bot added the bot Pull requests authored by a bot label Feb 21, 2026
@cole-miller cole-miller merged commit 77ae879 into v0.224.x Feb 21, 2026
27 checks passed
@cole-miller cole-miller deleted the cherry-pick-v0.224.x-930d9321 branch February 21, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot Pull requests authored by a bot cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant